Exemple #1
0
def delete_channel(namespace, package_name, channel_name):
  _check_channel_name(channel_name)
  reponame = repo_name(namespace, package_name)
  result = cnr_registry.delete_channel(reponame, channel_name, channel_class=Channel)
  logs_model.log_action('delete_tag', namespace, repository_name=package_name,
                        metadata={'channel': channel_name})
  return jsonify(result)
Exemple #2
0
def show_package_releases(namespace, package_name):
    reponame = repo_name(namespace, package_name)
    media_type = request.args.get("media_type", None)
    result = cnr_registry.show_package_releases(reponame,
                                                media_type=media_type,
                                                package_class=Package)
    return jsonify(result)
Exemple #3
0
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)
Exemple #4
0
 def _retrieve_package():
     reponame = repo_name(namespace, package_name)
     return cnr_registry.show_package(reponame,
                                      release,
                                      media_type,
                                      channel_class=Channel,
                                      package_class=Package)
Exemple #5
0
def add_channel_release(namespace, package_name, channel_name, release):
  _check_channel_name(channel_name, release)
  reponame = repo_name(namespace, package_name)
  result = cnr_registry.add_channel_release(reponame, channel_name, release, channel_class=Channel,
                                            package_class=Package)
  logs_model.log_action('create_tag', namespace, repository_name=package_name,
                        metadata={'channel': channel_name, 'release': release})
  return jsonify(result)
Exemple #6
0
def pull(namespace, package_name, release, media_type):
  logger.debug('Pull of release %s of app repository %s/%s', release, namespace, package_name)
  reponame = repo_name(namespace, package_name)
  data = cnr_registry.pull(reponame, release, media_type, Package, blob_class=Blob)
  logs_model.log_action('pull_repo', namespace, repository_name=package_name,
                        metadata={'release': release, 'mediatype': media_type})
  json_format = request.args.get('format', None) == 'json'
  return _pull(data, json_format)
Exemple #7
0
def show_package(namespace, package_name, release, media_type):
    reponame = repo_name(namespace, package_name)
    result = cnr_registry.show_package(reponame,
                                       release,
                                       media_type,
                                       channel_class=Channel,
                                       package_class=Package)
    return jsonify(result)
Exemple #8
0
def delete_package(namespace, package_name, release, media_type):
    reponame = repo_name(namespace, package_name)
    result = cnr_registry.delete_package(reponame, release, media_type, package_class=Package)
    logs_model.log_action(
        "delete_tag",
        namespace,
        repository_name=package_name,
        metadata={"release": release, "mediatype": media_type},
    )
    return jsonify(result)
Exemple #9
0
def pull(namespace, package_name, release, media_type):
    logger.debug("Pull of release %s of app repository %s/%s", release, namespace, package_name)
    reponame = repo_name(namespace, package_name)
    data = cnr_registry.pull(reponame, release, media_type, Package, blob_class=Blob)
    logs_model.log_action(
        "pull_repo",
        namespace,
        repository_name=package_name,
        metadata={"release": release, "mediatype": media_type},
    )
    json_format = request.args.get("format", None) == "json"
    return _pull(data, json_format)
Exemple #10
0
def delete_channel_release(namespace, package_name, channel_name, release):
    _check_channel_name(channel_name, release)
    reponame = repo_name(namespace, package_name)
    result = cnr_registry.delete_channel_release(
        reponame, channel_name, release, channel_class=Channel, package_class=Package
    )
    logs_model.log_action(
        "delete_tag",
        namespace,
        repository_name=package_name,
        metadata={"channel": channel_name, "release": release},
    )
    return jsonify(result)
Exemple #11
0
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)
Exemple #12
0
def blobs(namespace, package_name, digest):
  reponame = repo_name(namespace, package_name)
  data = cnr_registry.pull_blob(reponame, digest, blob_class=Blob)
  json_format = request.args.get('format', None) == 'json'
  return _pull(data, json_format=json_format)
Exemple #13
0
def show_channel(namespace, package_name, channel_name):
  reponame = repo_name(namespace, package_name)
  channel = cnr_registry.show_channel(reponame, channel_name, channel_class=Channel)
  return jsonify(channel)
Exemple #14
0
def list_channels(namespace, package_name):
  reponame = repo_name(namespace, package_name)
  return jsonify(cnr_registry.list_channels(reponame, channel_class=Channel))
Exemple #15
0
def show_package_release_manifests(namespace, package_name, release):
  reponame = repo_name(namespace, package_name)
  result = cnr_registry.show_package_manifests(reponame, release, package_class=Package)
  return jsonify(result)