Skip to content

Commit

Permalink
Bug Fix for Issue: Patch Operation on a group is removing all the use…
Browse files Browse the repository at this point in the history
…rs and groups #5
  • Loading branch information
AbhiDatabricks committed Sep 8, 2023
1 parent 230de1a commit 0826ba8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
18 changes: 7 additions & 11 deletions nestedaaddb/databricks_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def patch_dbgroup(self, gid, members, dbg, dbus, dbgroups, dryrun):
api_url = self.dbbaseUrl + "/Groups/" + gid
u = {
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:Group"
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
]
}

Expand Down Expand Up @@ -109,7 +109,8 @@ def patch_dbgroup(self, gid, members, dbg, dbus, dbgroups, dryrun):
# check if it's a user
if member["type"] == "user":
for dbu in dbus["Resources"]:
if dbu["displayName"].casefold() == member["data"][0].casefold() and dbu["userName"].casefold() == member["data"][1].casefold():
if dbu["displayName"].casefold() == member["data"][0].casefold() and dbu[
"userName"].casefold() == member["data"][1].casefold():
obj = dict()
obj["value"] = dbu["id"]
mem.append(obj)
Expand All @@ -124,19 +125,14 @@ def patch_dbgroup(self, gid, members, dbg, dbus, dbgroups, dryrun):
break

dictmem = {"members": mem}
dictsub = {'op': "add", 'path': "members", 'value': dictmem}
dictsub = {'op': "add", 'value': dictmem}
ops.append(dictsub)

if len(toremove) > 0:
mem = []
for member in toremove:
obj = dict()
obj["value"] = member["value"]
mem.append(obj)

dictmem = {"members": mem}
dictsub = {'op': "remove", 'path': "members", 'value': dictmem}
ops.append(dictsub)
for member in toremove:
dictsub = {'op': "remove", 'path': "members[value eq \"" + member["value"] + "\""}
ops.append(dictsub)

gdata = json.loads(json.dumps(u))
gdata["Operations"] = ops
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "nestedaaddb"
version = "0.1.0"
version = "0.1.4"
description = "A package that allows to sync Nested AAD Group to DataBricks"
readme = "README.md"
authors = [{ name = "Abhishek Pratap Singh", email = "[email protected]" }]
Expand All @@ -15,6 +15,6 @@ classifiers = [
"Programming Language :: Python :: 3",
]
keywords = ['Databricks', 'SCIM', 'nested AAD']
dependencies = ['azure-core', 'azure-identity']
dependencies = ['azure-core', 'azure-identity','msgraph-core']
requires-python = ">=3.7"

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
azure-identity
msgraph-core

0 comments on commit 0826ba8

Please sign in to comment.