Skip to content

Commit 7cd5cf0

Browse files
committed
chore: linting fix
1 parent f4c6044 commit 7cd5cf0

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

libraries/cloudharness-common/cloudharness/auth/quota.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
# quota tree node to hold the tree quota attributes
1010

1111

12-
13-
14-
1512
def get_group_quotas(group, application_config: ApplicationConfig):
1613
base_quotas = application_config.get("harness", {}).get("quotas", {})
1714
valid_keys_map = {key for key in base_quotas}
1815
return _compute_attributes_from_tree(_construct_attribute_tree([group], valid_keys_map))
1916

2017

21-
22-
2318
def attribute_to_quota(attr_value: str):
2419
return float(re.sub("[^0-9.]", "", attr_value) if type(attr_value) is str else attr_value)
2520

21+
2622
def get_user_quotas(application_config: ApplicationConfig = None, user_id: str = None) -> dict:
2723
"""Get the user quota from Keycloak and application
2824
@@ -39,8 +35,7 @@ def get_user_quotas(application_config: ApplicationConfig = None, user_id: str =
3935
if not application_config:
4036
application_config = get_current_configuration()
4137
base_quotas = application_config.get("harness", {}).get("quotas", {})
42-
43-
38+
4439
valid_keys_map = {key for key in base_quotas}
4540

4641
try:

libraries/cloudharness-common/cloudharness/auth/user_attributes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from cloudharness_model.models import ApplicationConfig
66
from cloudharness import log
77

8+
89
class KCAttributeNode:
910
def __init__(self, name, attrs):
1011
self.attrs = attrs
@@ -26,6 +27,7 @@ def _filter_attrs(attrs, valid_keys_map):
2627
valid_attrs.update({key: attrs[key][0]})
2728
return valid_attrs
2829

30+
2931
def _construct_attribute_tree(groups, valid_keys_map) -> KCAttributeNode:
3032
"""Construct a tree of attributes from the user groups"""
3133
root = KCAttributeNode("root", {})
@@ -56,6 +58,7 @@ def _construct_attribute_tree(groups, valid_keys_map) -> KCAttributeNode:
5658
class UserNotFound(Exception):
5759
pass
5860

61+
5962
def _compute_attributes_from_tree(node: KCAttributeNode, transform_value_fn=lambda x: x):
6063
"""Recursively traverse the tree and find the attributes per level
6164
the lower leafs overrule parent leafs values
@@ -100,7 +103,6 @@ def _compute_attributes_from_tree(node: KCAttributeNode, transform_value_fn=lamb
100103
return node.attrs
101104

102105

103-
104106
def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attributes={}, transform_value_fn=lambda x: x) -> dict:
105107
"""Get the user attributes from Keycloak recursively from the user attributes and groups
106108
@@ -115,7 +117,7 @@ def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attribut
115117
Example:
116118
{'quota-ws-maxcpu': 1000, 'quota-ws-open': 10, 'quota-ws-max': 8}
117119
"""
118-
120+
119121
try:
120122
auth_client = AuthClient()
121123
if not user_id:
@@ -125,7 +127,6 @@ def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attribut
125127
log.warning("Quotas not available: error retrieving user: %s", user_id)
126128
raise UserNotFound("User not found") from e
127129

128-
129130
group_quotas = _compute_attributes_from_tree(
130131
_construct_attribute_tree(
131132
user["userGroups"],
@@ -137,4 +138,4 @@ def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attribut
137138
for key in default_attributes:
138139
if key not in user_attrs:
139140
user_attrs.update({key: transform_value_fn(default_attributes[key])})
140-
return user_attrs
141+
return user_attrs

0 commit comments

Comments
 (0)