def push(namespace, package_name): reponame = repo_name(namespace, package_name) if not REPOSITORY_NAME_REGEX.match(package_name): logger.debug("Found invalid repository name CNR push: %s", reponame) raise InvalidUsage("invalid repository name: %s" % reponame) values = request.get_json(force=True, silent=True) or {} private = values.get("visibility", "private") owner = get_authenticated_user() if not Package.exists(reponame): if not CreateRepositoryPermission(namespace).can(): raise Forbidden( "Unauthorized access for: %s" % reponame, { "package": reponame, "scopes": ["create"] }, ) Package.create_repository(reponame, private, owner) logs_model.log_action("create_repo", namespace, repository_name=package_name) if not ModifyRepositoryPermission(namespace, package_name).can(): raise Forbidden("Unauthorized access for: %s" % reponame, { "package": reponame, "scopes": ["push"] }) if not "release" in values: raise InvalidUsage("Missing release") if not "media_type" in values: raise InvalidUsage("Missing media_type") if not "blob" in values: raise InvalidUsage("Missing blob") release_version = str(values["release"]) media_type = values["media_type"] force = request.args.get("force", "false") == "true" blob = Blob(reponame, values["blob"]) app_release = cnr_registry.push( reponame, release_version, media_type, blob, force, package_class=Package, user=owner, visibility=private, ) logs_model.log_action("push_repo", namespace, repository_name=package_name, metadata={"release": release_version}) return jsonify(app_release)
def _check_channel_name(channel_name, release=None): if not TAG_REGEX.match(channel_name): logger.debug('Found invalid channel name CNR add channel release: %s', channel_name) raise InvalidUsage("Found invalid channelname %s" % release, {'name': channel_name, 'release': release}) if release is not None and not TAG_REGEX.match(release): logger.debug('Found invalid release name CNR add channel release: %s', release) raise InvalidUsage('Found invalid channel release name %s' % release, {'name': channel_name, 'release': release})
def _check_channel_name(channel_name, release=None): if not TAG_REGEX.match(channel_name): logger.debug("Found invalid channel name CNR add channel release: %s", channel_name) raise InvalidUsage( "Found invalid channelname %s" % release, {"name": channel_name, "release": release} ) if release is not None and not TAG_REGEX.match(release): logger.debug("Found invalid release name CNR add channel release: %s", release) raise InvalidUsage( "Found invalid channel release name %s" % release, {"name": channel_name, "release": release}, )
def push(namespace, package_name): reponame = repo_name(namespace, package_name) if not REPOSITORY_NAME_REGEX.match(package_name): logger.debug('Found invalid repository name CNR push: %s', reponame) raise InvalidUsage('invalid repository name: %s' % reponame) values = request.get_json(force=True, silent=True) or {} private = values.get('visibility', 'private') owner = get_authenticated_user() if not Package.exists(reponame): if not CreateRepositoryPermission(namespace).can(): raise Forbidden("Unauthorized access for: %s" % reponame, {"package": reponame, "scopes": ['create']}) Package.create_repository(reponame, private, owner) logs_model.log_action('create_repo', namespace, repository_name=package_name) if not ModifyRepositoryPermission(namespace, package_name).can(): raise Forbidden("Unauthorized access for: %s" % reponame, {"package": reponame, "scopes": ['push']}) if not 'release' in values: raise InvalidUsage('Missing release') if not 'media_type' in values: raise InvalidUsage('Missing media_type') if not 'blob' in values: raise InvalidUsage('Missing blob') release_version = str(values['release']) media_type = values['media_type'] force = request.args.get('force', 'false') == 'true' blob = Blob(reponame, values['blob']) app_release = cnr_registry.push(reponame, release_version, media_type, blob, force, package_class=Package, user=owner, visibility=private) logs_model.log_action('push_repo', namespace, repository_name=package_name, metadata={'release': release_version}) return jsonify(app_release)
def login(): values = request.get_json(force=True, silent=True) or {} username = values.get('user', {}).get('username') password = values.get('user', {}).get('password') if not username or not password: raise InvalidUsage('Missing username or password') result, _ = validate_credentials(username, password) if not result.auth_valid: raise UnauthorizedAccess(result.error_message) return jsonify({'token': "basic " + b64encode("%s:%s" % (username, password))})
def login(): values = request.get_json(force=True, silent=True) or {} username = values.get("user", {}).get("username") password = values.get("user", {}).get("password") if not username or not password: raise InvalidUsage("Missing username or password") result, _ = validate_credentials(username, password) if not result.auth_valid: raise UnauthorizedAccess(result.error_message) auth = b64encode(b"%s:%s" % (username.encode("ascii"), password.encode("ascii"))) return jsonify({"token": "basic " + auth.decode("ascii")})
def _check(name, scope): if name is None: raise InvalidUsage("%s: %s is malformed" % (scope, name), {'name': name})
def test_error(): raise InvalidUsage("error message", {"path": request.path})