def download_url(cls, package_name, digest): blobpath = cls.upload_url(digest) locations = model.get_blob_locations(digest) if not locations: raise_package_not_found(package_name, digest) return storage.get_direct_download_url(locations, blobpath, get_request_ip())
def fetch_release(self, package_name, release, media_type): """ Retrieves an AppRelease from it's repository-name and release-name. """ repo = _application(package_name) try: tag, manifest, blob = appr_model.release.get_app_release( repo, release, media_type, self.models_ref) created_at = _timestamp_to_iso(tag.lifetime_start) blob_descriptor = BlobDescriptor( digest=_strip_sha256_header(blob.digest), mediaType=blob.media_type.name, size=blob.size, urls=[], ) app_manifest = ApplicationManifest( digest=manifest.digest, mediaType=manifest.media_type.name, content=blob_descriptor) app_release = ApplicationRelease(release=tag.name, created_at=created_at, name=package_name, manifest=app_manifest) return app_release except ( self.models_ref.Tag.DoesNotExist, self.models_ref.Manifest.DoesNotExist, self.models_ref.Blob.DoesNotExist, Repository.DoesNotExist, MediaType.DoesNotExist, ): raise_package_not_found(package_name, release, media_type)
def releases_data(self): path = self.releases_key if self._releases is None: try: self._releases = self._fetch_data(path) except ResourceNotFound: raise_package_not_found(self.package) return self._releases
def _fetch_b64blob(cls, package_name, digest): blobpath = cls.upload_url(digest) if blobpath is None: raise_package_not_found(package_name, digest) locations = model.get_blob_locations(digest) if not locations: raise_package_not_found(package_name, digest) return base64.b64encode(storage.get_content(locations, blobpath))
def list_release_channels(self, package_name, release, active=True): repo = _application(package_name) try: channels = appr_model.channel.get_tag_channels( repo, release, self.models_ref, active=active ) return [ChannelView(name=c.name, current=release) for c in channels] except (self.models_ref.Channel.DoesNotExist, self.models_ref.Tag.DoesNotExist): raise_package_not_found(package_name, release)
def get_release(cls, package, release_query, stable=False): releases = cls.all_releases(package) if not releases: raise_package_not_found(package, release=release_query) if release_query is None or release_query == 'default': return last_version(releases, stable) else: try: return select_version(releases, str(release_query), stable) except ValueError as e: raise InvalidRelease(e.message, {"release": release_query})
def list_manifests(self, package_name, release=None): """ Returns the list of all manifests of an Application. Todo: * Paginate """ try: repo = _application(package_name) return list(appr_model.manifest.get_manifest_types(repo, self.models_ref, release)) except (Repository.DoesNotExist, self.models_ref.Tag.DoesNotExist): raise_package_not_found(package_name, release)
def delete_release(self, package_name, release, media_type): """ Remove/Delete an app-release from an app-repository. It does not delete the entire app-repository, only a single release """ if self.is_readonly: raise ReadOnlyException('Currently in read-only mode') repo = _application(package_name) try: appr_model.release.delete_app_release(repo, release, media_type, self.models_ref) except (self.models_ref.Channel.DoesNotExist, self.models_ref.Tag.DoesNotExist, MediaType.DoesNotExist): raise_package_not_found(package_name, release, media_type)
def delete_release(self, release, media_type): try: self.get_lock(self.releases_key) data = self.releases_data if release not in data['releases'] or media_type not in data[ 'releases'][release]['manifests']: raise_package_not_found(self.package) data['releases'][release]['manifests'].pop(media_type) if not data['releases'][release]['manifests']: data['releases'].pop(release) if not data['releases']: self.delete_package(self.package) self._write_data(self.releases_key, data) return True finally: self.release_lock(self.releases_key)
def _application(package): ns, name = _split_package_name(package) repo = data.model.repository.get_app_repository(ns, name) if repo is None: raise_package_not_found(package) return repo
def get_blob(self, digest): try: path = self.blob_key(digest) return self._fetch_raw_data(path) except ResourceNotFound: raise_package_not_found(self.package, digest)
def release_channels(self, release): if release not in self.releases_data['releases']: raise_package_not_found(self.package, release) return self.releases_data['releases'][release]['channels']
def _check_channel_release(self, channel, release): if not self.ischannel_exists(channel): raise_channel_not_found(channel) if release not in self.releases_data['releases']: raise_package_not_found(self.package, release)
def release(self, release, media_type): try: return self.release_manifests(release)[media_type] except KeyError: raise_package_not_found(self.package, release, media_type)
def release_manifests(self, release): try: manifests = self.releases_data['releases'][release]['manifests'] return manifests except KeyError: raise_package_not_found(self.package, release)