use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class OSSTokenHandler method generateStsToken.
@Override
public Mono<STSToken> generateStsToken(Context<String, String> context, String bucketName, String key, String action) {
String policy = renderSecurityTokenPolicy(context, bucketName, key, action);
DefaultProfile profile = DefaultProfile.getProfile(context.get("region"), context.get("access_key"), context.get("secret_key"));
IAcsClient client = new DefaultAcsClient(profile);
AssumeRoleRequest request = new AssumeRoleRequest();
request.setDurationSeconds(Long.parseLong(context.get("token_duration_seconds", "1200")));
request.setPolicy(policy);
request.setRoleArn(context.get("role_arn"));
request.setRoleSessionName(context.get("session_name", "popeye"));
try {
AssumeRoleResponse response = client.getAcsResponse(request);
AssumeRoleResponse.Credentials credentials = response.getCredentials();
STSToken stsToken = new STSToken();
stsToken.setStsToken(credentials.getSecurityToken());
stsToken.setAccessKey(credentials.getAccessKeyId());
stsToken.setSecretKey(credentials.getAccessKeySecret());
stsToken.setExpiration(DateUtils.parse(credentials.getExpiration(), "yyyy-MM-dd'T'HH:mm:ss'Z'").plusHours(8));
// ζΎε
₯εε
stsToken.setEndpoint(getDomain(context, bucketName));
return Mono.just(stsToken);
} catch (ClientException e) {
return Mono.error(new StorageException("10002", e.toString()));
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method doesBucketExist.
@Override
public boolean doesBucketExist() {
try (S3AsyncClient s3AsyncClient = getClient("", "doesBucketExist")) {
HeadBucketRequest headBucketRequest = HeadBucketRequest.builder().bucket(config.getBucketName()).build();
HeadBucketResponse headBucketResponse = s3AsyncClient.headBucket(headBucketRequest).get();
return true;
} catch (S3Exception s3Exception) {
throw throwS3Exception(s3Exception);
} catch (Exception e) {
throw new StorageException("0002", e);
}
}
Aggregations