Compare commits
No commits in common. "aws-java-sdk-update" and "main" have entirely different histories.
aws-java-s
...
main
66
pom.xml
66
pom.xml
@ -4,13 +4,10 @@
|
||||
<parent>
|
||||
<groupId>com.bazaarvoice.commons</groupId>
|
||||
<artifactId>bv-opensource-super-pom</artifactId>
|
||||
<version>1.11</version>
|
||||
<version>1.4</version>
|
||||
</parent>
|
||||
|
||||
<!--
|
||||
<groupId>com.bazaarvoice.maven.plugins</groupId>
|
||||
-->
|
||||
<groupId>org.signal</groupId>
|
||||
<groupId>com.bazaarvoice.maven.plugins</groupId>
|
||||
<artifactId>s3-upload-maven-plugin</artifactId>
|
||||
<version>1.6-SNAPSHOT</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
@ -18,33 +15,16 @@
|
||||
<name>S3 upload maven plugin</name>
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/signalapp/s3-upload-maven-plugin</url>
|
||||
<connection>scm:git:git@github.com:signalapp/s3-upload-maven-plugin.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:signalapp/s3-upload-maven-plugin.git</developerConnection>
|
||||
<url>https://github.com/bazaarvoice/s3-upload-maven-plugin</url>
|
||||
<connection>scm:git:git@github.com:bazaarvoice/s3-upload-maven-plugin.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:bazaarvoice/s3-upload-maven-plugin.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype-nexus-staging</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<encoding>UTF-8</encoding>
|
||||
|
||||
<maven-plugin-api.version>3.8.1</maven-plugin-api.version>
|
||||
<maven-plugin-annotations.version>3.6.1</maven-plugin-annotations.version>
|
||||
<maven-plugin-plugin.version>3.6.1</maven-plugin-plugin.version>
|
||||
|
||||
<animal-sniffer-maven-plugin.version>1.20</animal-sniffer-maven-plugin.version>
|
||||
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
|
||||
|
||||
<aws-sdk-v2.version>2.16.96</aws-sdk-v2.version>
|
||||
<aws-sdk-v1.version>1.12.18</aws-sdk-v1.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@ -52,12 +32,12 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||
<version>${animal-sniffer-maven-plugin.version}</version>
|
||||
<version>1.15</version>
|
||||
<configuration>
|
||||
<signature>
|
||||
<groupId>org.codehaus.mojo.signature</groupId>
|
||||
<artifactId>java18</artifactId>
|
||||
<version>1.0</version>
|
||||
<artifactId>java16</artifactId>
|
||||
<version>1.1</version>
|
||||
</signature>
|
||||
</configuration>
|
||||
<executions>
|
||||
@ -72,7 +52,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>${maven-plugin-plugin.version}</version>
|
||||
<version>3.4</version>
|
||||
<configuration>
|
||||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||
</configuration>
|
||||
@ -95,7 +75,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>${nexus-staging-maven-plugin.version}</version>
|
||||
<version>1.6.7</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>sonatype-nexus-staging</serverId>
|
||||
@ -110,42 +90,30 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${maven-plugin-api.version}</version>
|
||||
<version>3.3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>${maven-plugin-annotations.version}</version>
|
||||
<version>3.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-core</artifactId>
|
||||
<version>${aws-sdk-v1.version}</version>
|
||||
<version>1.11.820</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>${aws-sdk-v1.version}</version>
|
||||
<version>1.11.820</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- The STS SDK is necessary if role based profiles are used for credentials. -->
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-sts</artifactId>
|
||||
<version>${aws-sdk-v1.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- The v2 auth SDK is necessary if v2 profiles are used for credentials. -->
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>auth</artifactId>
|
||||
<version>${aws-sdk-v2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- The SSO SDK is necessary if sso based profiles are used for credentials. -->
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>sso</artifactId>
|
||||
<version>${aws-sdk-v2.version}</version>
|
||||
<version>1.11.820</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -2,11 +2,6 @@ s3-upload-maven-plugin
|
||||
======================
|
||||
Uploads a file or (recursively) the contents of a directory to S3.
|
||||
|
||||
Fork notes
|
||||
----------
|
||||
|
||||
Adds pre-release quality support for AWS SSO credentials.
|
||||
|
||||
Configuration parameters
|
||||
------------------------
|
||||
|
||||
@ -20,7 +15,6 @@ Configuration parameters
|
||||
|secretKey|S3 secret key | *no* | if unspecified, uses the Default Provider, falling back to env variables |
|
||||
|doNotUpload|Dry run| *no* | false |
|
||||
|endpoint|Use a different s3 endpoint| *no* | s3.amazonaws.com |
|
||||
|region|Explicitly set a region (since 1.6)| *no* | determined from region provider chain |
|
||||
|
||||
Example: Upload a file
|
||||
----------------------
|
||||
@ -68,3 +62,4 @@ Example: Recursively upload a folder
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
package com.bazaarvoice.maven.plugins.s3.upload;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.auth.BasicSessionCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
|
||||
|
||||
/**
|
||||
* Derived from https://github.com/aws/aws-sdk-java/issues/803#issuecomment-593530484
|
||||
*
|
||||
* This adapter may be removed if the project is fully migrated to AWS SDK v2
|
||||
*/
|
||||
class CliCompatibleCredentialsProvider implements AWSCredentialsProvider {
|
||||
private final ProfileCredentialsProvider delegate;
|
||||
|
||||
public CliCompatibleCredentialsProvider() {
|
||||
this.delegate = ProfileCredentialsProvider.create();
|
||||
}
|
||||
|
||||
public CliCompatibleCredentialsProvider(String profileName) {
|
||||
this.delegate = ProfileCredentialsProvider.create("my-profile-name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AWSCredentials getCredentials() {
|
||||
AwsCredentials credentials = delegate.resolveCredentials();
|
||||
|
||||
if (credentials instanceof AwsSessionCredentials) {
|
||||
AwsSessionCredentials sessionCredentials = (AwsSessionCredentials) credentials;
|
||||
return new BasicSessionCredentials(sessionCredentials.accessKeyId(),
|
||||
sessionCredentials.secretAccessKey(),
|
||||
sessionCredentials.sessionToken());
|
||||
}
|
||||
|
||||
return new BasicAWSCredentials(credentials.accessKeyId(), credentials.secretAccessKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@ -2,16 +2,11 @@ package com.bazaarvoice.maven.plugins.s3.upload;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.AWSCredentialsProviderChain;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper;
|
||||
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
|
||||
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
|
||||
import com.amazonaws.auth.WebIdentityTokenCredentialsProvider;
|
||||
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
|
||||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
|
||||
import com.amazonaws.internal.StaticCredentialsProvider;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.Headers;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
@ -56,10 +51,6 @@ public class S3UploadMojo extends AbstractMojo
|
||||
@Parameter(property = "s3-upload.destination", required = true)
|
||||
private String destination;
|
||||
|
||||
/** The AWS region for the client configuration, if it is not available from the region provider chain. */
|
||||
@Parameter(property = "s3-upload.region")
|
||||
private String region;
|
||||
|
||||
/** Force override of endpoint for S3 regions such as EU. */
|
||||
@Parameter(property = "s3-upload.endpoint")
|
||||
private String endpoint;
|
||||
@ -75,12 +66,12 @@ public class S3UploadMojo extends AbstractMojo
|
||||
throw new MojoExecutionException("File/folder doesn't exist: " + source);
|
||||
}
|
||||
|
||||
AmazonS3 s3 = getS3Client(accessKey, secretKey, region);
|
||||
AmazonS3 s3 = getS3Client(accessKey, secretKey);
|
||||
if (endpoint != null) {
|
||||
s3.setEndpoint(endpoint);
|
||||
}
|
||||
|
||||
if (!s3.doesBucketExistV2(bucketName)) {
|
||||
if (!s3.doesBucketExist(bucketName)) {
|
||||
throw new MojoExecutionException("Bucket doesn't exist: " + bucketName);
|
||||
}
|
||||
|
||||
@ -100,30 +91,17 @@ public class S3UploadMojo extends AbstractMojo
|
||||
source, bucketName, destination));
|
||||
}
|
||||
|
||||
private static AmazonS3 getS3Client(String accessKey, String secretKey, String region)
|
||||
private static AmazonS3 getS3Client(String accessKey, String secretKey)
|
||||
{
|
||||
AWSCredentialsProvider provider;
|
||||
if (accessKey != null && secretKey != null) {
|
||||
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
|
||||
provider = new AWSStaticCredentialsProvider(credentials);
|
||||
provider = new StaticCredentialsProvider(credentials);
|
||||
} else {
|
||||
provider = new AWSCredentialsProviderChain(
|
||||
new EnvironmentVariableCredentialsProvider(),
|
||||
new SystemPropertiesCredentialsProvider(),
|
||||
WebIdentityTokenCredentialsProvider.create(),
|
||||
new ProfileCredentialsProvider(),
|
||||
new CliCompatibleCredentialsProvider(),
|
||||
new SsoCompatibleCredentialsProvider(),
|
||||
new EC2ContainerCredentialsProviderWrapper()
|
||||
);
|
||||
provider = new DefaultAWSCredentialsProviderChain();
|
||||
}
|
||||
|
||||
final AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard().withCredentials(provider);
|
||||
if (region != null) {
|
||||
s3ClientBuilder.setRegion(region);
|
||||
}
|
||||
|
||||
return s3ClientBuilder.build();
|
||||
return new AmazonS3Client(provider);
|
||||
}
|
||||
|
||||
private boolean upload(AmazonS3 s3, File sourceFile) throws MojoExecutionException
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
package com.bazaarvoice.maven.plugins.s3.upload;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.auth.BasicSessionCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
|
||||
import software.amazon.awssdk.services.sso.SsoClient;
|
||||
import software.amazon.awssdk.services.sso.auth.SsoCredentialsProvider;
|
||||
|
||||
/**
|
||||
* Derived from https://github.com/aws/aws-sdk-java/issues/2434#issuecomment-819985174
|
||||
*
|
||||
* This adapter may be removed if the project is fully migrated to AWS SDK v2
|
||||
*/
|
||||
class SsoCompatibleCredentialsProvider implements AWSCredentialsProvider {
|
||||
private final SsoCredentialsProvider delegate;
|
||||
|
||||
public SsoCompatibleCredentialsProvider() {
|
||||
final SsoClient ssoClient = SsoClient.builder().build();
|
||||
SsoCredentialsProvider.Builder builder = SsoCredentialsProvider.builder();
|
||||
|
||||
builder.ssoClient(ssoClient);
|
||||
|
||||
this.delegate = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AWSCredentials getCredentials() {
|
||||
AwsCredentials credentials = delegate.resolveCredentials();
|
||||
|
||||
if (credentials instanceof AwsSessionCredentials) {
|
||||
AwsSessionCredentials sessionCredentials = (AwsSessionCredentials) credentials;
|
||||
return new BasicSessionCredentials(sessionCredentials.accessKeyId(),
|
||||
sessionCredentials.secretAccessKey(),
|
||||
sessionCredentials.sessionToken());
|
||||
}
|
||||
|
||||
return new BasicAWSCredentials(credentials.accessKeyId(), credentials.secretAccessKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user