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 dynvar package for variable resolution with a dyn.Value tree #1143

Merged
merged 7 commits into from
Jan 24, 2024
Merged

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Jan 24, 2024

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).

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-commenter
Copy link

codecov-commenter commented Jan 24, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (ff6e035) 49.95% compared to head (57f1844) 50.24%.

Files Patch % Lines
libs/dyn/dynvar/resolve.go 92.00% 3 Missing and 3 partials ⚠️
libs/dyn/dynvar/ref.go 88.23% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

libs/dyn/dynvar/ref.go Show resolved Hide resolved
libs/dyn/dynvar/resolve.go Show resolved Hide resolved
Base automatically changed from dyn-visitors to main January 24, 2024 18:43
@pietern pietern added this pull request to the merge queue Jan 24, 2024
Merged via the queue into main with commit 14abcb3 Jan 24, 2024
4 checks passed
@pietern pietern deleted the dynvar branch January 24, 2024 18:56
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

3 participants