Skip to content

Commit

Permalink
Add code example for adding a user to a group using group patch API (#…
Browse files Browse the repository at this point in the history
…625)

## Changes
Added an example of adding a principal to a group using the group patch
API.

## Tests
Tested the code locally.
  • Loading branch information
chrisgravel-db committed Apr 22, 2024
1 parent c2367af commit a3c0207
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/groups/patch_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import time
from databricks.sdk import WorkspaceClient
from databricks.sdk.service import iam

w = WorkspaceClient()

group = w.groups.create(display_name=f'sdk-{time.time_ns()}-group')
user = w.users.create(
display_name=f'sdk-{time.time_ns()}-user', user_name=f'sdk-{time.time_ns()}@example.com')

w.groups.patch(
id=group.id,
operations=[iam.Patch(
op=iam.PatchOp.ADD,
value={"members": [{
"value": user.id,
}]},
)],
schemas=[iam.PatchSchema.URN_IETF_PARAMS_SCIM_API_MESSAGES_2_0_PATCH_OP],
)

# cleanup
w.users.delete(id=user.id)
w.groups.delete(id=group.id)

0 comments on commit a3c0207

Please sign in to comment.