mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-29 21:09:55 +00:00
packagers support (#100)
This commit is contained in:
@ -148,7 +148,7 @@ def setup_auth(application: Application, configuration: Configuration, validator
|
||||
setup_session(application, storage)
|
||||
|
||||
authorization_policy = _AuthorizationPolicy(validator)
|
||||
identity_policy = aiohttp_security.SessionIdentityPolicy()
|
||||
identity_policy = application["identity"] = aiohttp_security.SessionIdentityPolicy()
|
||||
|
||||
aiohttp_security.setup(application, identity_policy, authorization_policy)
|
||||
application.middlewares.append(_auth_handler(validator.allow_read_only))
|
||||
|
@ -44,3 +44,7 @@ class PackageSchema(Schema):
|
||||
keys=fields.String(), values=fields.Nested(PackagePropertiesSchema()), required=True, metadata={
|
||||
"description": "Packages which belong to this base",
|
||||
})
|
||||
packager = fields.String(metadata={
|
||||
"description": "packager for the last success package build",
|
||||
"example": "John Doe <john@doe.com>",
|
||||
})
|
||||
|
@ -183,3 +183,16 @@ class BaseView(View, CorsViewMixin):
|
||||
return response
|
||||
|
||||
self._raise_allowed_methods()
|
||||
|
||||
async def username(self) -> str | None:
|
||||
"""
|
||||
extract username from request if any
|
||||
|
||||
Returns:
|
||||
str | None: authorized username if any and None otherwise (e.g. if authorization is disabled)
|
||||
"""
|
||||
policy = self.request.app.get("identity")
|
||||
if policy is not None:
|
||||
identity: str = await policy.identify(self.request)
|
||||
return identity
|
||||
return None
|
||||
|
@ -67,6 +67,7 @@ class AddView(BaseView):
|
||||
except Exception as e:
|
||||
raise HTTPBadRequest(reason=str(e))
|
||||
|
||||
self.spawner.packages_add(packages, now=True)
|
||||
username = await self.username()
|
||||
self.spawner.packages_add(packages, username, now=True)
|
||||
|
||||
raise HTTPNoContent()
|
||||
|
@ -68,6 +68,7 @@ class RebuildView(BaseView):
|
||||
except Exception as e:
|
||||
raise HTTPBadRequest(reason=str(e))
|
||||
|
||||
self.spawner.packages_rebuild(depends_on)
|
||||
username = await self.username()
|
||||
self.spawner.packages_rebuild(depends_on, username)
|
||||
|
||||
raise HTTPNoContent()
|
||||
|
@ -67,6 +67,7 @@ class RequestView(BaseView):
|
||||
except Exception as e:
|
||||
raise HTTPBadRequest(reason=str(e))
|
||||
|
||||
self.spawner.packages_add(packages, now=False)
|
||||
username = await self.username()
|
||||
self.spawner.packages_add(packages, username, now=False)
|
||||
|
||||
raise HTTPNoContent()
|
||||
|
@ -57,6 +57,7 @@ class UpdateView(BaseView):
|
||||
Raises:
|
||||
HTTPNoContent: in case of success response
|
||||
"""
|
||||
self.spawner.packages_update()
|
||||
username = await self.username()
|
||||
self.spawner.packages_update(username)
|
||||
|
||||
raise HTTPNoContent()
|
||||
|
Reference in New Issue
Block a user