use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method getClient.
protected MinioClient getClient(String key, String action) {
if (minioClient != null) {
return minioClient;
}
if (!useStsToken()) {
throw new StorageClientNotFoundException("00002", "Storage action:" + action + " key:" + key + " initClient error");
}
long now = System.currentTimeMillis();
String cacheKey = StorageUtil.generateCacheKey(action, key);
StorageStsToken storageStsToken = STS_TOKEN_CACHE.getIfPresent(cacheKey);
boolean cacheusable = storageStsToken != null && storageStsToken.getExpiration().getTime() > now;
if (!cacheusable) {
storageStsToken = getStsToken(config, key, action);
Date expiration = storageStsToken.getExpiration();
if (expiration != null && expiration.getTime() - now > 3 * 60 * 1000) {
STS_TOKEN_CACHE.put(cacheKey, storageStsToken);
}
}
if (storageStsToken == null) {
throw new StorageException("00002", "securityToken获取失败");
}
config.setEndpoint(storageStsToken.getEndpoint().replaceAll(config.getBucketName() + StorageUtil.DOT, ""));
return this.createClient(config, storageStsToken);
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method generatePresignedUrl.
@Override
public URL generatePresignedUrl(String key, Date expiration) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "generatePresignedUrl");
int expire = (int) (expiration.getTime() - System.currentTimeMillis());
try {
String url = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(config.getBucketName()).expiry(expire, TimeUnit.MILLISECONDS).object(key).build());
return new URL(url);
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class SecurityServiceImpl method generateUploadStsSign.
@Override
public Mono<UploadSign> generateUploadStsSign(BaseStorageModel storage, String key, String mimeType, String successActionStatus) {
return getConfig(storage).flatMap(context -> {
if (context.isEmpty()) {
return Mono.error(new StorageException("00001"));
}
String finalMimeType = StringUtils.isBlank(mimeType) ? MediaTypeFactory.getMediaType(key) : mimeType;
// 判断host是否为空
return tokenHandlerFactory.getHandler(storage.getStorageType()).generateUploadStsSign(context, storage.getBucketName(), key, finalMimeType, successActionStatus).flatMap(uploadSign -> {
uploadSign.setStorageType(storage.getStorageType());
uploadSign.setTenentId(storage.getTenentId());
uploadSign.setBucketName(storage.getBucketName());
uploadSign.setMimeType(finalMimeType);
uploadSign.setSuccessActionStatus(StringUtils.isBlank(successActionStatus) ? null : successActionStatus);
return Mono.just(uploadSign);
});
});
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class SecurityServiceImpl method generateUploadSign.
@Override
public Mono<UploadSign> generateUploadSign(BaseStorageModel storage, String key, String mimeType, String successActionStatus) {
return getConfig(storage).flatMap(context -> {
if (context.isEmpty()) {
return Mono.error(new StorageException("00001"));
}
String finalMimeType = StringUtils.isBlank(mimeType) ? MediaTypeFactory.getMediaType(key) : mimeType;
// 判断host是否为空
return tokenHandlerFactory.getHandler(storage.getStorageType()).generateUploadSign(context, storage.getBucketName(), key, finalMimeType, successActionStatus).flatMap(uploadSign -> {
uploadSign.setStorageType(storage.getStorageType());
uploadSign.setTenentId(storage.getTenentId());
uploadSign.setBucketName(storage.getBucketName());
uploadSign.setMimeType(finalMimeType);
uploadSign.setSuccessActionStatus(successActionStatus);
return Mono.just(uploadSign);
});
});
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class SecurityServiceImpl method generateStsToken.
@Override
public Mono<STSToken> generateStsToken(BaseStorageModel storage, String key, String action) {
// 先查询到账号信息 然后调用下层
return getConfig(storage).flatMap(context -> {
if (context.isEmpty()) {
return Mono.error(new StorageException("00001"));
}
return tokenHandlerFactory.getHandler(storage.getStorageType()).generateStsToken(context, storage.getBucketName(), key, action).flatMap(stsToken -> {
stsToken.setStorageType(storage.getStorageType());
stsToken.setTenentId(storage.getTenentId());
stsToken.setBucketName(storage.getBucketName());
return Mono.just(stsToken);
});
});
}
Aggregations