Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Bugfixes and updates to AWS SDK #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea/libraries
.idea/tasks.xml
.idea/workspace.xml
.idea/
*.iml
target
pom.xml.releaseBackup
release.properties
4 changes: 1 addition & 3 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
This project is a [Maven Wagon][wagon] for [Amazon S3][s3]. In order to to publish artifacts to an S3 bucket, the user (as identified by their access key) must be listed as an owner on the bucket.

## Why this fork?
This fork's enhancement is the ability to customize the AWS credentials
provider chain that is used to resolve credentials for the S3 bucket that hosts
the Maven artifacts you deploy. The upstream version uses a default provider
chain that includes an `InstanceProfileCredentialsProvider` that, in my
opinion, just takes too darn long to realize it's not going to be able to
resolve any credentials and should give up.

- Uses a more recent version of the AWS SDK (and only depends on the S3 portion of the SDK)
- Allows customization of the AWS credentials provider chain
- By default it uses the DefaultAWSCredentialsProviderChain built in to the S3 SDK.
- Omits S3 calls for creating directories (unnecessary in S3)
- Fixes https://github.com/spring-projects/aws-maven/issues/40

## Usage
To publish Maven artifacts to S3 a build extension must be defined in a project's `pom.xml`. The latest version of the wagon can be found in the `mvn-repo` branch of this repository.
Expand Down Expand Up @@ -101,6 +101,7 @@ tokens:

- `EnvironmentVariable` - use an (EnvironmentVariableCredentialsProvider)[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/EnvironmentVariableCredentialsProvider.html] that checks `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY` environment variables
- `SystemProperties` - use a (SystemPropertiesCredentialsProvider)[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/SystemPropertiesCredentialsProvider.html] that checks the `aws.accessKeyId` and `aws.secretKey` Java system properties
- `Profile` - use an (ProfileCredentialsProvider)[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/profile/ProfileCredentialsProvider.html]
- `InstanceProfile` - use an (InstanceProfileCredentialsProvider)[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/InstanceProfileCredentialsProvider.html] that tries to load credentials from the Amazon EC2 Instance Metadata Service
- `AuthenticationInfo` - use an `org.springframework.build.aws.maven.AuthenticationInfoAWSCredentialsProvider` that gets credentials from the `<server>` username and password settings from `~/.m2/settings.xml`

Expand Down
27 changes: 16 additions & 11 deletions aws-maven.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.1" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.6" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.1.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.1.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.1.1" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.3" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk-s3:1.11.39" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk-kms:1.11.39" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk-core:1.11.39" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:jmespath-java:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: software.amazon.ion:ion-java:1.0.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.6.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.6.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.6.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.6.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.wagon:wagon-provider-api:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-utils:3.0.8" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.9.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:1.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.6" level="project" />
</component>
</module>

</module>
41 changes: 13 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>Standard Maven wagon support for s3:// urls</description>

<properties>
<amazonaws.version>1.7.1</amazonaws.version>
<amazonaws.version>1.11.39</amazonaws.version>
<junit.version>4.11</junit.version>
<logback.version>1.1.1</logback.version>
<mockito.version>1.9.5</mockito.version>
Expand All @@ -34,31 +34,26 @@
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${amazonaws.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax</artifactId>
</exclusion>
<exclusion>
<artifactId>joda-time</artifactId>
<groupId>joda-time</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -77,16 +72,6 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.springframework.build.aws.maven;

import java.io.File;
import java.util.List;

import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
Expand All @@ -31,9 +34,6 @@
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;

import java.io.File;
import java.util.List;

abstract class AbstractWagon implements Wagon {

private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
Expand Down Expand Up @@ -216,6 +216,14 @@ public final void openConnection() {
// Nothing to do here (never called by the wagon manager)
}

/**
*
* @param source
* @param destination should not begin with "/"
* @throws TransferFailedException
* @throws ResourceDoesNotExistException
* @throws AuthorizationException
*/
@Override
public final void put(File source, String destination) throws TransferFailedException,
ResourceDoesNotExistException, AuthorizationException {
Expand All @@ -239,7 +247,18 @@ public final void putDirectory(File sourceDirectory, String destinationDirectory
File[] files = sourceDirectory.listFiles();
if (files != null) {
for (File f : files) {
put(f, destinationDirectory + "/" + f.getName());
String destinationPrefix;
if (destinationDirectory.equals("./")) {
destinationPrefix = "";
} else {
destinationPrefix = destinationDirectory + "/";
}

if (f.isFile()) {
put(f, destinationPrefix + f.getName());
} else if (f.isDirectory()) {
putDirectory(f, destinationPrefix + f.getName());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@

package org.springframework.build.aws.maven;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class AuthenticationInfoAWSCredentialsProviderChain extends AWSCredentialsProviderChain {

public static final String PARAM_CREDENTIALS_PROVIDERS = "credentialsProviders";
public static final String VALUE_ENVIRONMENT_VARIABLE_CREDENTIALS_PROVIDER = "EnvironmentVariable";
public static final String VALUE_SYSTEM_PROPERTIES_CREDENTIALS_PROVIDER = "SystemProperties";
public static final String VALUE_PROFILE_CREDENTIALS_PROVIDER = "Profile";
public static final String VALUE_INSTANCE_PROFILE_CREDENTIALS_PROVIDER = "InstanceProfile";
public static final String VALUE_AUTHENTICATION_INFO_CREDENTIALS_PROVIDER = "AuthenticationInfo";

Expand All @@ -44,15 +48,16 @@ private AuthenticationInfoAWSCredentialsProviderChain(AWSCredentialsProvider...
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
super(new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider(false),
new AuthenticationInfoAWSCredentialsProvider(authenticationInfo));
}

public static AuthenticationInfoAWSCredentialsProviderChain buildFromParameterValue(String parameterValue,
public static AWSCredentialsProvider buildFromParameterValue(String parameterValue,
AuthenticationInfo authenticationInfo) {
if (parameterValue == null) {
log.debug("using default credentials provider chain");
return new AuthenticationInfoAWSCredentialsProviderChain(authenticationInfo);
log.debug("using " + DefaultAWSCredentialsProviderChain.class.getCanonicalName());

return new DefaultAWSCredentialsProviderChain();
}
String[] tokens = parameterValue.split("[^\\w]+");
List<AWSCredentialsProvider> providerList = new ArrayList<AWSCredentialsProvider>();
Expand All @@ -71,8 +76,10 @@ private static AWSCredentialsProvider parseProvider(String token, Authentication
provider = new EnvironmentVariableCredentialsProvider();
} else if (VALUE_SYSTEM_PROPERTIES_CREDENTIALS_PROVIDER.equalsIgnoreCase(token)) {
provider = new SystemPropertiesCredentialsProvider();
} else if (VALUE_PROFILE_CREDENTIALS_PROVIDER.equalsIgnoreCase(token)) {
provider = new ProfileCredentialsProvider();
} else if (VALUE_INSTANCE_PROFILE_CREDENTIALS_PROVIDER.equalsIgnoreCase(token)) {
provider = new InstanceProfileCredentialsProvider();
provider = new InstanceProfileCredentialsProvider(false);
} else if (VALUE_AUTHENTICATION_INFO_CREDENTIALS_PROVIDER.equalsIgnoreCase(token)) {
provider = new AuthenticationInfoAWSCredentialsProvider(authenticationInfo);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static String getBucketName(Repository repository) {
return repository.getHost();
}

/**
*
* @param repository
* @return a string representation of the basedir, if non-empty always ending in '/'
*/
static String getBaseDirectory(Repository repository) {
StringBuilder sb = new StringBuilder(repository.getBasedir()).deleteCharAt(0);

Expand Down
Loading