/** * Deletes a blob w/ enforcing {@link WritePolicy} if not {@code null}. otherwise write policy will NOT be checked. */ private void deleteBlob(final BlobRef blobRef, @Nullable WritePolicy effectiveWritePolicy, final String reason) { checkNotNull(blobRef); if (effectiveWritePolicy != null && !effectiveWritePolicy.checkDeleteAllowed()) { throw new IllegalOperationException("Repository does not allow deleting assets: " + repositoryName); } blobTx.delete(blobRef, reason); }
private ComponentMaintenance getComponentMaintenanceFacet(final Repository repository) { try { return repository.facet(ComponentMaintenance.class); } catch (MissingFacetException e) { throw new IllegalOperationException( format("Deleting from repository %s of type %s is not supported", repository.getName(), repository.getFormat()), e); } } }
@Override @Guarded(by = ACTIVE) public AssetBlob createBlob(final String blobName, final Supplier<InputStream> streamSupplier, final Iterable<HashAlgorithm> hashAlgorithms, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, final boolean skipContentVerification) throws IOException { checkNotNull(blobName); checkNotNull(streamSupplier); checkNotNull(hashAlgorithms); if (!writePolicy.checkCreateAllowed()) { throw new IllegalOperationException("Repository is read only: " + repositoryName); } Map<String, String> storageHeadersMap = buildStorageHeaders(blobName, streamSupplier, headers, declaredContentType, skipContentVerification); return blobTx.create( streamSupplier.get(), storageHeadersMap, hashAlgorithms, storageHeadersMap.get(BlobStore.CONTENT_TYPE_HEADER) ); }
@Override public AssetBlob setBlob(final Asset asset, final String blobName, final TempBlob originalBlob, @Nullable final Map<String, String> headers, @Nullable String declaredContentType, boolean skipContentVerification) throws IOException { checkNotNull(blobName); checkNotNull(originalBlob); // Enforce write policy ahead, as we have asset here BlobRef oldBlobRef = asset.blobRef(); if (oldBlobRef != null && !writePolicySelector.select(asset, writePolicy).checkUpdateAllowed()) { throw new IllegalOperationException("Repository does not allow updating assets: " + repositoryName); } AssetBlob assetBlob = createBlob(blobName, originalBlob, headers, declaredContentType, skipContentVerification); attachBlob(asset, assetBlob); return assetBlob; }
@Override @Guarded(by = ACTIVE) public AssetBlob createBlob(final String blobName, final Path sourceFile, final Map<HashAlgorithm, HashCode> hashes, @Nullable final Map<String, String> headers, final String declaredContentType, final long size) throws IOException { checkNotNull(blobName); checkNotNull(sourceFile); checkNotNull(hashes); checkArgument(!Strings2.isBlank(declaredContentType), "no declaredContentType provided"); if (!writePolicy.checkCreateAllowed()) { throw new IllegalOperationException("Repository is read only: " + repositoryName); } Map<String, String> storageHeaders = buildStorageHeaders(blobName, null, headers, declaredContentType, true); return blobTx.createByHardLinking( sourceFile, storageHeaders, hashes, declaredContentType, size ); }
@Override public AssetBlob createBlob(final String blobName, final TempBlob originalBlob, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, boolean skipContentVerification) throws IOException { checkNotNull(blobName); checkNotNull(originalBlob); if (!writePolicy.checkCreateAllowed()) { throw new IllegalOperationException("Repository is read only: " + repositoryName); } Map<String, String> storageHeadersMap = buildStorageHeaders(blobName, originalBlob, headers, declaredContentType, skipContentVerification); return blobTx.createByCopying( originalBlob.getBlob().getId(), storageHeadersMap, originalBlob.getHashes(), originalBlob.getHashesVerified() ); }
@Override @Guarded(by = ACTIVE) public AssetBlob setBlob(final Asset asset, final String blobName, final Supplier<InputStream> streamSupplier, final Iterable<HashAlgorithm> hashAlgorithms, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, final boolean skipContentVerification) throws IOException { checkNotNull(asset); // Enforce write policy ahead, as we have asset here BlobRef oldBlobRef = asset.blobRef(); if (oldBlobRef != null) { if (!writePolicySelector.select(asset, writePolicy).checkUpdateAllowed()) { throw new IllegalOperationException("Repository does not allow updating assets: " + repositoryName); } } final AssetBlob assetBlob = createBlob( blobName, streamSupplier, hashAlgorithms, headers, declaredContentType, skipContentVerification ); attachBlob(asset, assetBlob); return assetBlob; }
@Override @Guarded(by = ACTIVE) public AssetBlob setBlob(final Asset asset, final String blobName, final Path sourceFile, final Map<HashAlgorithm, HashCode> hashes, @Nullable final Map<String, String> headers, final String declaredContentType, final long size) throws IOException { checkNotNull(asset); checkArgument(!Strings2.isBlank(declaredContentType), "no declaredContentType provided"); // Enforce write policy ahead, as we have asset here BlobRef oldBlobRef = asset.blobRef(); if (oldBlobRef != null) { if (!writePolicySelector.select(asset, writePolicy).checkUpdateAllowed()) { throw new IllegalOperationException( "Repository does not allow updating assets: " + repositoryName); } } final AssetBlob assetBlob = createBlob( blobName, sourceFile, hashes, headers, declaredContentType, size ); attachBlob(asset, assetBlob); return assetBlob; }
/** * Deletes the existing blob for the asset if one exists, updating the blob updated field if necessary. The * write policy will be enforced for this operation and will throw an exception if updates are not supported. */ private void maybeDeleteBlob(final Asset asset, final WritePolicy effectiveWritePolicy) { DateTime now = DateTime.now(); if (asset.blobRef() != null) { // updating old blob if (!effectiveWritePolicy.checkUpdateAllowed()) { throw new IllegalOperationException("Repository does not allow updating assets: " + repositoryName); } asset.blobUpdated(now); deleteBlob(asset.blobRef(), effectiveWritePolicy, format("Updating asset %s", EntityHelper.id(asset))); } else { // creating new blob asset.blobCreated(now); asset.blobUpdated(now); } }
private Response doPut(@Nonnull final Context context, final MavenPath path, final MavenFacet mavenFacet) throws IOException { if (mavenFacet.layoutPolicy() == LayoutPolicy.STRICT && isValidSnapshot(path.getCoordinates()) && !mavenFacet.getMavenPathParser().isRepositoryMetadata(path)) { throw new IllegalOperationException("Invalid path for a Maven 2 repository"); } mavenFacet.put(path, context.getRequest().getPayload()); return HttpResponses.created(); }
@TransactionalStoreBlob public Asset ingestAsset(Payload body) throws IOException, PGPException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(body, FacetHelper.hashAlgorithms)) { ControlFile control = AptPackageParser.parsePackage(tempBlob); if (control == null) { throw new IllegalOperationException("Invalid Debian package supplied"); } return ingestAsset(control, tempBlob, body.getSize(), body.getContentType()); } }
throw new IllegalOperationException("Repository is read only: " + repositoryName);
throw new IllegalOperationException("Repository does not allow updating assets: " + repositoryName);