Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to visit values in dyn.Value tree #1142

Merged
merged 2 commits into from
Jan 24, 2024
Merged

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Jan 24, 2024

Changes

This change adds the following functions:

  • dyn.Get(value, "foo.bar") -> (dyn.Value, error)
  • dyn.Set(value, "foo.bar", newValue) -> (dyn.Value, error)
  • dyn.Map(value, "foo.bar", func) -> (dyn.Value, error)

And equivalent functions that take a previously constructed dyn.Path:

  • dyn.GetByPath(value, dyn.Path) -> (dyn.Value, error)
  • dyn.SetByPath(value, dyn.Path, newValue) -> (dyn.Value, error)
  • dyn.MapByPath(value, dyn.Path, func) -> (dyn.Value, error)

Changes made by the "set" and "map" functions are never reflected in the input argument; they return new dyn.Value instances for all nodes in the path leading up to the changed value.

Tests

New unit tests cover all critical paths.

This change adds the following functions:
* `dyn.Get(value, "foo.bar") -> (dyn.Value, error)`
* `dyn.Set(value, "foo.bar", newValue) -> (dyn.Value, error)`
* `dyn.Map(value, "foo.bar", func) -> (dyn.Value, error)`

And equivalent functions that take a previously constructed `dyn.Path`:
* `dyn.GetByPath(value, dyn.Path) -> (dyn.Value, error)`
* `dyn.SetByPath(value, dyn.Path, newValue) -> (dyn.Value, error)`
* `dyn.MapByPath(value, dyn.Path, func) -> (dyn.Value, error)`

Whenever the "set" and "map" functions need to change a value, they return
a new `dyn.Value` such that the input value is never changed.
libs/dyn/visit_test.go Outdated Show resolved Hide resolved
@pietern pietern added this pull request to the merge queue Jan 24, 2024
Merged via the queue into main with commit ff6e035 Jan 24, 2024
4 checks passed
@pietern pietern deleted the dyn-visitors branch January 24, 2024 18:43
github-merge-queue bot pushed a commit that referenced this pull request Jan 24, 2024
…1143)

## Changes

This is the `dyn` counterpart to the `bundle/config/interpolation`
package.

It relies on the paths in `${foo.bar}` being valid `dyn.Path` instances.
It leverages `dyn.Walk` to get a complete picture of all variable
references and uses `dyn.Get` to retrieve values pointed to by variable
references.

Depends on #1142.

## Tests

Unit test coverage. I tried to mirror the tests from
`bundle/config/interpolation` and added new ones where applicable (for
example to test type retention of referenced values).
pietern added a commit that referenced this pull request Jan 25, 2024
CLI:
 * Prompt for account profile only for account-level command execution instead of during `databricks labs install` flow ([#1128](#1128)).
 * Bring back `--json` flag for workspace-conf set-status command ([#1151](#1151)).

Bundles:
 * Set `run_as` permissions after variable interpolation ([#1141](#1141)).
 * Add functionality to visit values in `dyn.Value` tree ([#1142](#1142)).
 * Add `dynvar` package for variable resolution with a `dyn.Value` tree ([#1143](#1143)).
 * Add support for `anyOf` to `skip_prompt_if` ([#1133](#1133)).
 * Added `bundle generate pipeline` command ([#1139](#1139)).

Internal:
 * Use MockWorkspaceClient from SDK instead of WithImpl mocking ([#1134](#1134)).

Dependency updates:
 * Bump github.com/databricks/databricks-sdk-go from 0.29.0 to 0.29.1 ([#1137](#1137)).
 * Bump github.com/hashicorp/terraform-json from 0.20.0 to 0.21.0 ([#1138](#1138)).
 * Update actions/setup-go to v5 ([#1148](#1148)).
 * Update codecov/codecov-action to v3 ([#1149](#1149)).
 * Use latest patch release of Go toolchain ([#1152](#1152)).
@pietern pietern mentioned this pull request Jan 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jan 25, 2024
CLI:
* Prompt for account profile only for account-level command execution
instead of during `databricks labs install` flow
([#1128](#1128)).
* Bring back `--json` flag for workspace-conf set-status command
([#1151](#1151)).

Bundles:
* Set `run_as` permissions after variable interpolation
([#1141](#1141)).
* Add functionality to visit values in `dyn.Value` tree
([#1142](#1142)).
* Add `dynvar` package for variable resolution with a `dyn.Value` tree
([#1143](#1143)).
* Add support for `anyOf` to `skip_prompt_if`
([#1133](#1133)).
* Added `bundle generate pipeline` command
([#1139](#1139)).

Internal:
* Use MockWorkspaceClient from SDK instead of WithImpl mocking
([#1134](#1134)).

Dependency updates:
* Bump github.com/databricks/databricks-sdk-go from 0.29.0 to 0.29.1
([#1137](#1137)).
* Bump github.com/hashicorp/terraform-json from 0.20.0 to 0.21.0
([#1138](#1138)).
* Update actions/setup-go to v5
([#1148](#1148)).
* Update codecov/codecov-action to v3
([#1149](#1149)).
* Use latest patch release of Go toolchain
([#1152](#1152)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants