packagers support (#100)

This commit is contained in:
2023-06-05 02:37:19 +03:00
committed by GitHub
parent d495163fdd
commit 4b984afb64
89 changed files with 849 additions and 318 deletions

View File

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

View File

@ -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>",
})

View File

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

View File

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

View File

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

View File

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

View File

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