Feature mgmtapi add sha256 to softwaremodules (#918)
* Add sha256 hash to softwaremodules in mgmt api Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Adapt rest docs Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Edit comments Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add proper license header Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
0e9caf3a88
commit
5feb5873c4
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* Thrown if SHA256 checksum check fails.
|
||||
*/
|
||||
public class InvalidSHA256HashException extends AbstractServerRtException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new FileUploadFailedException with
|
||||
* {@link SpServerError#SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH} error.
|
||||
*/
|
||||
public InvalidSHA256HashException() {
|
||||
super(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA256_MATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* of the error
|
||||
* @param cause
|
||||
* for the exception
|
||||
*/
|
||||
public InvalidSHA256HashException(final String message, final Throwable cause) {
|
||||
super(message, SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA256_MATCH, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* of the error
|
||||
*/
|
||||
public InvalidSHA256HashException(final String message) {
|
||||
super(message, SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA256_MATCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class ArtifactUpload {
|
||||
*/
|
||||
public ArtifactUpload(final InputStream inputStream, final long moduleId, final String filename,
|
||||
final boolean overrideExisting, final long filesize) {
|
||||
this(inputStream, moduleId, filename, null, null, overrideExisting, null, filesize);
|
||||
this(inputStream, moduleId, filename, null, null, null, overrideExisting, null, filesize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,14 +85,14 @@ public class ArtifactUpload {
|
||||
* the size of the file in bytes.
|
||||
*/
|
||||
public ArtifactUpload(final InputStream inputStream, final long moduleId, final String filename,
|
||||
final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting,
|
||||
final String contentType, final long filesize) {
|
||||
final String providedMd5Sum, final String providedSha1Sum, final String providedSha256Sum,
|
||||
final boolean overrideExisting, final String contentType, final long filesize) {
|
||||
this.inputStream = inputStream;
|
||||
this.moduleId = moduleId;
|
||||
this.filename = filename;
|
||||
this.providedMd5Sum = providedMd5Sum;
|
||||
this.providedSha1Sum = providedSha1Sum;
|
||||
this.providedSha256Sum = null;
|
||||
this.providedSha256Sum = providedSha256Sum;
|
||||
this.overrideExisting = overrideExisting;
|
||||
this.contentType = contentType;
|
||||
this.filesize = filesize;
|
||||
|
||||
@@ -25,11 +25,12 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA256HashException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.FileSizeAndStorageQuotaCheckingInputStream;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.ArtifactUpload;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -121,16 +122,17 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
private AbstractDbArtifact storeArtifact(final ArtifactUpload artifactUpload) {
|
||||
try(final InputStream quotaStream = wrapInQuotaStream(artifactUpload.getInputStream())) {
|
||||
return artifactRepository.store(tenantAware.getCurrentTenant(), quotaStream,
|
||||
artifactUpload.getFilename(), artifactUpload.getContentType(),
|
||||
new DbArtifactHash(artifactUpload.getProvidedSha1Sum(), artifactUpload.getProvidedMd5Sum(),
|
||||
artifactUpload.getProvidedSha256Sum()));
|
||||
try (final InputStream quotaStream = wrapInQuotaStream(artifactUpload.getInputStream())) {
|
||||
return artifactRepository.store(tenantAware.getCurrentTenant(), quotaStream, artifactUpload.getFilename(),
|
||||
artifactUpload.getContentType(), new DbArtifactHash(artifactUpload.getProvidedSha1Sum(),
|
||||
artifactUpload.getProvidedMd5Sum(), artifactUpload.getProvidedSha256Sum()));
|
||||
} catch (final ArtifactStoreException | IOException e) {
|
||||
throw new ArtifactUploadFailedException(e);
|
||||
} catch (final HashNotMatchException e) {
|
||||
if (e.getHashFunction().equals(HashNotMatchException.SHA1)) {
|
||||
throw new InvalidSHA1HashException(e.getMessage(), e);
|
||||
} else if (e.getHashFunction().equals(HashNotMatchException.SHA256)) {
|
||||
throw new InvalidSHA256HashException(e.getMessage(), e);
|
||||
} else {
|
||||
throw new InvalidMD5HashException(e.getMessage(), e);
|
||||
}
|
||||
@@ -148,7 +150,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
final long currentlyUsed = localArtifactRepository.getSumOfUndeletedArtifactSize().orElse(0L);
|
||||
final long maxArtifactSizeTotal = quotaManagement.getMaxArtifactStorage();
|
||||
|
||||
return new FileSizeAndStorageQuotaCheckingInputStream(in, maxArtifactSize, maxArtifactSizeTotal - currentlyUsed);
|
||||
return new FileSizeAndStorageQuotaCheckingInputStream(in, maxArtifactSize,
|
||||
maxArtifactSizeTotal - currentlyUsed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,9 +30,9 @@ import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.FileSizeQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.StorageQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
@@ -84,12 +84,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int artifactSize = artifactData.length();
|
||||
verifyThrownExceptionBy(
|
||||
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"),
|
||||
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
|
||||
NOT_EXIST_IDL, "xxx", null, null, null, false, null, artifactSize)),
|
||||
"SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"),
|
||||
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
|
||||
NOT_EXIST_IDL, "xxx", null, null, null, false, null, artifactSize)),
|
||||
"SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(() -> artifactManagement.delete(NOT_EXIST_IDL), "Artifact");
|
||||
|
||||
Reference in New Issue
Block a user