-
Notifications
You must be signed in to change notification settings - Fork 71
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 dynvar
package for variable resolution with a dyn.Value
tree
#1143
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch dynvar # Changes to be committed: # new file: libs/dyn/dynvar/lookup.go # new file: libs/dyn/dynvar/lookup_test.go # new file: libs/dyn/dynvar/ref.go # new file: libs/dyn/dynvar/ref_test.go # new file: libs/dyn/dynvar/resolve.go # new file: libs/dyn/dynvar/resolve_test.go # # Untracked files: # extra/ #
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1143 +/- ##
==========================================
+ Coverage 49.95% 50.24% +0.28%
==========================================
Files 285 288 +3
Lines 10839 10933 +94
==========================================
+ Hits 5415 5493 +78
- Misses 4858 4869 +11
- Partials 566 571 +5 ☔ View full report in Codecov by Sentry. |
andrewnester
approved these changes
Jan 24, 2024
// DefaultLookup is the default lookup function used by [Resolve]. | ||
func DefaultLookup(in dyn.Value) Lookup { | ||
return func(path dyn.Path) (dyn.Value, error) { | ||
return dyn.GetByPath(in, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
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)).
Merged
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This is the
dyn
counterpart to thebundle/config/interpolation
package.It relies on the paths in
${foo.bar}
being validdyn.Path
instances. It leveragesdyn.Walk
to get a complete picture of all variable references and usesdyn.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).