Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    def store_blob(self, cnrblob, content_media_type):
        if self.is_readonly:
            raise ReadOnlyException('Currently in read-only mode')

        fp = cnrblob.packager.io_file
        path = cnrblob.upload_url(cnrblob.digest)
        locations = storage.preferred_locations
        storage.stream_write(locations, path, fp, 'application/x-gzip')
        db_blob = appr_model.blob.get_or_create_blob(cnrblob.digest,
                                                     cnrblob.size,
                                                     content_media_type,
                                                     locations,
                                                     self.models_ref)
        return BlobDescriptor(mediaType=content_media_type,
                              digest=_strip_sha256_header(db_blob.digest),
                              size=db_blob.size,
                              urls=[])