-
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 all 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
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
19 changes: 19 additions & 0 deletions
19
acceptance/bundle/resources/permissions/dashboards/create/databricks.yml.tmpl
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,19 @@ | ||
| bundle: | ||
| name: dashboard-perm-$UNIQUE_NAME | ||
|
|
||
| resources: | ||
| dashboards: | ||
| foo: | ||
| display_name: test-dashboard-$UNIQUE_NAME | ||
| warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID | ||
| parent_path: /Users/$CURRENT_USER_NAME/folder1 | ||
| serialized_dashboard: '{"pages":[{"name":"page1","displayName":"Page 1"}]}' | ||
| permissions: | ||
| - level: CAN_READ | ||
| user_name: $TEST_USER_EMAIL | ||
| - level: CAN_MANAGE | ||
| group_name: $TEST_GROUP_NAME | ||
| - level: CAN_MANAGE | ||
| service_principal_name: $TEST_SP_APPLICATION_ID | ||
| - level: CAN_MANAGE | ||
| user_name: $CURRENT_USER_NAME |
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-[UNIQUE_NAME]", | ||
| "parent_path": "/Users/[USERNAME]/folder1", | ||
| "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" | ||
| } | ||
| } | ||
| }, | ||
| "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": "[TEST_USER_EMAIL]" | ||
| }, | ||
| { | ||
| "group_name": "[TEST_GROUP_NAME]", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "service_principal_name": "[TEST_SP_APPLICATION_ID]" | ||
| }, | ||
| { | ||
| "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": "[TEST_USER_EMAIL]" | ||
| }, | ||
| { | ||
| "group_name": "[TEST_GROUP_NAME]", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "service_principal_name": "[TEST_SP_APPLICATION_ID]" | ||
| }, | ||
| { | ||
| "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_MANAGE", | ||
| "service_principal_name": "[TEST_SP_APPLICATION_ID]" | ||
| }, | ||
| { | ||
| "group_name": "[TEST_GROUP_NAME]", | ||
| "permission_level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| }, | ||
| { | ||
| "permission_level": "CAN_READ", | ||
| "user_name": "[TEST_USER_EMAIL]" | ||
| } | ||
| ] | ||
| } | ||
| } |
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": {} | ||
| } |
6 changes: 6 additions & 0 deletions
6
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.
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
|
|
||
| >>> [CLI] bundle validate -o json | ||
| [ | ||
| { | ||
| "level": "CAN_READ", | ||
| "user_name": "[TEST_USER_EMAIL]" | ||
| }, | ||
| { | ||
| "group_name": "[TEST_GROUP_NAME]", | ||
| "level": "CAN_MANAGE" | ||
| }, | ||
| { | ||
| "level": "CAN_MANAGE", | ||
| "service_principal_name": "[TEST_SP_APPLICATION_ID]" | ||
| }, | ||
| { | ||
| "level": "CAN_MANAGE", | ||
| "user_name": "[USERNAME]" | ||
| } | ||
| ] | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dashboard-perm-[UNIQUE_NAME]/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/dashboard-perm-[UNIQUE_NAME]/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
| if [ -z "$CLOUD_ENV" ]; then | ||
| export TEST_USER_EMAIL="[email protected]" | ||
| export TEST_GROUP_NAME="data-team" | ||
| export TEST_SP_APPLICATION_ID="f37d18cd-98a8-4db5-8112-12dd0a6bfe38" | ||
|
|
||
| echo "$TEST_USER_EMAIL:TEST_USER_EMAIL" >> ACC_REPLS | ||
| echo "$TEST_GROUP_NAME:TEST_GROUP_NAME" >> ACC_REPLS | ||
| echo "$TEST_SP_APPLICATION_ID:TEST_SP_APPLICATION_ID" >> ACC_REPLS | ||
| fi | ||
|
|
||
| envsubst < databricks.yml.tmpl > databricks.yml | ||
|
|
||
| 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 | ||
|
|
||
| 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.py //permissions > out.requests.deploy.$DATABRICKS_BUNDLE_ENGINE.json | ||
|
|
||
| trace $CLI bundle destroy --auto-approve | ||
| print_requests.py //permissions > out.requests.destroy.$DATABRICKS_BUNDLE_ENGINE.json |
3 changes: 3 additions & 0 deletions
3
acceptance/bundle/resources/permissions/dashboards/create/test.toml
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,3 @@ | ||
| Local = false | ||
| RequiresWarehouse = true | ||
| Cloud = true | ||
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
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" | ||
|
|
@@ -252,6 +253,36 @@ var testDeps = map[string]prepareWorkspace{ | |
| }}, | ||
| }, nil | ||
| }, | ||
|
|
||
| "dashboards.permissions": func(client *databricks.WorkspaceClient) (any, error) { | ||
| ctx := context.Background() | ||
| parentPath := "/Workspace/Users/[email protected]" | ||
|
|
||
| // Create parent directory if it doesn't exist | ||
| err := client.Workspace.MkdirsByPath(ctx, parentPath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := client.Lakeview.Create(ctx, dashboards.CreateDashboardRequest{ | ||
| Dashboard: dashboards.Dashboard{ | ||
| DisplayName: "dashboard-permissions", | ||
| ParentPath: parentPath, | ||
| SerializedDashboard: `{"pages":[{"name":"page1","displayName":"Page 1"}]}`, | ||
| }, | ||
| }) | ||
| 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) { | ||
|
|
||
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.
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.
Why not run this test locally?
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.
The cloud identity is a service principal, but the local identity is a username. That shows up in the permissions request body.
It was easiest to just run the test on the cloud. Otherwise we'll need separate golden files for local and cloud.
Uh oh!
There was an error while loading. Please reload this page.
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.
We have
IsServicePrincipal = truesetting in test.toml for such cases. This makes test runner set up service-principal-like identity locally.