@@ -16,19 +16,19 @@ def addChild(self, child):
1616 self .children .append (child )
1717
1818
19- def _filter_attrs (attrs , valid_keys_map ):
19+ def _filter_attrs (attrs , valid_keys ):
2020 # only use the attributes defined by the valid keys map
2121 valid_attrs = {}
2222 if attrs is None :
2323 return valid_attrs
2424 for key in attrs :
25- if key in valid_keys_map :
25+ if key in valid_keys :
2626 # map to value
2727 valid_attrs .update ({key : attrs [key ][0 ]})
2828 return valid_attrs
2929
3030
31- def _construct_attribute_tree (groups , valid_keys_map ) -> KCAttributeNode :
31+ def _construct_attribute_tree (groups , valid_keys ) -> KCAttributeNode :
3232 """Construct a tree of attributes from the user groups"""
3333 root = KCAttributeNode ("root" , {})
3434 for group in groups :
@@ -49,7 +49,7 @@ def _construct_attribute_tree(groups, valid_keys_map) -> KCAttributeNode:
4949 # add the child with it's attributes and last segment name
5050 n = KCAttributeNode (
5151 paths [len (paths ) - 1 ],
52- _filter_attrs (group ["attributes" ], valid_keys_map )
52+ _filter_attrs (group ["attributes" ], valid_keys )
5353 )
5454 r .addChild (n )
5555 return root
@@ -103,12 +103,12 @@ def _compute_attributes_from_tree(node: KCAttributeNode, transform_value_fn=lamb
103103 return node .attrs
104104
105105
106- def get_user_attributes (user_id : str = None , valid_keys_map = {}, default_attributes = {}, transform_value_fn = lambda x : x ) -> dict :
106+ def get_user_attributes (user_id : str = None , valid_keys = {}, default_attributes = {}, transform_value_fn = lambda x : x ) -> dict :
107107 """Get the user attributes from Keycloak recursively from the user attributes and groups
108108
109109 Args:
110110 user_id (str): the Keycloak user id or username to get the quotas for
111- valid_keys_map (dict ): the valid keys to use for the attributes
111+ valid_keys (iterable ): the valid keys to use for the attributes
112112 default_attributes (dict): the default attributes to use if the user does not have the attribute
113113
114114 Returns:
@@ -130,8 +130,8 @@ def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attribut
130130 group_quotas = _compute_attributes_from_tree (
131131 _construct_attribute_tree (
132132 user ["userGroups" ],
133- valid_keys_map ), transform_value_fn )
134- user_attrs = _filter_attrs (user ["attributes" ], valid_keys_map )
133+ valid_keys ), transform_value_fn )
134+ user_attrs = _filter_attrs (user ["attributes" ], valid_keys )
135135 for key in group_quotas :
136136 if key not in user_attrs :
137137 user_attrs .update ({key : group_quotas [key ]})
0 commit comments