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 d429880 commit 65c0d04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 38 deletions.
45 changes: 10 additions & 35 deletions buildbot_netauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from abc import ABC
from pathlib import Path

import netauth
Expand All @@ -12,33 +11,24 @@
__version__ = "0.0.1"


class NetAuthPlugin(ABC):
class BuildbotNetAuth(util.CustomAuth, AvatarBase, UserInfoProviderBase):
"""
NetAuth buildbot plugin base
NetAuth authentication, user info, and avatar provider
:param na_inst: a NetAuth instance (useful if also using the UserInfoProvider), optional
:param conf: path to a NetAuth config file, optional, ignored if `na_inst` is provided
:param kwargs: all other keyword arguments are passed to the NetAuth instance, if it is created internally
"""

def __init__(self, *, na_inst: netauth.NetAuth | None = None, conf: Path | None = None, **kwargs):
if na_inst is not None:
self.netauth = na_inst
self.netauth.service_name = "buildbot"
else:
kwargs["service_name"] = "buildbot"
if conf is not None:
self.netauth = netauth.NetAuth.with_config(conf, **kwargs)
else:
self.netauth = netauth.NetAuth(**kwargs)
super().__init__()

def __init__(self, *, conf: Path | None = None, **kwargs):
kwargs["service_name"] = "buildbot"

if conf is not None:
self.netauth = netauth.NetAuth.with_config(conf, **kwargs)
else:
self.netauth = netauth.NetAuth(**kwargs)

class NetAuthAuth(NetAuthPlugin, util.CustomAuth):
"""NetAuth authentication provider"""
def __init__(self, *, na_inst: netauth.NetAuth | None = None, conf: Path | None = None, **kwargs):
super().__init__(na_inst=na_inst, conf=conf, **kwargs)
super().__init__()

def requestAvatarId(self, cred):
if self.check_credentials(cred.username, cred.password):
Expand All @@ -52,13 +42,6 @@ def check_credentials(self, username: str, password: str) -> bool:
except netauth.error.UnauthenticatedError:
return False


class NetAuthUserInfo(NetAuthPlugin, UserInfoProviderBase):
"""NetAuth user info provider"""

def __init__(self, *, na_inst: netauth.NetAuth | None = None, conf: Path | None = None, **kwargs):
super().__init__(na_inst=na_inst, conf=conf, **kwargs)

def getUserInfo(self, username):
try:
entity = self.netauth.entity_info(username)
Expand All @@ -85,16 +68,8 @@ def getUserInfo(self, username):
except netauth.error.NetAuthRpcError as e:
return defer.fail(e)


class AvatarNetAuth(NetAuthPlugin, AvatarBase):
"""NetAuth avatar provider"""

name = "netauth"

def __init__(self, *, na_inst: netauth.NetAuth | None = None, conf: Path | None = None, **kwargs):
super().__init__(na_inst=na_inst, conf=conf, **kwargs)

def getUserAvatar(self, email, username, size, defaultAvatarUrl):
print(repr(email), repr(username), repr(size), repr(defaultAvatarUrl))
if username.endswith("@netauth"):
try:
kv = self.netauth.entity_kv_get(username.removesuffix("@netauth"), "avatar")
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ publish = [
]

[project.entry-points."buildbot.util"]
NetAuthAuth = "buildbot_netauth:NetAuthAuth"
NetAuthUserInfo = "buildbot_netauth:NetAuthUserInfo"
AvatarNetAuth = "buildbot_netauth:AvatarNetAuth"
BuildbotNetAuth = "buildbot_netauth:BuildbotNetAuth"

[project.urls]
Repository = "https://github.com/classabbyamp/buildbot-netauth"
Expand Down

0 comments on commit 65c0d04

Please sign in to comment.