Skip to content

Commit a3c0207

Browse files
Add code example for adding a user to a group using group patch API (#625)
## Changes Added an example of adding a principal to a group using the group patch API. ## Tests Tested the code locally.
1 parent c2367af commit a3c0207

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/groups/patch_groups.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time
2+
from databricks.sdk import WorkspaceClient
3+
from databricks.sdk.service import iam
4+
5+
w = WorkspaceClient()
6+
7+
group = w.groups.create(display_name=f'sdk-{time.time_ns()}-group')
8+
user = w.users.create(
9+
display_name=f'sdk-{time.time_ns()}-user', user_name=f'sdk-{time.time_ns()}@example.com')
10+
11+
w.groups.patch(
12+
id=group.id,
13+
operations=[iam.Patch(
14+
op=iam.PatchOp.ADD,
15+
value={"members": [{
16+
"value": user.id,
17+
}]},
18+
)],
19+
schemas=[iam.PatchSchema.URN_IETF_PARAMS_SCIM_API_MESSAGES_2_0_PATCH_OP],
20+
)
21+
22+
# cleanup
23+
w.users.delete(id=user.id)
24+
w.groups.delete(id=group.id)

0 commit comments

Comments
 (0)