-
Notifications
You must be signed in to change notification settings - Fork 112
direct: Add permissions support for dashboards #3882
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
Open
shreyas-goenka
wants to merge
9
commits into
main
Choose a base branch
from
direct-dashboard-permissions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
61d3d79
direct: Add permissions support for dashboards
shreyas-goenka 26d86e2
update to not require test server changes
shreyas-goenka c406377
update test to cloud'
shreyas-goenka 9b47128
use priint requests python
shreyas-goenka d07abea
remove all_test.go changs
shreyas-goenka fe2c3a7
-
shreyas-goenka 04b229c
Merge remote-tracking branch 'origin' into direct-dashboard-permissions
shreyas-goenka 392b2ae
update tests
shreyas-goenka 80eba8b
fix test for dashboard permissions (TestAll)
shreyas-goenka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
acceptance/bundle/resources/permissions/dashboards/create/databricks.yml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| resources: | ||
| dashboards: | ||
| foo: | ||
| display_name: test-dashboard | ||
| warehouse_id: 123abc | ||
| parent_path: /Users/[email protected]/folder1 | ||
| serialized_dashboard: '{"pages":[{"name":"page1","displayName":"Page 1"}]}' | ||
| permissions: | ||
| - level: CAN_READ | ||
| user_name: [email protected] | ||
| - level: CAN_MANAGE | ||
| group_name: data-team | ||
| - level: CAN_MANAGE | ||
| service_principal_name: f37d18cd-98a8-4db5-8112-12dd0a6bfe38 | ||
| - level: CAN_MANAGE | ||
| user_name: [email protected] |
49 changes: 49 additions & 0 deletions
49
acceptance/bundle/resources/permissions/dashboards/create/out.plan.direct.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| { | ||
| "plan": { | ||
| "resources.dashboards.foo": { | ||
| "action": "create", | ||
| "new_state": { | ||
| "config": { | ||
| "display_name": "test-dashboard", | ||
| "parent_path": "/Users/[USERNAME]/folder1", | ||
| "warehouse_id": "123abc" | ||
| } | ||
| } | ||
| }, | ||
| "resources.dashboards.foo.permissions": { | ||
| "depends_on": [ | ||
| { | ||
| "node": "resources.dashboards.foo", | ||
| "label": "${resources.dashboards.foo.id}" | ||
| } | ||
| ], | ||
| "action": "create", | ||
| "new_state": { | ||
| "config": { | ||
| "object_id": "", | ||
| "permissions": [ | ||
| { | ||
| "permission_level": "CAN_READ", | ||
| "user_name": "[email protected]" | ||
| }, | ||
| { | ||
| "group_name": "data-team", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "service_principal_name": "[UUID]" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| } | ||
| ] | ||
| }, | ||
| "vars": { | ||
| "object_id": "/dashboards/${resources.dashboards.foo.id}" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
acceptance/bundle/resources/permissions/dashboards/create/out.plan.terraform.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "plan": { | ||
| "resources.dashboards.foo": { | ||
| "action": "create" | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
acceptance/bundle/resources/permissions/dashboards/create/out.requests.deploy.direct.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "method": "PUT", | ||
| "path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]", | ||
| "body": { | ||
| "access_control_list": [ | ||
| { | ||
| "permission_level": "CAN_READ", | ||
| "user_name": "[email protected]" | ||
| }, | ||
| { | ||
| "group_name": "data-team", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "service_principal_name": "[UUID]" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| } | ||
| ] | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
acceptance/bundle/resources/permissions/dashboards/create/out.requests.deploy.terraform.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "method": "PUT", | ||
| "path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]", | ||
| "body": { | ||
| "access_control_list": [ | ||
| { | ||
| "permission_level": "CAN_READ", | ||
| "user_name": "[email protected]" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "service_principal_name": "[UUID]" | ||
| }, | ||
| { | ||
| "group_name": "data-team", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| } | ||
| ] | ||
| } | ||
| } |
Empty file.
5 changes: 5 additions & 0 deletions
5
...ptance/bundle/resources/permissions/dashboards/create/out.requests.destroy.terraform.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "method": "PUT", | ||
| "path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]", | ||
| "body": {} | ||
| } |
5 changes: 5 additions & 0 deletions
5
acceptance/bundle/resources/permissions/dashboards/create/out.test.toml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
acceptance/bundle/resources/permissions/dashboards/create/output.txt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
|
|
||
| >>> [CLI] bundle validate -o json | ||
| [ | ||
| { | ||
| "level": "CAN_READ", | ||
| "user_name": "[email protected]" | ||
| }, | ||
| { | ||
| "group_name": "data-team", | ||
| "level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "level": "CAN_MANAGE", | ||
| "service_principal_name": "[UUID]" | ||
| }, | ||
| { | ||
| "level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| } | ||
| ] | ||
|
|
||
| >>> [CLI] workspace mkdirs /Users/[USERNAME]/folder1 | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete dashboard foo | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! |
23 changes: 23 additions & 0 deletions
23
acceptance/bundle/resources/permissions/dashboards/create/script
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| trace $CLI bundle validate -o json | jq .resources.dashboards.foo.permissions | ||
| rm out.requests.txt | ||
|
|
||
| $CLI bundle debug plan > out.plan.$DATABRICKS_BUNDLE_ENGINE.json | ||
|
|
||
| print_requests() { | ||
| jq -c < out.requests.txt | jq 'select(.method != "GET" and (.path | contains("permissions")))' | ||
| rm out.requests.txt | ||
| } | ||
|
|
||
| # create the parent path | ||
| trace $CLI workspace mkdirs /Users/[email protected]/folder1 | ||
|
|
||
| rm out.requests.txt | ||
| trace $CLI bundle deploy | ||
|
|
||
| dashboard_id=$($CLI bundle summary --output json | jq -r '.resources.dashboards.foo.id') | ||
| echo "$dashboard_id:DASHBOARD_ID" >> ACC_REPLS | ||
|
|
||
| print_requests > out.requests.deploy.$DATABRICKS_BUNDLE_ENGINE.json | ||
|
|
||
| trace $CLI bundle destroy --auto-approve | ||
| print_requests > out.requests.destroy.$DATABRICKS_BUNDLE_ENGINE.json | ||
This file contains hidden or 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 file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/service/apps" | ||
| "github.com/databricks/databricks-sdk-go/service/catalog" | ||
| "github.com/databricks/databricks-sdk-go/service/dashboards" | ||
| "github.com/databricks/databricks-sdk-go/service/database" | ||
| "github.com/databricks/databricks-sdk-go/service/iam" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
|
|
@@ -97,6 +98,16 @@ var testConfig map[string]any = map[string]any{ | |
| }, | ||
| }, | ||
| }, | ||
|
|
||
| "dashboards": &resources.Dashboard{ | ||
| DashboardConfig: resources.DashboardConfig{ | ||
| Dashboard: dashboards.Dashboard{ | ||
| DisplayName: "my_dashboard", | ||
| SerializedDashboard: `{"pages":[{"name":"page1","displayName":"Page 1"}]}`, | ||
| WarehouseId: "warehouse123", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| type prepareWorkspace func(client *databricks.WorkspaceClient) (any, error) | ||
|
|
@@ -252,6 +263,27 @@ var testDeps = map[string]prepareWorkspace{ | |
| }}, | ||
| }, nil | ||
| }, | ||
|
|
||
| "dashboards.permissions": func(client *databricks.WorkspaceClient) (any, error) { | ||
| resp, err := client.Lakeview.Create(context.Background(), dashboards.CreateDashboardRequest{ | ||
| Dashboard: dashboards.Dashboard{ | ||
| DisplayName: "dashboard-permissions", | ||
| SerializedDashboard: `{"pages":[{"name":"page1","displayName":"Page 1"}]}`, | ||
| WarehouseId: "warehouse123", | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &PermissionsState{ | ||
| ObjectID: "/dashboards/" + resp.DashboardId, | ||
| Permissions: []iam.AccessControlRequest{{ | ||
| PermissionLevel: "CAN_MANAGE", | ||
| UserName: "[email protected]", | ||
| }}, | ||
| }, nil | ||
| }, | ||
| } | ||
|
|
||
| func TestAll(t *testing.T) { | ||
|
|
@@ -340,7 +372,13 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W | |
| var relevantChanges []structdiff.Change | ||
| for _, change := range changes { | ||
| fieldName := change.Path.String() | ||
| if fieldName != "updated_at" { | ||
| // Filter out fields that are expected to change between DoRefresh and DoUpdate | ||
| // - updated_at, update_time: timestamps that change on updates | ||
| // - etag: version field that changes on updates | ||
| // - path: computed field for dashboards | ||
| // - serialized_dashboard: test server adds pageType and formatting | ||
| if fieldName != "updated_at" && fieldName != "update_time" && fieldName != "etag" && | ||
| fieldName != "path" && fieldName != "serialized_dashboard" { | ||
| relevantChanges = append(relevantChanges, change) | ||
| } | ||
| } | ||
|
|
@@ -373,6 +411,12 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W | |
| // t.Logf("Testing %s v=%#v, remoteValue=%#v", path.String(), val, remoteValue) | ||
| // We expect fields set explicitly to be preserved by testserver, which is true for all resources as of today. | ||
| // If not true for your resource, add exception here: | ||
|
|
||
| // Dashboard serialized_dashboard is modified by the server (adds pageType, reorders keys, adds newline) | ||
| if path.String() == "serialized_dashboard" { | ||
| return | ||
| } | ||
|
|
||
| assert.Equal(t, val, remoteValue, "path=%q\nnewState=%s\nremappedState=%s", path.String(), jsonDump(newState), jsonDump(remappedState)) | ||
| })) | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.