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;
}
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));
}
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);
}
}
}
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));
}
Aggregations