Skip to content

Commit c938e46

Browse files
direct: Add permissions support for dashboards (#3882)
Tested using new acceptance tests.
1 parent 497bc87 commit c938e46

File tree

16 files changed

+224
-7
lines changed

16 files changed

+224
-7
lines changed

acceptance/acceptance_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ func TestInprocessMode(t *testing.T) {
145145
require.Equal(t, 1, testAccept(t, true, "selftest/server"))
146146
}
147147

148+
// Configure replacements for environment variables we read from test environments.
149+
func setReplsForTestEnvVars(t *testing.T, repls *testdiff.ReplacementsContext) {
150+
envVars := []string{
151+
"TEST_DEFAULT_WAREHOUSE_ID",
152+
"TEST_INSTANCE_POOL_ID",
153+
}
154+
for _, envVar := range envVars {
155+
if value := os.Getenv(envVar); value != "" {
156+
repls.Set(value, "["+envVar+"]")
157+
}
158+
}
159+
}
160+
148161
func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
149162
repls := testdiff.ReplacementsContext{}
150163
cwd, err := os.Getwd()
@@ -232,17 +245,14 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
232245
}
233246
}
234247

248+
setReplsForTestEnvVars(t, &repls)
249+
235250
if cloudEnv != "" && UseVersion == "" {
236251
// Create linux release artifacts, to be used by the cloud-only ssh tunnel tests
237252
releasesDir := CreateReleaseArtifacts(t, cwd, coverDir, "linux")
238253
t.Setenv("CLI_RELEASES_DIR", releasesDir)
239254
}
240255

241-
testDefaultWarehouseId := os.Getenv("TEST_DEFAULT_WAREHOUSE_ID")
242-
if testDefaultWarehouseId != "" {
243-
repls.Set(testDefaultWarehouseId, "[TEST_DEFAULT_WAREHOUSE_ID]")
244-
}
245-
246256
terraformrcPath := filepath.Join(terraformDir, ".terraformrc")
247257
t.Setenv("TF_CLI_CONFIG_FILE", terraformrcPath)
248258
t.Setenv("DATABRICKS_TF_CLI_CONFIG_FILE", terraformrcPath)
@@ -256,8 +266,6 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
256266
// do it last so that full paths match first:
257267
repls.SetPath(buildDir, "[BUILD_DIR]")
258268

259-
repls.Set(os.Getenv("TEST_INSTANCE_POOL_ID"), "[TEST_INSTANCE_POOL_ID]")
260-
261269
testdiff.PrepareReplacementsDevVersion(t, &repls)
262270
testdiff.PrepareReplacementSdkVersion(t, &repls)
263271
testdiff.PrepareReplacementsGoVersion(t, &repls)

acceptance/bundle/refschema/out.fields.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ resources.dashboards.*.serialized_dashboard string ALL
439439
resources.dashboards.*.update_time string ALL
440440
resources.dashboards.*.url string INPUT
441441
resources.dashboards.*.warehouse_id string ALL
442+
resources.dashboards.*.permissions.object_id string ALL
443+
resources.dashboards.*.permissions.permissions []iam.AccessControlRequest ALL
444+
resources.dashboards.*.permissions.permissions[*] iam.AccessControlRequest ALL
445+
resources.dashboards.*.permissions.permissions[*].group_name string ALL
446+
resources.dashboards.*.permissions.permissions[*].permission_level iam.PermissionLevel ALL
447+
resources.dashboards.*.permissions.permissions[*].service_principal_name string ALL
448+
resources.dashboards.*.permissions.permissions[*].user_name string ALL
442449
resources.database_catalogs.*.create_database_if_not_exists bool ALL
443450
resources.database_catalogs.*.database_instance_name string ALL
444451
resources.database_catalogs.*.database_name string ALL
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bundle:
2+
name: dashboard-perm-$UNIQUE_NAME
3+
4+
resources:
5+
dashboards:
6+
foo:
7+
display_name: test-dashboard-$UNIQUE_NAME
8+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
9+
parent_path: /Users/$CURRENT_USER_NAME/folder1
10+
serialized_dashboard: '{"pages":[{"name":"page1","displayName":"Page 1"}]}'
11+
permissions:
12+
- level: CAN_READ
13+
user_name: $TEST_USER_EMAIL
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"plan": {
3+
"resources.dashboards.foo": {
4+
"action": "create",
5+
"new_state": {
6+
"value": {
7+
"display_name": "test-dashboard-[UNIQUE_NAME]",
8+
"parent_path": "/Users/[USERNAME]/folder1",
9+
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
10+
}
11+
}
12+
},
13+
"resources.dashboards.foo.permissions": {
14+
"depends_on": [
15+
{
16+
"node": "resources.dashboards.foo",
17+
"label": "${resources.dashboards.foo.id}"
18+
}
19+
],
20+
"action": "create",
21+
"new_state": {
22+
"value": {
23+
"object_id": "",
24+
"permissions": [
25+
{
26+
"permission_level": "CAN_READ",
27+
"user_name": "[email protected]"
28+
},
29+
{
30+
"permission_level": "CAN_MANAGE",
31+
"service_principal_name": "[USERNAME]"
32+
}
33+
]
34+
},
35+
"vars": {
36+
"object_id": "/dashboards/${resources.dashboards.foo.id}"
37+
}
38+
}
39+
}
40+
}
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"plan": {
3+
"resources.dashboards.foo": {
4+
"action": "create"
5+
},
6+
"resources.dashboards.foo.permissions": {
7+
"action": "create"
8+
}
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"method": "PUT",
3+
"path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]",
4+
"body": {
5+
"access_control_list": [
6+
{
7+
"permission_level": "CAN_READ",
8+
"user_name": "[email protected]"
9+
},
10+
{
11+
"permission_level": "CAN_MANAGE",
12+
"service_principal_name": "[USERNAME]"
13+
}
14+
]
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"method": "PUT",
3+
"path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]",
4+
"body": {
5+
"access_control_list": [
6+
{
7+
"permission_level": "CAN_MANAGE",
8+
"service_principal_name": "[USERNAME]"
9+
},
10+
{
11+
"permission_level": "CAN_READ",
12+
"user_name": "[email protected]"
13+
}
14+
]
15+
}
16+
}

acceptance/bundle/resources/permissions/dashboards/create/out.requests.destroy.direct.json

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"method": "PUT",
3+
"path": "/api/2.0/permissions/dashboards/[DASHBOARD_ID]",
4+
"body": {}
5+
}

acceptance/bundle/resources/permissions/dashboards/create/out.test.toml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)