Ejemplo n.º 1
0
def initiate_upload(namespace, repo_name, uuid, location_name,
                    storage_metadata):
    """ Initiates a blob upload for the repository with the given namespace and name,
      in a specific location. """
    repo = _basequery.get_existing_repository(namespace, repo_name)
    return initiate_upload_for_repo(repo, uuid, location_name,
                                    storage_metadata)
Ejemplo n.º 2
0
def get_repository(namespace_name, repository_name, kind_filter=None):
    try:
        return _basequery.get_existing_repository(namespace_name,
                                                  repository_name,
                                                  kind_filter=kind_filter)
    except Repository.DoesNotExist:
        return None
Ejemplo n.º 3
0
def create_email_authorization_for_repo(namespace_name, repository_name, email):
    try:
        repo = _basequery.get_existing_repository(namespace_name, repository_name)
    except Repository.DoesNotExist:
        raise DataModelException("Invalid repository %s/%s" % (namespace_name, repository_name))

    return RepositoryAuthorizedEmail.create(repository=repo, email=email, confirmed=False)
Ejemplo n.º 4
0
def get_app_repository(namespace_name, repository_name):
    """ Find an application repository. """
    try:
        return _basequery.get_existing_repository(namespace_name,
                                                  repository_name,
                                                  kind_filter="application")
    except Repository.DoesNotExist:
        return None
Ejemplo n.º 5
0
def purge_repository(namespace_name, repository_name):
  """ Completely delete all traces of the repository. Will return True upon
      complete success, and False upon partial or total failure. Garbage
      collection is incremental and repeatable, so this return value does
      not need to be checked or responded to.
      """
  try:
    repo = _basequery.get_existing_repository(namespace_name, repository_name)
  except Repository.DoesNotExist:
    return False

  assert repo.name == repository_name

  # Delete the repository of all Appr-referenced entries.
  # Note that new-model Tag's must be deleted in *two* passes, as they can reference parent tags,
  # and MySQL is... particular... about such relationships when deleting.
  if repo.kind.name == 'application':
    ApprTag.delete().where(ApprTag.repository == repo, ~(ApprTag.linked_tag >> None)).execute()
    ApprTag.delete().where(ApprTag.repository == repo).execute()
  else:
    # GC to remove the images and storage.
    _purge_repository_contents(repo)

  # Ensure there are no additional tags, manifests, images or blobs in the repository.
  assert ApprTag.select().where(ApprTag.repository == repo).count() == 0
  assert Tag.select().where(Tag.repository == repo).count() == 0
  assert RepositoryTag.select().where(RepositoryTag.repository == repo).count() == 0
  assert Manifest.select().where(Manifest.repository == repo).count() == 0
  assert ManifestBlob.select().where(ManifestBlob.repository == repo).count() == 0
  assert Image.select().where(Image.repository == repo).count() == 0

  # Delete the rest of the repository metadata.
  try:
    # Make sure the repository still exists.
    fetched = _basequery.get_existing_repository(namespace_name, repository_name)
  except Repository.DoesNotExist:
    return False

  fetched.delete_instance(recursive=True, delete_nullable=False)

  # Run callbacks
  for callback in config.repo_cleanup_callbacks:
    callback(namespace_name, repository_name)

  return True
Ejemplo n.º 6
0
def create_delegate_token(namespace_name,
                          repository_name,
                          friendly_name,
                          role="read"):
    read_only = Role.get(name=role)
    repo = _basequery.get_existing_repository(namespace_name, repository_name)
    new_token = AccessToken.create(repository=repo,
                                   role=read_only,
                                   friendly_name=friendly_name,
                                   temporary=False)

    return new_token
Ejemplo n.º 7
0
Archivo: tag.py Proyecto: zhill/quay
def store_tag_manifest_for_testing(namespace_name, repository_name, tag_name,
                                   manifest, leaf_layer_id, storage_id_map):
    """ Stores a tag manifest for a specific tag name in the database. Returns the TagManifest
      object, as well as a boolean indicating whether the TagManifest was created.
  """
    try:
        repo = _basequery.get_existing_repository(namespace_name,
                                                  repository_name)
    except Repository.DoesNotExist:
        raise DataModelException("Invalid repository %s/%s" %
                                 (namespace_name, repository_name))

    return store_tag_manifest_for_repo(repo.id, tag_name, manifest,
                                       leaf_layer_id, storage_id_map)
Ejemplo n.º 8
0
def store_blob_record_and_temp_link(namespace,
                                    repo_name,
                                    blob_digest,
                                    location_obj,
                                    byte_count,
                                    link_expiration_s,
                                    uncompressed_byte_count=None):
    repo = _basequery.get_existing_repository(namespace, repo_name)
    assert repo

    return store_blob_record_and_temp_link_in_repo(repo.id, blob_digest,
                                                   location_obj, byte_count,
                                                   link_expiration_s,
                                                   uncompressed_byte_count)
Ejemplo n.º 9
0
def __set_entity_repo_permission(entity, permission_entity_property,
                                 namespace_name, repository_name, role_name):
  repo = _basequery.get_existing_repository(namespace_name, repository_name)
  new_role = Role.get(Role.name == role_name)

  # Fetch any existing permission for this entity on the repo
  try:
    entity_attr = getattr(RepositoryPermission, permission_entity_property)
    perm = RepositoryPermission.get(entity_attr == entity, RepositoryPermission.repository == repo)
    perm.role = new_role
    perm.save()
    return perm
  except RepositoryPermission.DoesNotExist:
    set_entity_kwargs = {permission_entity_property: entity}
    new_perm = RepositoryPermission.create(repository=repo, role=new_role, **set_entity_kwargs)
    return new_perm
Ejemplo n.º 10
0
Archivo: tag.py Proyecto: zhill/quay
def create_or_update_tag(namespace_name,
                         repository_name,
                         tag_name,
                         tag_docker_image_id,
                         reversion=False,
                         now_ms=None):
    try:
        repo = _basequery.get_existing_repository(namespace_name,
                                                  repository_name)
    except Repository.DoesNotExist:
        raise DataModelException("Invalid repository %s/%s" %
                                 (namespace_name, repository_name))

    return create_or_update_tag_for_repo(repo.id,
                                         tag_name,
                                         tag_docker_image_id,
                                         reversion=reversion,
                                         now_ms=now_ms)