Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
classabbyamp committed Aug 4, 2024
1 parent ddccf19 commit 8adba0b
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions buildbot_netauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,43 +51,42 @@ def getUserInfo(self, username):
if not username:
return defer.fail(ValueError("username not found"))

def thr():
try:
entity = self.netauth.entity_info(username)

if entity is None:
return defer.fail(ValueError("entity not found"))

id = entity.id
email = f"{id}@netauth"
if (meta := entity.meta) is not None:
full_name = meta.display_name or meta.legal_name or id
groups = meta.groups or []
else:
full_name = entity.id
groups = []

return defer.succeed(
{
"email": email,
"full_name": full_name,
"groups": groups,
}
)
except netauth.error.NetAuthRpcError as e:
return defer.fail(e)
return threads.deferToThread(thr)
username = username.removesuffix("@netauth")

try:
entity = self.netauth.entity_info(username)

if entity is None:
return defer.fail(ValueError("entity not found"))

id = entity.id
email = f"{id}@netauth"
if (meta := entity.meta) is not None:
full_name = meta.display_name or meta.legal_name or id
groups = meta.groups or []
else:
full_name = entity.id
groups = []

return defer.succeed(
{
"email": email,
"full_name": full_name,
"groups": groups,
}
)
except netauth.error.NetAuthRpcError as e:
return defer.fail(e)

def getUserAvatar(self, email, username, size, defaultAvatarUrl):
print(repr(email), repr(username), repr(size), repr(defaultAvatarUrl))
username = bytes2unicode(username)
if username and username.endswith("@netauth"):
def thr():
try:
kv = self.netauth.entity_kv_get(username.removesuffix("@netauth"), "avatar")
avatar = kv.get("avatar")
if avatar:
raise resource.Redirect(avatar[0])
except netauth.error.NetAuthRpcError:
pass
return threads.deferToThread(thr)
username = username.removesuffix("@netauth")
try:
kv = self.netauth.entity_kv_get(username, "avatar")
avatar = kv.get("avatar")
if avatar:
raise resource.Redirect(avatar[0])
except netauth.error.NetAuthRpcError:
pass

0 comments on commit 8adba0b

Please sign in to comment.