Skip to content

Commit

Permalink
feat(IAMService): use logger, return errors for getUser function and …
Browse files Browse the repository at this point in the history
…log them to VOMS2CSAgent email
  • Loading branch information
andresailer committed Sep 11, 2024
1 parent 6773c43 commit fdce07a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/DIRAC/ConfigurationSystem/Client/VOMS2CSSynchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def syncCSWithVOMS(self):
if not result["OK"]:
self.log.error("Could not retrieve user information", result["Message"])
return result

if getUserErrors := result.get("Errors", []):
self.adminMsgs["Errors"].extend(getUserErrors)
self.vomsUserDict = result["Value"]
message = f"There are {len(self.vomsUserDict)} user entries in VOMS for VO {self.vomsVOName}"
self.adminMsgs["Info"].append(message)
Expand Down
13 changes: 8 additions & 5 deletions src/DIRAC/Core/Security/IAMService.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, access_token, vo=None):
:param str access_token: the token used to talk to IAM, with the scim:read property
"""
self.log = gLogger.getSubLogger(self.__class__.__name__)

if not access_token:
raise ValueError("access_token not set")
Expand Down Expand Up @@ -127,13 +128,15 @@ def convert_iam_to_voms(iam_output):
def getUsers(self):
self.iam_users_raw = self._getIamUserDump()
users = {}
errors = 0
errors = []
for user in self.iam_users_raw:
try:
users.update(self.convert_iam_to_voms(user))
except Exception as e:
errors += 1
print(f"Could not convert {user['name']} {e!r} ")
print(f"There were in total {errors} errors")
errors.append(f"{user['name']} {e!r}")
self.log.error("Could not convert", f"{user['name']} {e!r}")
self.log.error("There were in total", f"{len(errors)} errors")
self.userDict = dict(users)
return S_OK(users)
result = S_OK(users)
result["Errors"] = errors
return result

0 comments on commit fdce07a

Please sign in to comment.