Exemplo n.º 1
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)
Exemplo n.º 2
0
 def reset_db(cls, force=False):
     """ clean the database """
     if os.getenv("CNR_DB_ALLOW_RESET", "false") == "true" or force:
         try:
             etcd_client.delete(cnr.models.kv.CNR_KV_PREFIX, recursive=True)
         except etcd.EtcdKeyNotFound:
             pass
     else:
         raise Forbidden("Reset DB is deactivated")
Exemplo n.º 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)
Exemplo n.º 4
0
 def reset_db(cls, force=False):
     """ clean the database """
     if os.getenv("CNR_DB_ALLOW_RESET", "false") == "true" or force:
         raise NotImplementedError
     else:
         raise Forbidden("Reset DB is deactivated")
Exemplo n.º 5
0
 def reset_db(cls, force=False):
     """ clean the database """
     if os.getenv("CNR_DB_ALLOW_RESET", "false") == "true" or force:
         redis_client.flushall()
     else:
         raise Forbidden("Reset DB is deactivated")
Exemplo n.º 6
0
def _raise_method(repository, scopes):
  raise Forbidden("Unauthorized access for: %s" % repository,
                  {"package": repository, "scopes": scopes})
Exemplo n.º 7
0
 def reset_db(cls, force=False):
     """ clean the database """
     if os.getenv("CNR_DB_ALLOW_RESET", "false") == "true" or force:
         filesystem_client.flushall(cnr.models.kv.CNR_KV_PREFIX)
     else:
         raise Forbidden("Reset DB is deactivated")