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 2d0042a commit ddccf19
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions buildbot_netauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from buildbot.www import resource
from buildbot.www.avatar import AvatarBase
from buildbot.www.auth import UserInfoProviderBase, bytes2unicode
from twisted.internet import defer
from twisted.internet import defer, threads
from twisted.cred.error import UnauthorizedLogin

__version__ = "0.0.1"
Expand Down Expand Up @@ -34,7 +34,7 @@ def __init__(self, *, conf: Path | None = None, **kwargs):

def requestAvatarId(self, cred):
if self.check_credentials(cred.username, cred.password):
return defer.succeed(f"{cred.username}@netauth")
return defer.succeed(cred.username + b"@netauth")
return defer.fail(UnauthorizedLogin())

def check_credentials(self, username: str, password: str) -> bool:
Expand All @@ -51,39 +51,43 @@ def getUserInfo(self, username):
if not username:
return defer.fail(ValueError("username not found"))

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 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)

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"):
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
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)

0 comments on commit ddccf19

Please sign in to comment.