def list(self, request, *args, **kwargs): self.paginator.init_from_request(request) params = self.request.query_params.dict() params.update({ 'offset': self.paginator.offset, 'limit': self.paginator.limit, 'certification': constants.CertificationStatus.CERTIFIED.value }) api = galaxy_pulp.GalaxyCollectionVersionsApi(pulp.get_client()) response = api.list( prefix=settings.X_PULP_API_PREFIX, namespace=self.kwargs['namespace'], name=self.kwargs['name'], **params, ) # Consider an empty list of versions as a 404 on the Collection if not response.results: raise NotFound() self._fix_list_urls(response.results) return self.paginator.paginate_proxy_response(response.results, response.count)
def update(self, request, *args, **kwargs): namespace = self.kwargs['namespace'] name = self.kwargs['name'] namespace_obj = get_object_or_404(models.Namespace, name=namespace) self.check_object_permissions(self.request, namespace_obj) serializer = CollectionSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) data = serializer.validated_data collection = galaxy_pulp.models.Collection( deprecated=data.get('deprecated', False)) api = galaxy_pulp.GalaxyCollectionsApi(pulp.get_client()) response = api.put( prefix=settings.X_PULP_API_PREFIX, namespace=namespace, name=name, collection=collection, ) return Response(response.to_dict())
def list(self, request, *args, **kwargs): self.paginator.init_from_request(request) params = { 'offset': self.paginator.offset, 'limit': self.paginator.limit, } for key, value in self.request.query_params.lists(): if key == 'keywords': key = 'q' if isinstance(value, list): params[key] = ','.join(value) else: params[key] = value api = galaxy_pulp.PulpCollectionsApi(pulp.get_client()) response = api.list( is_highest=True, exclude_fields='docs_blob', **params ) namespaces = set(collection['namespace'] for collection in response.results) namespaces = self._query_namespaces(namespaces) data = serializers.CollectionListSerializer( response.results, many=True, context={'namespaces': namespaces} ).data return self.paginator.paginate_proxy_response(data, response.count)
def retrieve(self, request, *args, **kwargs): api = galaxy_pulp.GalaxyCollectionsApi(pulp.get_client()) response = api.get(prefix=settings.X_PULP_API_PREFIX, namespace=self.kwargs['namespace'], name=self.kwargs['name']) response = self._fix_item_urls(response) return Response(response)
def retrieve(self, request, *args, **kwargs): api = galaxy_pulp.GalaxyImportsApi(pulp.get_client()) task = self.get_object() task_info = api.get(prefix=settings.X_PULP_API_PREFIX, id=self.kwargs['task_id']) data = serializers.ImportTaskDetailSerializer(task_info, context={ 'task_obj': task }).data return Response(data)
def retrieve(self, request, *args, **kwargs): api = galaxy_pulp.GalaxyCollectionVersionsApi(pulp.get_client()) response = api.get( prefix=settings.X_PULP_API_PREFIX, namespace=self.kwargs['namespace'], name=self.kwargs['name'], version=self.kwargs['version'], ) self._fix_retrieve_url(response) response['download_url'] = self._transform_pulp_url(request, response['download_url']) return Response(response)
def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(queryset) api = galaxy_pulp.GalaxyImportsApi(pulp.get_client()) results = [] for task in page: task_info = api.get(prefix=settings.X_PULP_API_PREFIX, id=str(task.pk)) data = serializers.ImportTaskListSerializer(task_info, context={'task_obj': task}).data results.append(data) return self.get_paginated_response(results)
def list(self, request, *args, **kwargs): self.paginator.init_from_request(request) params = self.request.query_params.dict() params.update({ 'offset': self.paginator.offset, 'limit': self.paginator.limit, }) api = galaxy_pulp.GalaxyCollectionsApi(pulp.get_client()) response = api.list(prefix=settings.X_PULP_API_PREFIX, **params) data = list(map(self._fix_item_urls, response.results)) return self.paginator.paginate_proxy_response(data, response.count)
def list(self, request, *args, **kwargs): self.paginator.init_from_request(request) params = self.request.query_params.dict() params.update({ 'offset': self.paginator.offset, 'limit': self.paginator.limit, }) api = galaxy_pulp.PulpTagsApi(pulp.get_client()) response = api.list(**params) return self.paginator.paginate_proxy_response(response.results, response.count)
def retrieve(self, request, *args, **kwargs): namespace, name = self.kwargs['collection'].split('/') namespace_obj = get_object_or_404(models.Namespace, name=namespace) params_dict = self.request.query_params.dict() version = params_dict.get('version', '') api = galaxy_pulp.PulpCollectionsApi(pulp.get_client()) params = { 'namespace': namespace, 'name': name, } if version == '': params['is_highest'] = True params[ 'certification'] = constants.CertificationStatus.CERTIFIED.value else: params['version'] = version response = api.list(**params) if not response.results: raise NotFound() all_versions = api.list( namespace=namespace, name=name, fields='version,id,pulp_created,artifact', certification=constants.CertificationStatus.CERTIFIED.value) all_versions = [{ 'version': collection['version'], 'id': collection['id'], 'created': collection['pulp_created'] } for collection in all_versions.results] collection = response.results[0] data = serializers.CollectionDetailSerializer(collection, context={ 'namespace': namespace_obj, 'all_versions': all_versions }).data return Response(data)
def retrieve(self, request, *args, **kwargs): namespace, name, version = self.kwargs['version'].split('/') api = galaxy_pulp.PulpCollectionsApi(pulp.get_client()) response = api.list(namespace=namespace, name=name, version=version, limit=1) if not response.results: raise NotFound() data = serializers.CollectionVersionDetailSerializer( response.results[0]).data return Response(data)
def set_certified(self, request, *args, **kwargs): namespace, name, version = self.kwargs['version'].split('/') namespace_obj = get_object_or_404(models.Namespace, name=namespace) self.check_object_permissions(request, namespace_obj) api = galaxy_pulp.GalaxyCollectionVersionsApi(pulp.get_client()) serializer = serializers.CertificationSerializer( data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) certification = serializer.validated_data.get('certification') response = api.set_certified( prefix=settings.X_PULP_API_PREFIX, namespace=namespace, name=name, version=version, certification_info=galaxy_pulp.CertificationInfo(certification), ) return Response(response)
def list(self, request, *args, **kwargs): self.paginator.init_from_request(request) params = self.request.query_params.dict() params.update({ 'offset': self.paginator.offset, 'limit': self.paginator.limit, }) # pulp uses ordering, but the UI is standardized around sort if params.get('sort'): params['ordering'] = params.get('sort') del params['sort'] api = galaxy_pulp.PulpCollectionsApi(pulp.get_client()) response = api.list(exclude_fields='docs_blob', **params) data = serializers.CollectionVersionSerializer(response.results, many=True).data return self.paginator.paginate_proxy_response(data, response.count)
def post(self, request, *args, **kwargs): metrics.collection_import_attempts.inc() serializer = CollectionUploadSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) data = serializer.validated_data filename = data['filename'] try: namespace = models.Namespace.objects.get(name=filename.namespace) except models.Namespace.DoesNotExist: raise ValidationError('Namespace "{0}" does not exist.'.format( filename.namespace)) self.check_object_permissions(request, namespace) api = pulp.get_client() url = '{host}/{prefix}/{path}'.format( host=api.configuration.host, path='v3/artifacts/collections/', prefix=settings.X_PULP_API_PREFIX) headers = {} headers.update(api.default_headers) headers.update({'Content-Type': 'multipart/form-data'}) api.update_params_for_auth(headers, tuple(), api.configuration.auth_settings()) post_params = self._prepare_post_params(data) try: upload_response = api.request( 'POST', url, headers=headers, post_params=post_params, ) except galaxy_pulp.ApiException: log.exception( 'Failed to publish artifact %s (namespace=%s, sha256=%s) to pulp at url=%s', # noqa data['file'].name, namespace, data.get('sha256'), url) raise upload_response_data = json.loads(upload_response.data) task_detail = api.call_api( upload_response_data['task'], 'GET', auth_settings=['BasicAuth'], response_type='CollectionImport', _return_http_data_only=True, ) log.info( 'Publishing of artifact %s to namespace=%s by user=%s created pulp import task_id=%s', # noqa data['file'].name, namespace, request.user, task_detail.id) import_obj = models.CollectionImport.objects.create( task_id=task_detail.id, created_at=task_detail.created_at, namespace=namespace, name=data['filename'].name, version=data['filename'].version, ) metrics.collection_import_successes.inc() return Response(data={'task': import_obj.get_absolute_url()}, status=upload_response.status)
def retrieve(self, request, pk): api = galaxy_pulp.GalaxyImportsApi(pulp.get_client()) response = api.get(prefix=settings.X_PULP_API_PREFIX, id=pk) return Response(response.to_dict())