diff --git a/pom.xml b/pom.xml index db2b1b5..ac6ab7c 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ UTF-8 11 - 1.0.4 + 1.1.5 1.0.2 1.7.30 1.12.429 diff --git a/src/main/java/com/zebrunner/carina/amazon/AmazonS3Manager.java b/src/main/java/com/zebrunner/carina/amazon/AmazonS3Manager.java index 658be44..31ca4ed 100644 --- a/src/main/java/com/zebrunner/carina/amazon/AmazonS3Manager.java +++ b/src/main/java/com/zebrunner/carina/amazon/AmazonS3Manager.java @@ -34,9 +34,11 @@ import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.transfer.Download; import com.amazonaws.services.s3.transfer.TransferManagerBuilder; +import com.zebrunner.carina.amazon.config.AmazonConfiguration; import com.zebrunner.carina.commons.artifact.IArtifactManager; -import com.zebrunner.carina.utils.Configuration; import com.zebrunner.carina.utils.common.CommonUtils; +import com.zebrunner.carina.utils.config.Configuration; +import com.zebrunner.carina.utils.config.StandardConfigurationOption; import org.apache.commons.lang3.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,6 +50,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,18 +76,16 @@ public static synchronized AmazonS3Manager getInstance() { AmazonS3Manager amazonS3Manager = new AmazonS3Manager(); AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); - String s3region = Configuration.get(Configuration.Parameter.S3_REGION); - if (!s3region.isEmpty()) { - builder.withRegion(Regions.fromName(s3region)); + Configuration.get(AmazonConfiguration.Parameter.S3_REGION).ifPresent(region -> + builder.withRegion(Regions.fromName(region)) + ); + Optional accessKey = Configuration.get(AmazonConfiguration.Parameter.ACCESS_KEY_ID, StandardConfigurationOption.DECRYPT); + Optional secretKey = Configuration.get(AmazonConfiguration.Parameter.SECRET_KEY, StandardConfigurationOption.DECRYPT); + if (accessKey.isPresent() && secretKey.isPresent()) { + builder.withCredentials(new AWSStaticCredentialsProvider( + new BasicAWSCredentials(accessKey.get(), secretKey.get()))) + .build(); } - - String accessKey = Configuration.getDecrypted(Configuration.Parameter.ACCESS_KEY_ID); - String secretKey = Configuration.getDecrypted(Configuration.Parameter.SECRET_KEY); - if (!accessKey.isEmpty() && !secretKey.isEmpty()) { - BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); - builder.withCredentials(new AWSStaticCredentialsProvider(creds)).build(); - } - amazonS3Manager.s3client = builder.build(); instance = amazonS3Manager; } diff --git a/src/main/java/com/zebrunner/carina/amazon/config/AmazonConfiguration.java b/src/main/java/com/zebrunner/carina/amazon/config/AmazonConfiguration.java new file mode 100644 index 0000000..4bb07c4 --- /dev/null +++ b/src/main/java/com/zebrunner/carina/amazon/config/AmazonConfiguration.java @@ -0,0 +1,50 @@ +package com.zebrunner.carina.amazon.config; + +import com.zebrunner.carina.utils.config.Configuration; +import com.zebrunner.carina.utils.config.IParameter; + +import java.util.Optional; + +public final class AmazonConfiguration extends Configuration { + + public enum Parameter implements IParameter { + + S3_BUCKET_NAME("s3_bucket_name"), + + S3_REGION("s3_region"), + + ACCESS_KEY_ID("access_key_id") { + @Override + public boolean hidden() { + return true; + } + }, + + SECRET_KEY("secret_key") { + @Override + public boolean hidden() { + return true; + } + }; + + private final String key; + + Parameter(String key) { + this.key = key; + } + + public String getKey() { + return key; + } + } + + @Override + public String toString() { + Optional asString = asString(Parameter.values()); + if (asString.isEmpty()) { + return ""; + } + return "\n============= Amazon configuration ============\n" + + asString.get(); + } +}