def post(self, namespace, repository): """ Change the visibility of a repository. """ if not model.repo_exists(namespace, repository): raise NotFound() tags, _ = tuf_metadata_api.get_default_tags_with_expiration( namespace, repository) if tags and not tuf_metadata_api.delete_metadata( namespace, repository): raise DownstreamIssue("Unable to delete downstream trust metadata") values = request.get_json() model.set_trust(namespace, repository, values["trust_enabled"]) log_action( "change_repo_trust", namespace, { "repo": repository, "namespace": namespace, "trust_enabled": values["trust_enabled"] }, repo_name=repository, ) return {"success": True}
def put(self, namespace, repository): """ Change the state of a repository. """ if not model.repo_exists(namespace, repository): raise NotFound() values = request.get_json() state_name = values['state'] try: state = RepositoryState[state_name] except KeyError: state = None if state == RepositoryState.MIRROR and not features.REPO_MIRROR: return {'detail': 'Unknown Repository State: %s' % state_name}, 400 if state is None: return { 'detail': '%s is not a valid Repository state.' % state_name }, 400 model.set_repository_state(namespace, repository, state) log_action('change_repo_state', namespace, { 'repo': repository, 'namespace': namespace, 'state_changed': state_name }, repo_name=repository) return {'success': True}
def put(self, namespace, repository): """ Change the state of a repository. """ if not model.repo_exists(namespace, repository): raise NotFound() values = request.get_json() state_name = values["state"] try: state = RepositoryState[state_name] except KeyError: state = None if state == RepositoryState.MIRROR and not features.REPO_MIRROR: return {"detail": "Unknown Repository State: %s" % state_name}, 400 if state is None: return {"detail": "%s is not a valid Repository state." % state_name}, 400 model.set_repository_state(namespace, repository, state) log_action( "change_repo_state", namespace, {"repo": repository, "namespace": namespace, "state_changed": state_name}, repo_name=repository, ) return {"success": True}
def post(self): """ Create a new repository. """ owner = get_authenticated_user() req = request.get_json() if owner is None and "namespace" not in "req": raise InvalidRequest( "Must provide a namespace or must be logged in.") namespace_name = req[ "namespace"] if "namespace" in req else owner.username permission = CreateRepositoryPermission(namespace_name) if permission.can(): repository_name = req["repository"] visibility = req["visibility"] if model.repo_exists(namespace_name, repository_name): raise request_error(message="Repository already exists") visibility = req["visibility"] if visibility == "private": check_allowed_private_repos(namespace_name) # Verify that the repository name is valid. if not REPOSITORY_NAME_REGEX.match(repository_name): raise InvalidRequest("Invalid repository name") kind = req.get("repo_kind", "image") or "image" created = model.create_repo( namespace_name, repository_name, owner, req["description"], visibility=visibility, repo_kind=kind, ) if created is None: raise InvalidRequest("Could not create repository") log_action( "create_repo", namespace_name, { "repo": repository_name, "namespace": namespace_name }, repo_name=repository_name, ) return { "namespace": namespace_name, "name": repository_name, "kind": kind, }, 201 raise Unauthorized()
def post(self): """Create a new repository.""" owner = get_authenticated_user() req = request.get_json() if owner is None and 'namespace' not in 'req': raise InvalidRequest( 'Must provide a namespace or must be logged in.') namespace_name = req[ 'namespace'] if 'namespace' in req else owner.username permission = CreateRepositoryPermission(namespace_name) if permission.can(): repository_name = req['repository'] visibility = req['visibility'] if model.repo_exists(namespace_name, repository_name): raise request_error(message='Repository already exists') visibility = req['visibility'] if visibility == 'private': check_allowed_private_repos(namespace_name) # Verify that the repository name is valid. if not REPOSITORY_NAME_REGEX.match(repository_name): raise InvalidRequest('Invalid repository name') kind = req.get('repo_kind', 'image') or 'image' model.create_repo(namespace_name, repository_name, owner, req['description'], visibility=visibility, repo_kind=kind) log_action('create_repo', namespace_name, { 'repo': repository_name, 'namespace': namespace_name }, repo_name=repository_name) return { 'namespace': namespace_name, 'name': repository_name, 'kind': kind, }, 201 raise Unauthorized()
def put(self, namespace, repository): """ Update the description in the specified repository. """ if not model.repo_exists(namespace, repository): raise NotFound() values = request.get_json() model.set_description(namespace, repository, values["description"]) log_action( "set_repo_description", namespace, {"repo": repository, "namespace": namespace, "description": values["description"]}, repo_name=repository, ) return {"success": True}
def put(self, namespace, repository): """ Update the description in the specified repository. """ if not model.repo_exists(namespace, repository): raise NotFound() values = request.get_json() model.set_description(namespace, repository, values['description']) log_action('set_repo_description', namespace, { 'repo': repository, 'namespace': namespace, 'description': values['description'] }, repo_name=repository) return {'success': True}
def post(self, namespace, repository): """ Change the visibility of a repository. """ if model.repo_exists(namespace, repository): values = request.get_json() visibility = values["visibility"] if visibility == "private": check_allowed_private_repos(namespace) model.set_repository_visibility(namespace, repository, visibility) log_action( "change_repo_visibility", namespace, {"repo": repository, "namespace": namespace, "visibility": values["visibility"]}, repo_name=repository, ) return {"success": True}
def post(self, namespace, repository): """ Change the visibility of a repository. """ if model.repo_exists(namespace, repository): values = request.get_json() visibility = values['visibility'] if visibility == 'private': check_allowed_private_repos(namespace) model.set_repository_visibility(namespace, repository, visibility) log_action('change_repo_visibility', namespace, { 'repo': repository, 'namespace': namespace, 'visibility': values['visibility'] }, repo_name=repository) return {'success': True}
def post(self, namespace, repository): """ Change the visibility of a repository. """ if not model.repo_exists(namespace, repository): raise NotFound() tags, _ = tuf_metadata_api.get_default_tags_with_expiration( namespace, repository) if tags and not tuf_metadata_api.delete_metadata( namespace, repository): raise DownstreamIssue('Unable to delete downstream trust metadata') values = request.get_json() model.set_trust(namespace, repository, values['trust_enabled']) log_action('change_repo_trust', namespace, { 'repo': repository, 'namespace': namespace, 'trust_enabled': values['trust_enabled'] }, repo_name=repository) return {'success': True}