fix comparing groups
This commit is contained in:
14
app/kube.py
14
app/kube.py
@@ -6,7 +6,7 @@ from kubernetes import client, config
|
|||||||
OIDC_USERS_NAMESPACE = os.environ["OIDC_USERS_NAMESPACE"]
|
OIDC_USERS_NAMESPACE = os.environ["OIDC_USERS_NAMESPACE"]
|
||||||
|
|
||||||
|
|
||||||
def users_with_group(group: str) -> List[str]:
|
def users_with_group(requiredGroup: str) -> List[str]:
|
||||||
config.load_incluster_config()
|
config.load_incluster_config()
|
||||||
api_instance = client.CustomObjectsApi()
|
api_instance = client.CustomObjectsApi()
|
||||||
|
|
||||||
@@ -15,13 +15,15 @@ def users_with_group(group: str) -> List[str]:
|
|||||||
ret = api_instance.list_namespaced_custom_object(
|
ret = api_instance.list_namespaced_custom_object(
|
||||||
"codemowers.cloud", "v1beta1", OIDC_USERS_NAMESPACE, "oidcusers"
|
"codemowers.cloud", "v1beta1", OIDC_USERS_NAMESPACE, "oidcusers"
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in ret["items"]:
|
for item in ret["items"]:
|
||||||
if group not in item.get("status", {}).get("groups", []):
|
for group in item.get("status", {}).get("groups", []):
|
||||||
continue
|
groupName = group.get("prefix", "") + ":" + group.get("name", "")
|
||||||
|
if groupName == requiredGroup:
|
||||||
|
users.append(item["metadata"]["name"])
|
||||||
|
continue
|
||||||
|
|
||||||
users.append(item["metadata"]["name"])
|
print(f"INFO: {len(users)} users in group {requiredGroup}")
|
||||||
|
|
||||||
print(f"INFO: {len(users)} users in group {group}")
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user