Skip to content

Commit d35b0e3

Browse files
authored
Enable secret_scopes tests on testserver; add /Groups endpoint (#4222)
1 parent cef1d51 commit d35b0e3

21 files changed

+140
-43
lines changed

acceptance/bin/sort_acls_json.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Sort ACLs in JSON files recursively to ensure consistent ordering.
4+
5+
This script reads JSON from stdin, recursively finds all "acls" arrays,
6+
sorts them by principal, and outputs the normalized JSON pretty-printed.
7+
8+
Usage:
9+
cat file.json | sort_acls_json.py
10+
sort_acls_json.py < file.json
11+
"""
12+
13+
import json
14+
import sys
15+
16+
17+
def sort_acls_recursive(obj):
18+
"""Recursively traverse the object and sort any 'acls' arrays by principal."""
19+
if isinstance(obj, dict):
20+
result = {}
21+
for key, value in obj.items():
22+
if key == "acls" and isinstance(value, list):
23+
result[key] = sorted(value, key=repr)
24+
else:
25+
result[key] = sort_acls_recursive(value)
26+
return result
27+
elif isinstance(obj, list):
28+
return [sort_acls_recursive(item) for item in obj]
29+
else:
30+
return obj
31+
32+
33+
def main():
34+
raw = sys.stdin.read()
35+
try:
36+
data = json.loads(raw)
37+
except Exception:
38+
print("Not json:\n" + raw, flush=True)
39+
raise
40+
normalized = sort_acls_recursive(data)
41+
print(json.dumps(normalized, indent=2))
42+
43+
44+
if __name__ == "__main__":
45+
main()

acceptance/bundle/resources/secret_scopes/basic/out.plan2.direct.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
"remote_state": {
5656
"scope_name": "test-scope-[UNIQUE_NAME]-1",
5757
"acls": [
58-
{
59-
"permission": "WRITE",
60-
"principal": "deco-test-user@databricks.com"
61-
},
6258
{
6359
"permission": "MANAGE",
6460
"principal": "[USERNAME]"
61+
},
62+
{
63+
"permission": "WRITE",
64+
"principal": "deco-test-user@databricks.com"
6565
}
6666
]
6767
},

acceptance/bundle/resources/secret_scopes/basic/out.plan_verify_no_drift.direct.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
"remote_state": {
2323
"scope_name": "test-scope-[UNIQUE_NAME]-2",
2424
"acls": [
25-
{
26-
"permission": "WRITE",
27-
"principal": "deco-test-user@databricks.com"
28-
},
2925
{
3026
"permission": "MANAGE",
3127
"principal": "[USERNAME]"
28+
},
29+
{
30+
"permission": "WRITE",
31+
"principal": "deco-test-user@databricks.com"
3232
}
3333
]
3434
}

acceptance/bundle/resources/secret_scopes/basic/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/resources/secret_scopes/basic/output.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Deployment complete!
2323
"value":"bXktc2VjcmV0LXZhbHVl"
2424
}
2525

26+
>>> [CLI] secrets list-acls test-scope-[UNIQUE_NAME]-1
27+
{"permission":"MANAGE","principal":"[USERNAME]"}
28+
{"permission":"WRITE","principal":"deco-test-user@databricks.com"}
29+
2630
>>> print_requests.py //secrets
2731
{
2832
"method": "POST",
@@ -77,6 +81,10 @@ Deployment complete!
7781
"value":"YW5vdGhlci1zZWNyZXQtdmFsdWU="
7882
}
7983

84+
>>> [CLI] secrets list-acls test-scope-[UNIQUE_NAME]-2
85+
{"permission":"MANAGE","principal":"[USERNAME]"}
86+
{"permission":"WRITE","principal":"deco-test-user@databricks.com"}
87+
8088
>>> print_requests.py //secrets
8189
{
8290
"method": "POST",

acceptance/bundle/resources/secret_scopes/basic/script

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cleanup() {
99
trap cleanup EXIT
1010

1111
title "create the secret scope"
12-
trace $CLI bundle plan -o json > out.plan1.$DATABRICKS_BUNDLE_ENGINE.json
12+
trace $CLI bundle plan -o json | sort_acls_json.py > out.plan1.$DATABRICKS_BUNDLE_ENGINE.json
1313
trace $CLI bundle deploy
1414

1515
scope_name=$($CLI bundle summary --output json | jq -r '.resources.secret_scopes.my_scope.name')
@@ -18,14 +18,15 @@ trace $CLI secrets list-scopes -o json | jq ".[] | select(.name == \"$scope_name
1818
title "put and get secret in first scope"
1919
trace $CLI secrets put-secret $scope_name my-key --string-value "my-secret-value"
2020
trace $CLI secrets get-secret $scope_name my-key
21+
trace $CLI secrets list-acls $scope_name | jq -c '.[]' | sort
2122

2223
trace print_requests.py //secrets
2324

2425
title "update the name of the scope (should recreate)"
2526
export SECRET_SCOPE_NAME="test-scope-$UNIQUE_NAME-2"
2627
envsubst < databricks.yml.tmpl > databricks.yml
2728

28-
trace $CLI bundle plan -o json > out.plan2.$DATABRICKS_BUNDLE_ENGINE.json
29+
trace $CLI bundle plan -o json | sort_acls_json.py > out.plan2.$DATABRICKS_BUNDLE_ENGINE.json
2930
trace $CLI bundle deploy
3031

3132
# Capture API requests for verification. Terraform cleans up ACLs before deleting the scope, but direct does not, hence the difference in requests.
@@ -37,8 +38,9 @@ trace $CLI secrets list-scopes -o json | jq ".[] | select(.name == \"$scope_name
3738
title "put and get secret in recreated scope"
3839
trace $CLI secrets put-secret $scope_name another-key --string-value "another-secret-value"
3940
trace $CLI secrets get-secret $scope_name another-key
41+
trace $CLI secrets list-acls $scope_name | jq -c '.[]' | sort
4042

4143
trace print_requests.py //secrets
4244

4345
title "verify there's no persistent drift"
44-
trace $CLI bundle plan -o json > out.plan_verify_no_drift.$DATABRICKS_BUNDLE_ENGINE.json
46+
trace $CLI bundle plan -o json | sort_acls_json.py > out.plan_verify_no_drift.$DATABRICKS_BUNDLE_ENGINE.json
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Cloud = true
2-
Local = false
2+
Local = true
33
RecordRequests = true
44
IsServicePrincipal = true

acceptance/bundle/resources/secret_scopes/permissions/out.acls.create.direct.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

acceptance/bundle/resources/secret_scopes/permissions/out.acls.create.terraform.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

acceptance/bundle/resources/secret_scopes/permissions/out.acls.recreate.direct.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)