Search in sources :

Example 1 with StreamPayload

use of org.sonatype.nexus.repository.view.payloads.StreamPayload in project nexus-public by sonatype.

the class OrientAptHostedFacet method ingestAsset.

@TransactionalStoreBlob
protected Asset ingestAsset(final ControlFile control, final TempBlob body, final long size, final String contentType) throws IOException {
    OrientAptFacet aptFacet = getRepository().facet(OrientAptFacet.class);
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    PackageInfo info = new PackageInfo(control);
    String name = info.getPackageName();
    String version = info.getVersion();
    String architecture = info.getArchitecture();
    String assetPath = AptFacetHelper.buildAssetPath(name, version, architecture);
    Content content = aptFacet.put(assetPath, new StreamPayload(body, size, contentType), info);
    Asset asset = Content.findAsset(tx, bucket, content);
    String indexSection = buildIndexSection(control, asset.size(), asset.getChecksums(AptFacetHelper.hashAlgorithms), assetPath);
    asset.formatAttributes().set(P_ARCHITECTURE, architecture);
    asset.formatAttributes().set(P_PACKAGE_NAME, name);
    asset.formatAttributes().set(P_PACKAGE_VERSION, version);
    asset.formatAttributes().set(P_INDEX_SECTION, indexSection);
    asset.formatAttributes().set(P_ASSET_KIND, "DEB");
    tx.saveAsset(asset);
    rebuildIndexes(singletonList(new AssetChange(AssetAction.ADDED, asset)));
    return asset;
}
Also used : StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) OrientAptFacet(org.sonatype.nexus.repository.apt.orient.OrientAptFacet) Bucket(org.sonatype.nexus.repository.storage.Bucket) PackageInfo(org.sonatype.nexus.repository.apt.internal.debian.PackageInfo) Content(org.sonatype.nexus.repository.view.Content) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 2 with StreamPayload

use of org.sonatype.nexus.repository.view.payloads.StreamPayload in project nexus-public by sonatype.

the class OrientAptHostedFacet method rebuildIndexes.

@TransactionalStoreMetadata
public void rebuildIndexes(final List<AssetChange> changes) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    OrientAptFacet aptFacet = getRepository().facet(OrientAptFacet.class);
    AptSigningFacet signingFacet = getRepository().facet(AptSigningFacet.class);
    Bucket bucket = tx.findBucket(getRepository());
    StringBuilder sha256Builder = new StringBuilder();
    StringBuilder md5Builder = new StringBuilder();
    String releaseFile;
    try (CompressingTempFileStore store = buildPackageIndexes(tx, bucket, changes)) {
        for (Map.Entry<String, CompressingTempFileStore.FileMetadata> entry : store.getFiles().entrySet()) {
            Content plainContent = aptFacet.put(packageIndexName(entry.getKey(), ""), new StreamPayload(entry.getValue().plainSupplier(), entry.getValue().plainSize(), AptMimeTypes.TEXT));
            addSignatureItem(md5Builder, MD5, plainContent, packageRelativeIndexName(entry.getKey(), ""));
            addSignatureItem(sha256Builder, SHA256, plainContent, packageRelativeIndexName(entry.getKey(), ""));
            Content gzContent = aptFacet.put(packageIndexName(entry.getKey(), ".gz"), new StreamPayload(entry.getValue().gzSupplier(), entry.getValue().bzSize(), AptMimeTypes.GZIP));
            addSignatureItem(md5Builder, MD5, gzContent, packageRelativeIndexName(entry.getKey(), ".gz"));
            addSignatureItem(sha256Builder, SHA256, gzContent, packageRelativeIndexName(entry.getKey(), ".gz"));
            Content bzContent = aptFacet.put(packageIndexName(entry.getKey(), ".bz2"), new StreamPayload(entry.getValue().bzSupplier(), entry.getValue().bzSize(), AptMimeTypes.BZIP));
            addSignatureItem(md5Builder, MD5, bzContent, packageRelativeIndexName(entry.getKey(), ".bz2"));
            addSignatureItem(sha256Builder, SHA256, bzContent, packageRelativeIndexName(entry.getKey(), ".bz2"));
        }
        releaseFile = buildReleaseFile(aptFacet.getDistribution(), store.getFiles().keySet(), md5Builder.toString(), sha256Builder.toString());
    }
    aptFacet.put(releaseIndexName(RELEASE), new BytesPayload(releaseFile.getBytes(Charsets.UTF_8), AptMimeTypes.TEXT));
    byte[] inRelease = signingFacet.signInline(releaseFile);
    aptFacet.put(releaseIndexName(INRELEASE), new BytesPayload(inRelease, AptMimeTypes.TEXT));
    byte[] releaseGpg = signingFacet.signExternal(releaseFile);
    aptFacet.put(releaseIndexName(RELEASE_GPG), new BytesPayload(releaseGpg, AptMimeTypes.SIGNATURE));
}
Also used : StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) OrientAptFacet(org.sonatype.nexus.repository.apt.orient.OrientAptFacet) Bucket(org.sonatype.nexus.repository.storage.Bucket) Content(org.sonatype.nexus.repository.view.Content) CompressingTempFileStore(org.sonatype.nexus.repository.apt.internal.hosted.CompressingTempFileStore) AptSigningFacet(org.sonatype.nexus.repository.apt.internal.gpg.AptSigningFacet) Map(java.util.Map) HashMap(java.util.HashMap) TransactionalStoreMetadata(org.sonatype.nexus.repository.transaction.TransactionalStoreMetadata)

Example 3 with StreamPayload

use of org.sonatype.nexus.repository.view.payloads.StreamPayload in project nexus-public by sonatype.

the class MavenUploadHandler method doPut.

@Override
protected Content doPut(ImportFileConfiguration configuration) throws IOException {
    OrientMavenFacet mavenFacet = configuration.getRepository().facet(OrientMavenFacet.class);
    MavenPath mavenPath = parser.parsePath(configuration.getAssetName());
    File content = configuration.getFile();
    Path contentPath = content.toPath();
    if (configuration.isHardLinkingEnabled()) {
        final AttributesMap contentAttributes = new AttributesMap();
        contentAttributes.set(Content.CONTENT_LAST_MODIFIED, new DateTime(Files.getLastModifiedTime(contentPath).toMillis()));
        byte[] bytes = Files.readAllBytes(contentPath);
        Map<HashAlgorithm, HashCode> hashes = HashType.ALGORITHMS.stream().collect(Collectors.toMap(a -> a, a -> a.function().hashBytes(bytes)));
        return mavenFacet.put(mavenPath, contentPath, configuration.getAssetName(), contentAttributes, hashes, Files.size(contentPath));
    } else {
        try (FileInputStream fis = new FileInputStream(content)) {
            Payload payload = new StreamPayload(() -> fis, content.length(), Files.probeContentType(contentPath));
            return doPut(configuration.getRepository(), mavenPath, payload);
        }
    }
}
Also used : Path(java.nio.file.Path) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) VersionPolicy(org.sonatype.nexus.repository.maven.VersionPolicy) MavenFacet(org.sonatype.nexus.repository.maven.MavenFacet) Singleton(javax.inject.Singleton) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap) Inject(javax.inject.Inject) UnitOfWork(org.sonatype.nexus.transaction.UnitOfWork) Repository(org.sonatype.nexus.repository.Repository) PartPayload(org.sonatype.nexus.repository.view.PartPayload) Maven2MavenPathParser(org.sonatype.nexus.repository.maven.internal.Maven2MavenPathParser) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) TempBlob(org.sonatype.nexus.repository.view.payloads.TempBlob) Map(java.util.Map) MavenUploadHandlerSupport(org.sonatype.nexus.repository.maven.MavenUploadHandlerSupport) Payload(org.sonatype.nexus.repository.view.Payload) UploadDefinitionExtension(org.sonatype.nexus.repository.rest.UploadDefinitionExtension) Named(javax.inject.Named) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) Path(java.nio.file.Path) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Files(java.nio.file.Files) MavenPomGenerator(org.sonatype.nexus.repository.maven.internal.MavenPomGenerator) HashCode(com.google.common.hash.HashCode) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) ContentPermissionChecker(org.sonatype.nexus.repository.security.ContentPermissionChecker) File(java.io.File) ImportFileConfiguration(org.sonatype.nexus.repository.importtask.ImportFileConfiguration) Content(org.sonatype.nexus.repository.view.Content) VersionPolicyValidator(org.sonatype.nexus.repository.maven.internal.VersionPolicyValidator) VariableResolverAdapter(org.sonatype.nexus.repository.security.VariableResolverAdapter) HashType(org.sonatype.nexus.repository.maven.MavenPath.HashType) Maven2Format(org.sonatype.nexus.repository.maven.internal.Maven2Format) HashAlgorithm(org.sonatype.nexus.common.hash.HashAlgorithm) ComponentUpload(org.sonatype.nexus.repository.upload.ComponentUpload) MavenHostedFacet(org.sonatype.nexus.repository.maven.MavenHostedFacet) UploadResponse(org.sonatype.nexus.repository.upload.UploadResponse) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) DateTime(org.joda.time.DateTime) FileInputStream(java.io.FileInputStream) HashCode(com.google.common.hash.HashCode) PartPayload(org.sonatype.nexus.repository.view.PartPayload) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) Payload(org.sonatype.nexus.repository.view.Payload) File(java.io.File) HashAlgorithm(org.sonatype.nexus.common.hash.HashAlgorithm)

Example 4 with StreamPayload

use of org.sonatype.nexus.repository.view.payloads.StreamPayload in project nexus-public by sonatype.

the class AptHostedFacet method rebuildMetadata.

/**
 * Method for triggering Apt metadata recalculation with possibility to specify what actually asset was changed
 */
public void rebuildMetadata(List<AssetChange> changeList) throws IOException {
    AptContentFacet aptFacet = getRepository().facet(AptContentFacet.class);
    AptSigningFacet signingFacet = getRepository().facet(AptSigningFacet.class);
    StringBuilder sha256Builder = new StringBuilder();
    StringBuilder md5Builder = new StringBuilder();
    String releaseFile;
    try (CompressingTempFileStore store = buildPackageIndexes(changeList)) {
        for (Map.Entry<String, CompressingTempFileStore.FileMetadata> entry : store.getFiles().entrySet()) {
            FluentAsset metadataAsset = aptFacet.put(packageIndexName(entry.getKey(), StringUtils.EMPTY), new StreamPayload(entry.getValue().plainSupplier(), entry.getValue().plainSize(), AptMimeTypes.TEXT));
            addSignatureItem(md5Builder, MD5, metadataAsset, packageRelativeIndexName(entry.getKey(), StringUtils.EMPTY));
            addSignatureItem(sha256Builder, SHA256, metadataAsset, packageRelativeIndexName(entry.getKey(), StringUtils.EMPTY));
            FluentAsset gzMetadataAsset = aptFacet.put(packageIndexName(entry.getKey(), GZ), new StreamPayload(entry.getValue().gzSupplier(), entry.getValue().bzSize(), AptMimeTypes.GZIP));
            addSignatureItem(md5Builder, MD5, gzMetadataAsset, packageRelativeIndexName(entry.getKey(), GZ));
            addSignatureItem(sha256Builder, SHA256, gzMetadataAsset, packageRelativeIndexName(entry.getKey(), GZ));
            FluentAsset bzMetadataAsset = aptFacet.put(packageIndexName(entry.getKey(), BZ2), new StreamPayload(entry.getValue().bzSupplier(), entry.getValue().bzSize(), AptMimeTypes.BZIP));
            addSignatureItem(md5Builder, MD5, bzMetadataAsset, packageRelativeIndexName(entry.getKey(), BZ2));
            addSignatureItem(sha256Builder, SHA256, bzMetadataAsset, packageRelativeIndexName(entry.getKey(), BZ2));
        }
        releaseFile = buildReleaseFile(aptFacet.getDistribution(), store.getFiles().keySet(), md5Builder.toString(), sha256Builder.toString());
    }
    aptFacet.put(releaseIndexName(RELEASE), new BytesPayload(releaseFile.getBytes(Charsets.UTF_8), AptMimeTypes.TEXT));
    byte[] inRelease = signingFacet.signInline(releaseFile);
    aptFacet.put(releaseIndexName(INRELEASE), new BytesPayload(inRelease, AptMimeTypes.TEXT));
    byte[] releaseGpg = signingFacet.signExternal(releaseFile);
    aptFacet.put(releaseIndexName(RELEASE_GPG), new BytesPayload(releaseGpg, AptMimeTypes.SIGNATURE));
}
Also used : StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) AptContentFacet(org.sonatype.nexus.repository.apt.datastore.AptContentFacet) CompressingTempFileStore(org.sonatype.nexus.repository.apt.internal.hosted.CompressingTempFileStore) AptSigningFacet(org.sonatype.nexus.repository.apt.internal.gpg.AptSigningFacet) Map(java.util.Map) HashMap(java.util.HashMap) FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset)

Aggregations

StreamPayload (org.sonatype.nexus.repository.view.payloads.StreamPayload)4 Map (java.util.Map)3 Content (org.sonatype.nexus.repository.view.Content)3 HashMap (java.util.HashMap)2 AptSigningFacet (org.sonatype.nexus.repository.apt.internal.gpg.AptSigningFacet)2 CompressingTempFileStore (org.sonatype.nexus.repository.apt.internal.hosted.CompressingTempFileStore)2 OrientAptFacet (org.sonatype.nexus.repository.apt.orient.OrientAptFacet)2 Bucket (org.sonatype.nexus.repository.storage.Bucket)2 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)2 BytesPayload (org.sonatype.nexus.repository.view.payloads.BytesPayload)2 HashCode (com.google.common.hash.HashCode)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1