Skip to content

Commit

Permalink
Fix fetching of uid from multi value attribute fix naming issue for m…
Browse files Browse the repository at this point in the history
…irrored groups parameter
  • Loading branch information
BlackVoid committed May 25, 2024
1 parent f986e41 commit 29e2e57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions apricot/oauth/keycloak_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def groups(self) -> list[JSONDict]:
# If group_gid exists then set the cache to the same value
# This ensures that any groups without a `gid` attribute will receive a
# UID that does not overlap with existing groups
if group_gid := group_dict["attributes"]["gid"]:
if (group_gid := group_dict["attributes"]["gid"]) and len(group_dict["attributes"]["gid"]) == 1:
self.uid_cache.overwrite_group_uid(
group_dict["id"], int(group_gid, 10)
group_dict["id"], int(group_gid[0], 10)
)

# Read group attributes
Expand All @@ -72,7 +72,7 @@ def groups(self) -> list[JSONDict]:
attributes: JSONDict = {}
attributes["cn"] = group_dict.get("name", None)
attributes["description"] = group_dict.get("id", None)
attributes["gidNumber"] = group_dict["attributes"]["gid"]
attributes["gidNumber"] = group_dict["attributes"]["gid"][0]
attributes["oauth_id"] = group_dict.get("id", None)
# Add membership attributes
members = self.query(
Expand Down Expand Up @@ -107,9 +107,9 @@ def users(self) -> list[JSONDict]:
# If user_uid exists then set the cache to the same value.
# This ensures that any groups without a `gid` attribute will receive a
# UID that does not overlap with existing groups
if user_uid := user_dict["attributes"]["uid"]:
if (user_uid := user_dict["attributes"]["uid"]) and len(user_dict["attributes"]["uid"]) == 1:
self.uid_cache.overwrite_user_uid(
user_dict["id"], int(user_uid, 10)
user_dict["id"], int(user_uid[0], 10)
)

# Read user attributes
Expand Down Expand Up @@ -139,12 +139,12 @@ def users(self) -> list[JSONDict]:
attributes["displayName"] = full_name
attributes["mail"] = user_dict.get("email")
attributes["description"] = ""
attributes["gidNumber"] = user_dict["attributes"]["uid"]
attributes["gidNumber"] = user_dict["attributes"]["uid"][0]
attributes["givenName"] = first_name if first_name else ""
attributes["homeDirectory"] = f"/home/{username}" if username else None
attributes["oauth_id"] = user_dict.get("id", None)
attributes["sn"] = last_name if last_name else ""
attributes["uidNumber"] = user_dict["attributes"]["uid"]
attributes["uidNumber"] = user_dict["attributes"]["uid"][0]
output.append(attributes)
except KeyError:
pass
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
parser.add_argument("-p", "--port", type=int, default=1389, help="Port to run on.")
parser.add_argument("-s", "--client-secret", type=str, help="OAuth client secret.")
parser.add_argument("--disable-mirrored-groups", action="store_false",
dest="enable_mirrored", default=True,
dest="enable_mirrored_groups", default=True,
help="Disable creation of mirrored groups.")
parser.add_argument("--debug", action="store_true", help="Enable debug logging.")
# Options for Microsoft Entra backend
Expand Down

0 comments on commit 29e2e57

Please sign in to comment.