From a3c02072b8d125de75ac391a4ba82e80424a0103 Mon Sep 17 00:00:00 2001 From: Christopher Gravel <162506757+chrisgravel-db@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:03:29 -0700 Subject: [PATCH] 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. --- examples/groups/patch_groups.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/groups/patch_groups.py diff --git a/examples/groups/patch_groups.py b/examples/groups/patch_groups.py new file mode 100644 index 00000000..fa86dc66 --- /dev/null +++ b/examples/groups/patch_groups.py @@ -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)