Add flag to enable trust per repo (#2541)
* Add flag to enable trust per repo * Add api for enabling/disabling trust * Add new LogEntryKind for changing repo trust settings Also add tests for repo trust api * Add `set_trust` method to repository * Expose new logkind to UI * Fix registry tests * Rebase migrations and regen test.db * Raise downstreamissue if trust metadata can't be removed * Refactor change_repo_trust * Add show_if to change_repo_trust endpoint
This commit is contained in:
parent
aa1c8d47dd
commit
2661db7485
13 changed files with 176 additions and 12 deletions
|
@ -568,6 +568,7 @@ class Repository(BaseModel):
|
|||
description = FullIndexedTextField(match_function=db_match_func, null=True)
|
||||
badge_token = CharField(default=uuid_generator)
|
||||
kind = EnumField(RepositoryKind)
|
||||
trust_enabled = BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
|
|
|
@ -13,7 +13,7 @@ _MEDIA_TYPE = "application/vnd.docker.distribution.manifest.v1+prettyjws"
|
|||
|
||||
|
||||
class Repository(namedtuple('Repository', ['id', 'name', 'namespace_name', 'description',
|
||||
'is_public', 'kind'])):
|
||||
'is_public', 'kind', 'trust_enabled'])):
|
||||
"""
|
||||
Repository represents a namespaced collection of tags.
|
||||
:type id: int
|
||||
|
@ -22,6 +22,7 @@ class Repository(namedtuple('Repository', ['id', 'name', 'namespace_name', 'desc
|
|||
:type description: string
|
||||
:type is_public: bool
|
||||
:type kind: string
|
||||
:type trust_enabled: bool
|
||||
"""
|
||||
|
||||
class ManifestJSON(namedtuple('ManifestJSON', ['digest', 'json', 'media_type'])):
|
||||
|
@ -536,6 +537,7 @@ def _repository_for_repo(repo):
|
|||
description=repo.description,
|
||||
is_public=model.repository.is_repository_public(repo),
|
||||
kind=model.repository.get_repo_kind_name(repo),
|
||||
trust_enabled=repo.trust_enabled,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
"""Add trust_enabled to repository
|
||||
|
||||
Revision ID: ed01e313d3cb
|
||||
Revises: c3d4b7ebcdf7
|
||||
Create Date: 2017-04-14 17:38:03.319695
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ed01e313d3cb'
|
||||
down_revision = 'c3d4b7ebcdf7'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
def upgrade(tables):
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('repository', sa.Column('trust_enabled', sa.Boolean(), nullable=False))
|
||||
### end Alembic commands ###
|
||||
op.bulk_insert(tables.logentrykind, [
|
||||
{'name': 'change_repo_trust'},
|
||||
])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('repository', 'trust_enabled')
|
||||
### end Alembic commands ###
|
||||
|
||||
op.execute(tables
|
||||
.logentrykind
|
||||
.delete()
|
||||
.where(tables.
|
||||
logentrykind.name == op.inline_literal('change_repo_trust')))
|
|
@ -279,6 +279,11 @@ def unstar_repository(user, repository):
|
|||
.execute())
|
||||
except Star.DoesNotExist:
|
||||
raise DataModelException('Star not found.')
|
||||
|
||||
|
||||
def set_trust(repo, trust_enabled):
|
||||
repo.trust_enabled = trust_enabled
|
||||
repo.save()
|
||||
|
||||
|
||||
def get_user_starred_repositories(user, kind_filter='image'):
|
||||
|
|
Reference in a new issue