Example #1
0
    def list_applications(self,
                          namespace=None,
                          media_type=None,
                          search=None,
                          username=None,
                          with_channels=False):
        """
        Lists all repositories that contain applications, with optional filtering to a specific
        namespace and view a specific user.
        """
        limit = app.config.get("APP_REGISTRY_RESULTS_LIMIT", 50)
        namespace_whitelist = app.config.get(
            "APP_REGISTRY_PACKAGE_LIST_CACHE_WHITELIST", [])

        # NOTE: This caching only applies for the super-large and commonly requested results
        # sets.
        if (namespace is not None and namespace in namespace_whitelist
                and media_type is None and search is None and username is None
                and not with_channels):

            def _list_applications():
                return [
                    found._asdict()
                    for found in self._list_applications(namespace=namespace,
                                                         limit=limit)
                ]

            apps_cache_key = cache_key.for_appr_applications_list(
                namespace, limit)
            results = [
                CachedApplication(**found) for found in model_cache.retrieve(
                    apps_cache_key, _list_applications)
            ]
        else:
            results = self._list_applications(namespace,
                                              media_type,
                                              search,
                                              username,
                                              with_channels,
                                              limit=limit)

        return [
            ApplicationSummaryView(
                namespace=result.namespace,
                name=result.name,
                visibility=result.visibility,
                default=result.tag_names[0] if result.tag_names else None,
                channels=[
                    ChannelView(name=channel.name,
                                current=channel.linked_tag_name)
                    for channel in result.channels
                ] if result.channels is not None else None,
                manifests=result.manifests,
                releases=result.tag_names,
                updated_at=_timestamp_to_iso(result.latest_lifetime_start),
                created_at=_timestamp_to_iso(result.first_lifetime_start),
            ) for result in results
        ]
Example #2
0
    def _list_applications(
        self,
        namespace=None,
        media_type=None,
        search=None,
        username=None,
        with_channels=False,
        limit=None,
    ):
        limit = limit or app.config.get("APP_REGISTRY_RESULTS_LIMIT", 50)
        views = []
        for repo in appr_model.package.list_packages_query(self.models_ref,
                                                           namespace,
                                                           media_type,
                                                           search,
                                                           username=username,
                                                           limit=limit):
            tag_set_prefetch = getattr(repo,
                                       self.models_ref.tag_set_prefetch_name)
            releases = [t.name for t in tag_set_prefetch]
            if not releases:
                continue
            available_releases = [
                str(x) for x in sorted(cnr.semver.versions(releases, False),
                                       reverse=True)
            ]
            channels = None
            if with_channels:
                channels = [
                    ChannelView(name=chan.name, current=chan.linked_tag.name)
                    for chan in appr_model.channel.get_repo_channels(
                        repo, self.models_ref)
                ]

            app_name = _join_package_name(repo.namespace_user.username,
                                          repo.name)
            manifests = self.list_manifests(app_name, available_releases[0])
            view = ApplicationSummaryView(
                namespace=repo.namespace_user.username,
                name=app_name,
                visibility=data_model.repository.repository_visibility_name(
                    repo),
                default=available_releases[0],
                channels=channels,
                manifests=manifests,
                releases=available_releases,
                updated_at=_timestamp_to_iso(
                    tag_set_prefetch[-1].lifetime_start),
                created_at=_timestamp_to_iso(
                    tag_set_prefetch[0].lifetime_start),
            )
            views.append(view)

        return views
Example #3
0
    def list_applications(self,
                          namespace=None,
                          media_type=None,
                          search=None,
                          username=None,
                          with_channels=False):
        """ Lists all repositories that contain applications, with optional filtering to a specific
        namespace and view a specific user.
    """

        views = []
        for repo in appr_model.package.list_packages_query(self.models_ref,
                                                           namespace,
                                                           media_type,
                                                           search,
                                                           username=username):
            tag_set_prefetch = getattr(repo,
                                       self.models_ref.tag_set_prefetch_name)
            releases = [t.name for t in tag_set_prefetch]
            if not releases:
                continue
            available_releases = [
                str(x) for x in sorted(cnr.semver.versions(releases, False),
                                       reverse=True)
            ]
            channels = None
            if with_channels:
                channels = [
                    ChannelView(name=chan.name, current=chan.linked_tag.name)
                    for chan in appr_model.channel.get_repo_channels(
                        repo, self.models_ref)
                ]

            app_name = _join_package_name(repo.namespace_user.username,
                                          repo.name)
            manifests = self.list_manifests(app_name, available_releases[0])
            view = ApplicationSummaryView(
                namespace=repo.namespace_user.username,
                name=app_name,
                visibility=repo.visibility.name,
                default=available_releases[0],
                channels=channels,
                manifests=manifests,
                releases=available_releases,
                updated_at=_timestamp_to_iso(
                    tag_set_prefetch[-1].lifetime_start),
                created_at=_timestamp_to_iso(
                    tag_set_prefetch[0].lifetime_start),
            )
            views.append(view)
        return views
Example #4
0
    def list_applications(self,
                          namespace=None,
                          media_type=None,
                          search=None,
                          username=None,
                          with_channels=False):
        """
        Lists all repositories that contain applications, with optional filtering to a specific
        namespace and view a specific user.
        """
        limit = app.config.get("APP_REGISTRY_RESULTS_LIMIT", 50)
        namespace_whitelist = app.config.get(
            "APP_REGISTRY_PACKAGE_LIST_CACHE_WHITELIST", [])

        # NOTE: This caching only applies for the super-large and commonly requested results
        # sets.
        if (namespace is not None and namespace in namespace_whitelist
                and media_type is None and search is None and username is None
                and not with_channels):

            def _list_applications():
                return [
                    found._asdict()
                    for found in self._list_applications(namespace=namespace,
                                                         limit=limit)
                ]

            apps_cache_key = cache_key.for_appr_applications_list(
                namespace, limit)
            return [
                ApplicationSummaryView(**found) for found in
                model_cache.retrieve(apps_cache_key, _list_applications)
            ]
        else:
            return self._list_applications(namespace,
                                           media_type,
                                           search,
                                           username,
                                           with_channels,
                                           limit=limit)