Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if outstanding_downloads > max_downloads:
saturated = True
incoming_content = incoming_content[i + 1:] # remove handled content
break
else:
incoming_content = []
if pending:
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
for gathered_downloaders in done:
results = gathered_downloaders.result()
for download_result in results[:-1]:
content = results[-1]
for declarative_artifact in content.d_artifacts:
if declarative_artifact.artifact._state.adding:
new_artifact = Artifact(
**download_result.artifact_attributes,
file=download_result.path
)
declarative_artifact.artifact = new_artifact
pb.done = pb.done + len(content.d_artifacts)
outstanding_downloads = outstanding_downloads - len(content.d_artifacts)
await out_q.put(content)
else:
if shutdown:
break
if outstanding_downloads < max_downloads:
saturated = False
await out_q.put(None)
return artifact_downloader
def validate(self, data):
if hasattr(self, 'initial_data'):
validate_unknown_fields(self.initial_data, self.fields)
repository = data.pop('repository', None)
repository_version = data.get('repository_version')
if not repository and not repository_version:
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified"))
elif not repository and repository_version:
return data
elif repository and not repository_version:
version = models.RepositoryVersion.latest(repository)
if version:
new_data = {'repository_version': version}
new_data.update(data)
return new_data
else:
raise serializers.ValidationError(
detail=_('Repository has no version available to publish'))
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified "
"but not both.")
path_param = None
if "}" in path:
resource_path = "%s}/" % path.rsplit(sep="}", maxsplit=1)[0]
if resource_path in endpoints:
view = endpoints[resource_path][0]
if not hasattr(view, "queryset") or view.queryset is None:
if hasattr(view, "model"):
resource_model = view.model
else:
continue
else:
resource_model = view.queryset.model
resource_name = self.get_parameter_name(resource_model)
prefix_ = None
if issubclass(resource_model, RepositoryVersion):
prefix_ = view_cls.parent_viewset.endpoint_name
param_name = self.get_parameter_slug_from_model(resource_model, prefix_)
if resource_path in resources:
path = path.replace(resource_path, "{%s}" % resources[resource_path])
else:
resources[resource_path] = param_name
resource_example[resource_path] = self.get_example_uri(path)
path = path.replace(resource_path, "{%s}" % resources[resource_path])
example = resource_example[resource_path]
resource_description = self.get_resource_description(resource_name, example)
path_param = openapi.Parameter(
name=param_name,
description=resource_description,
required=True,
in_=openapi.IN_PATH,
type=openapi.TYPE_STRING,
@classmethod
def latest(cls, repository):
"""
Get the latest RepositoryVersion on a repository
Args:
repository (pulpcore.plugin.models.Repository): to get the latest version of
Returns:
pulpcore.plugin.repository.RepositoryVersion: The latest RepositoryVersion
"""
with suppress(models.RepositoryVersion.DoesNotExist):
model = repository.versions.exclude(complete=False).latest()
return RepositoryVersion(model)
async def _handle_component(self, component, release, release_file, file_references):
# Create release_component
release_component_dc = DeclarativeContent(
content=ReleaseComponent(component=component, release=release)
)
release_component = await self._create_unit(release_component_dc)
architectures = _filter_split(release_file.architectures, self.architectures)
pending_tasks = []
# Handle package indices
pending_tasks.extend(
[
self._handle_package_index(
release_file, release_component, architecture, file_references
)
for architecture in architectures
]
)
# Handle installer package indices
if self.remote.sync_udebs:
# Create release_file
release_file_dc = DeclarativeContent(
content=ReleaseFile(distribution=distribution),
d_artifacts=[
self._to_d_artifact(os.path.join("dists", distribution, filename))
for filename in ["Release", "InRelease", "Release.gpg"]
],
)
release_file = await self._create_unit(release_file_dc)
if release_file is None:
return
# Create release object
release_unit = Release(
codename=release_file.codename, suite=release_file.suite, distribution=distribution
)
release_dc = DeclarativeContent(content=release_unit)
release = await self._create_unit(release_dc)
# Create release architectures
for architecture in _filter_split(release_file.architectures, self.architectures):
release_architecture_dc = DeclarativeContent(
content=ReleaseArchitecture(architecture=architecture, release=release)
)
await self.put(release_architecture_dc)
# Parse release file
log.info('Parsing Release file for release: "{}"'.format(release_file.codename))
release_file_dict = deb822.Release(release_file.main_artifact.file)
# collect file references in new dict
file_references = defaultdict(deb822.Deb822Dict)
for digest_name in ["SHA512", "SHA256", "SHA1", "MD5sum"]:
if digest_name in release_file_dict:
for unit in release_file_dict[digest_name]:
file_references[unit["Name"]].update(unit)
if not source_repo and not source_repo_version:
raise serializers.ValidationError(
_("Either the 'source_repo' or 'source_repo_version' need to be specified"))
if source_repo and source_repo_version:
raise serializers.ValidationError(
_("Either the 'source_repo' or 'source_repo_version' need to be specified "
"but not both.")
)
if not source_repo and source_repo_version:
repo = {'source_repo': source_repo_version.repository}
new_data.update(repo)
if source_repo and not source_repo_version:
version = RepositoryVersion.latest(source_repo)
if version:
repo_version = {'source_repo_version': version}
new_data.update(repo_version)
else:
raise serializers.ValidationError(
detail=_('Repository has no version available to copy'))
types = data.get('types')
final_types = []
if types:
for t in types:
substitution = RPM_PLUGIN_TYPE_CHOICE_MAP.get(t)
if not substitution:
raise serializers.ValidationError(_(
"'{type}' is an invalid type, please use one of {choices}".format(
def untag_image(tag, repository_pk):
"""
Create a new repository version without a specified manifest's tag name.
"""
repository = Repository.objects.get(pk=repository_pk)
latest_version = RepositoryVersion.latest(repository)
tags_in_latest_repository = latest_version.content.filter(
pulp_type="docker.tag"
)
tags_to_remove = Tag.objects.filter(
pk__in=tags_in_latest_repository,
name=tag
)
with RepositoryVersion.create(repository) as repository_version:
repository_version.remove_content(tags_to_remove)
1. must_remain: These content units are referenced by content units that will not be removed
2. to_remove: These content units are either explicity given by the user,
or they are referenced by the content explicity given, and they are not in must_remain.
3. to_remain: Content in the repo that is not in to_remove. This category
is used to determine must_remain of lower heirarchy content.
Args:
repository_pk (int): The primary key for a Repository for which a new Repository Version
should be created.
content_units (list): List of PKs for :class:`~pulpcore.app.models.Content` that
should be removed from the Repository.
"""
repository = Repository.objects.get(pk=repository_pk)
latest_version = RepositoryVersion.latest(repository)
latest_content = latest_version.content.all() if latest_version else Content.objects.none()
tags_in_repo = Q(pk__in=latest_content.filter(pulp_type='docker.tag'))
manifests_in_repo = Q(pk__in=latest_content.filter(pulp_type='docker.manifest'))
user_provided_content = Q(pk__in=content_units)
type_manifest_list = Q(media_type=MEDIA_TYPE.MANIFEST_LIST)
type_manifest = Q(media_type__in=[MEDIA_TYPE.MANIFEST_V1, MEDIA_TYPE.MANIFEST_V2])
blobs_in_repo = Q(pk__in=latest_content.filter(pulp_type='docker.blob'))
# Tags do not have must_remain because they are the highest level content.
tags_to_remove = Tag.objects.filter(user_provided_content & tags_in_repo)
tags_to_remain = Tag.objects.filter(tags_in_repo).exclude(pk__in=tags_to_remove)
tagged_manifests_must_remain = Q(
pk__in=tags_to_remain.values_list("tagged_manifest", flat=True)
)
tagged_manifests_to_remove = Q(pk__in=tags_to_remove.values_list("tagged_manifest", flat=True))
def validate(self, data):
"""
Validate data passed through a request call.
Check if a repository has got a reference to a latest repository version. A
new dictionary object is initialized by the passed data and altered by a latest
repository version.
"""
new_data = {}
new_data.update(data)
latest_version = RepositoryVersion.latest(data['repository'])
if not latest_version:
raise serializers.ValidationError(
_("The latest repository version of '{}' was not found"
.format(data['repository']))
)
new_data['latest_version'] = latest_version
return new_data