Skip to content

Commit

Permalink
Merge pull request #20 from zebrunner/develop
Browse files Browse the repository at this point in the history
1.1.4
  • Loading branch information
vdelendik authored Jun 29, 2023
2 parents eca818a + f299b28 commit cacc2b7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<carina-utils.version>1.0.4</carina-utils.version>
<carina-utils.version>1.1.5</carina-utils.version>
<carina-commons.version>1.0.2</carina-commons.version>
<slf4j.version>1.7.30</slf4j.version>
<aws-java-sdk.version>1.12.429</aws-java-sdk.version>
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/zebrunner/carina/amazon/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<String> accessKey = Configuration.get(AmazonConfiguration.Parameter.ACCESS_KEY_ID, StandardConfigurationOption.DECRYPT);
Optional<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> asString = asString(Parameter.values());
if (asString.isEmpty()) {
return "";
}
return "\n============= Amazon configuration ============\n" +
asString.get();
}
}

0 comments on commit cacc2b7

Please sign in to comment.