Search in sources :

Example 21 with StorageException

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()));
    }
}
Also used : DefaultProfile(com.aliyuncs.profile.DefaultProfile) AssumeRoleRequest(com.aliyuncs.sts.model.v20150401.AssumeRoleRequest) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) STSToken(com.workoss.boot.storage.model.STSToken) AssumeRoleResponse(com.aliyuncs.sts.model.v20150401.AssumeRoleResponse) IAcsClient(com.aliyuncs.IAcsClient) ClientException(com.aliyuncs.exceptions.ClientException) StorageException(com.workoss.boot.storage.exception.StorageException)

Example 22 with StorageException

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);
    }
}
Also used : StorageException(com.workoss.boot.storage.exception.StorageException) StorageException(com.workoss.boot.storage.exception.StorageException) StorageDownloadException(com.workoss.boot.storage.exception.StorageDownloadException) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient)

Aggregations

StorageException (com.workoss.boot.storage.exception.StorageException)22 StorageDownloadException (com.workoss.boot.storage.exception.StorageDownloadException)10 StorageClientNotFoundException (com.workoss.boot.storage.exception.StorageClientNotFoundException)9 ErrorResponseException (io.minio.errors.ErrorResponseException)6 MinioException (io.minio.errors.MinioException)6 HashMap (java.util.HashMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 Date (java.util.Date)3 Map (java.util.Map)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)2 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)2 ProgressListener (com.amazonaws.event.ProgressListener)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)2