use of com.dracoon.sdk.crypto.error.UnknownVersionException in project cyberduck by iterate-ch.
the class PresignedMultipartOutputStream method close.
@Override
public void close() throws IOException {
try {
if (close.get()) {
log.warn(String.format("Skip double close of stream %s", this));
return;
}
if (null != canceled.get()) {
return;
}
if (etags.isEmpty()) {
new SDSTouchFeature(session, nodeid).touch(file, new TransferStatus());
} else {
try {
final CompleteS3FileUploadRequest completeS3FileUploadRequest = new CompleteS3FileUploadRequest().keepShareLinks(overall.isExists() ? new HostPreferences(session.getHost()).getBoolean("sds.upload.sharelinks.keep") : false).resolutionStrategy(overall.isExists() ? CompleteS3FileUploadRequest.ResolutionStrategyEnum.OVERWRITE : CompleteS3FileUploadRequest.ResolutionStrategyEnum.FAIL);
if (overall.getFilekey() != null) {
final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class);
final FileKey fileKey = reader.readValue(overall.getFilekey().array());
final EncryptedFileKey encryptFileKey = Crypto.encryptFileKey(TripleCryptConverter.toCryptoPlainFileKey(fileKey), TripleCryptConverter.toCryptoUserPublicKey(session.keyPair().getPublicKeyContainer()));
completeS3FileUploadRequest.setFileKey(TripleCryptConverter.toSwaggerFileKey(encryptFileKey));
}
etags.forEach((key, value) -> completeS3FileUploadRequest.addPartsItem(new S3FileUploadPart().partEtag(StringUtils.remove(value, '"')).partNumber(key)));
new NodesApi(session.getClient()).completeS3FileUpload(completeS3FileUploadRequest, createFileUploadResponse.getUploadId(), StringUtils.EMPTY);
// Polling
final ScheduledThreadPool polling = new ScheduledThreadPool();
final CountDownLatch done = new CountDownLatch(1);
final AtomicReference<BackgroundException> failure = new AtomicReference<>();
final ScheduledFuture f = polling.repeat(new Runnable() {
@Override
public void run() {
try {
final S3FileUploadStatus uploadStatus = new NodesApi(session.getClient()).requestUploadStatusFiles(createFileUploadResponse.getUploadId(), StringUtils.EMPTY, null);
switch(uploadStatus.getStatus()) {
case "finishing":
// Expected
break;
case "transfer":
failure.set(new InteroperabilityException(uploadStatus.getStatus()));
done.countDown();
case "error":
failure.set(new InteroperabilityException(uploadStatus.getErrorDetails().getMessage()));
done.countDown();
case "done":
nodeid.cache(file, String.valueOf(uploadStatus.getNode().getId()));
done.countDown();
break;
}
} catch (ApiException e) {
failure.set(new SDSExceptionMappingService(nodeid).map("Upload {0} failed", e, file));
done.countDown();
}
}
}, new HostPreferences(session.getHost()).getLong("sds.upload.s3.status.period"), TimeUnit.MILLISECONDS);
Uninterruptibles.awaitUninterruptibly(done);
polling.shutdown();
if (null != failure.get()) {
throw failure.get();
}
} catch (CryptoSystemException | InvalidFileKeyException | InvalidKeyPairException | UnknownVersionException e) {
throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file);
} catch (ApiException e) {
throw new SDSExceptionMappingService(nodeid).map("Upload {0} failed", e, file);
}
}
} catch (BackgroundException e) {
throw new IOException(e);
} finally {
close.set(true);
}
}
Aggregations