Esempio n. 1
0
def rollback(mirror, since_ms):
    """

  :param mirror: Mirror to perform rollback on
  :param start_time: Time mirror was started; all changes after will be undone
  :return:
  """

    repository_ref = registry_model.lookup_repository(
        mirror.repository.namespace_user.username, mirror.repository.name)
    tags, has_more = registry_model.list_repository_tag_history(
        repository_ref, 1, 100, since_time_ms=since_ms)
    for tag in tags:
        logger.debug("Repo mirroring rollback tag '%s'" % tag)

        # If the tag has an end time, it was either deleted or moved.
        if tag.lifetime_end_ms:
            #  If a future entry exists with a start time equal to the end time for this tag,
            # then the action was a move, rather than a delete and a create.
            newer_tag = filter(
                lambda t: tag != t and tag.name == t.name and tag.
                lifetime_end_ms and t.lifetime_start_ms == tag.lifetime_end_ms,
                tags,
            )[0]
            if newer_tag:
                logger.debug("Repo mirroring rollback revert tag '%s'" % tag)
                retarget_tag(tag.name, tag.manifest._db_id, is_reversion=True)
            else:
                logger.debug("Repo mirroring recreate tag '%s'" % tag)
                retarget_tag(tag.name, tag.manifest._db_id, is_reversion=True)

        #  If the tag has a start time, it was created.
        elif tag.lifetime_start_ms:
            logger.debug("Repo mirroring rollback delete tag '%s'" % tag)
            delete_tag(mirror.repository, tag.name)
Esempio n. 2
0
    def get_repo(self,
                 namespace_name,
                 repository_name,
                 user,
                 include_tags=True,
                 max_tags=500):
        repo = model.repository.get_repository(namespace_name, repository_name)
        if repo is None:
            return None

        is_starred = model.repository.repository_is_starred(
            user, repo) if user else False
        is_public = model.repository.is_repository_public(repo)
        kind_name = RepositoryTable.kind.get_name(repo.kind_id)
        base = RepositoryBaseElement(
            namespace_name, repository_name, is_starred, is_public, kind_name,
            repo.description, repo.namespace_user.organization,
            repo.namespace_user.removed_tag_expiration_s, None, None, False,
            False, False, repo.namespace_user.stripe_id is None, repo.state)

        if base.kind_name == 'application':
            channels = channel_model.get_repo_channels(repo,
                                                       appr_model.models_ref)
            releases = release_model.get_release_objs(repo,
                                                      appr_model.models_ref)
            releases_channels_map = defaultdict(list)
            return ApplicationRepository(base, [
                _create_channel(channel, releases_channels_map)
                for channel in channels
            ], [
                Release(release.name, release.lifetime_start,
                        releases_channels_map) for release in releases
            ], repo.state)

        tags = None
        repo_ref = RepositoryReference.for_repo_obj(repo)
        if include_tags:
            tags, _ = registry_model.list_repository_tag_history(
                repo_ref, page=1, size=max_tags, active_tags_only=True)
            tags = [
                Tag(
                    tag.name, tag.legacy_image.docker_image_id
                    if tag.legacy_image_if_present else None,
                    tag.legacy_image.aggregate_size
                    if tag.legacy_image_if_present else None,
                    tag.lifetime_start_ts, tag.manifest_digest,
                    tag.lifetime_end_ts) for tag in tags
            ]

        start_date = datetime.now() - timedelta(days=MAX_DAYS_IN_3_MONTHS)
        counts = model.log.get_repository_action_counts(repo, start_date)

        assert repo.state is not None
        return ImageRepositoryRepository(
            base, tags, [Count(count.date, count.count) for count in counts],
            repo.badge_token, repo.trust_enabled, repo.state)
Esempio n. 3
0
def test_list_repo_tags(repo_namespace, repo_name, client, query_count, app):
    # Pre-cache media type loads to ensure consistent query count.
    Manifest.media_type.get_name(1)

    params = {"repository": repo_namespace + "/" + repo_name}
    with client_with_identity("devtable", client) as cl:
        with assert_query_count(query_count):
            tags = conduct_api_call(cl, ListRepositoryTags, "get",
                                    params).json["tags"]

        repo_ref = registry_model.lookup_repository(repo_namespace, repo_name)
        history, _ = registry_model.list_repository_tag_history(repo_ref)
        assert len(tags) == len(history)
Esempio n. 4
0
def rollback(mirror, since_ms):
    """
    :param mirror: Mirror to perform rollback on
    :param start_time: Time mirror was started; all changes after will be undone
    :return:
    """

    repository_ref = registry_model.lookup_repository(
        mirror.repository.namespace_user.username, mirror.repository.name)

    tags = []
    index = 1
    has_more = True
    while has_more:
        tags_page, has_more = registry_model.list_repository_tag_history(
            repository_ref,
            index,
            TAG_ROLLBACK_PAGE_SIZE,
            since_time_ms=since_ms)
        tags.extend(tags_page)
        index = index + 1

    for tag in tags:
        logger.debug("Repo mirroring rollback tag '%s'" % tag)

        # If the tag has an end time, it was either deleted or moved.
        if tag.lifetime_end_ms:
            #  If a future entry exists with a start time equal to the end time for this tag,
            # then the action was a move, rather than a delete and a create.
            tag_list = list(
                filter(
                    lambda t: tag != t and tag.name == t.name and tag.
                    lifetime_end_ms and t.lifetime_start_ms == tag.
                    lifetime_end_ms,
                    tags,
                ))
            if len(tag_list) > 0:
                logger.debug("Repo mirroring rollback revert tag '%s'" % tag)
                retarget_tag(tag.name, tag.manifest._db_id, is_reversion=True)
            else:
                logger.debug("Repo mirroring recreate tag '%s'" % tag)
                retarget_tag(tag.name, tag.manifest._db_id, is_reversion=True)

        #  If the tag has a start time, it was created.
        elif tag.lifetime_start_ms:
            logger.debug("Repo mirroring rollback delete tag '%s'" % tag)
            delete_tag(mirror.repository, tag.name)
Esempio n. 5
0
File: tag.py Progetto: xzwupeng/quay
    def get(self, namespace, repository, parsed_args):
        specific_tag = parsed_args.get('specificTag') or None
        page = max(1, parsed_args.get('page', 1))
        limit = min(100, max(1, parsed_args.get('limit', 50)))
        active_tags_only = parsed_args.get('onlyActiveTags')

        repo_ref = registry_model.lookup_repository(namespace, repository)
        if repo_ref is None:
            raise NotFound()

        history, has_more = registry_model.list_repository_tag_history(
            repo_ref,
            page=page,
            size=limit,
            specific_tag_name=specific_tag,
            active_tags_only=active_tags_only)
        return {
            'tags': [_tag_dict(tag) for tag in history],
            'page': page,
            'has_additional': has_more,
        }
Esempio n. 6
0
    def get(self, namespace, repository, parsed_args):
        specific_tag = parsed_args.get("specificTag") or None
        page = max(1, parsed_args.get("page", 1))
        limit = min(100, max(1, parsed_args.get("limit", 50)))
        active_tags_only = parsed_args.get("onlyActiveTags")

        repo_ref = registry_model.lookup_repository(namespace, repository)
        if repo_ref is None:
            raise NotFound()

        history, has_more = registry_model.list_repository_tag_history(
            repo_ref,
            page=page,
            size=limit,
            specific_tag_name=specific_tag,
            active_tags_only=active_tags_only,
        )
        return {
            "tags": [_tag_dict(tag) for tag in history],
            "page": page,
            "has_additional": has_more,
        }