-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from metamx/common-aws-config
Common AWS module + consistent credential chain for both S3 and auto-scaling
- Loading branch information
Showing
13 changed files
with
255 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Druid - a distributed column store. | ||
~ Copyright (C) 2015 Metamarkets Group Inc. | ||
~ | ||
~ This program is free software; you can redistribute it and/or | ||
~ modify it under the terms of the GNU General Public License | ||
~ as published by the Free Software Foundation; either version 2 | ||
~ of the License, or (at your option) any later version. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, | ||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
~ GNU General Public License for more details. | ||
~ | ||
~ You should have received a copy of the GNU General Public License | ||
~ along with this program; if not, write to the Free Software | ||
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>druid-aws-common</artifactId> | ||
<name>druid-aws-common</name> | ||
<description>druid-aws-common</description> | ||
|
||
<parent> | ||
<groupId>io.druid</groupId> | ||
<artifactId>druid</artifactId> | ||
<version>0.7.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.druid</groupId> | ||
<artifactId>druid-common</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk</artifactId> | ||
</dependency> | ||
|
||
<!-- Tests --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
aws-common/src/main/java/io/druid/common/aws/AWSCredentialsUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* Copyright (C) 2015 Metamarkets Group Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package io.druid.common.aws; | ||
|
||
import com.amazonaws.auth.AWSCredentialsProviderChain; | ||
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; | ||
import com.amazonaws.auth.InstanceProfileCredentialsProvider; | ||
import com.amazonaws.auth.SystemPropertiesCredentialsProvider; | ||
import com.amazonaws.auth.profile.ProfileCredentialsProvider; | ||
|
||
public class AWSCredentialsUtils | ||
{ | ||
public static AWSCredentialsProviderChain defaultAWSCredentialsProviderChain(final AWSCredentialsConfig config) { | ||
return new AWSCredentialsProviderChain( | ||
new ConfigDrivenAwsCredentialsConfigProvider(config), | ||
new LazyFileSessionCredentialsProvider(config), | ||
new EnvironmentVariableCredentialsProvider(), | ||
new SystemPropertiesCredentialsProvider(), | ||
new ProfileCredentialsProvider(), | ||
new InstanceProfileCredentialsProvider()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
aws-common/src/main/java/io/druid/common/aws/ConfigDrivenAwsCredentialsConfigProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* Copyright (C) 2015 Metamarkets Group Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package io.druid.common.aws; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.google.common.base.Strings; | ||
|
||
public class ConfigDrivenAwsCredentialsConfigProvider implements AWSCredentialsProvider | ||
{ | ||
private AWSCredentialsConfig config; | ||
|
||
public ConfigDrivenAwsCredentialsConfigProvider(AWSCredentialsConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public com.amazonaws.auth.AWSCredentials getCredentials() | ||
{ | ||
if (!Strings.isNullOrEmpty(config.getAccessKey()) && !Strings.isNullOrEmpty(config.getSecretKey())) { | ||
return new com.amazonaws.auth.AWSCredentials() { | ||
@Override | ||
public String getAWSAccessKeyId() { | ||
return config.getAccessKey(); | ||
} | ||
|
||
@Override | ||
public String getAWSSecretKey() { | ||
return config.getSecretKey(); | ||
} | ||
}; | ||
} | ||
throw new AmazonClientException("Unable to load AWS credentials from druid AWSCredentialsConfig"); | ||
} | ||
|
||
@Override | ||
public void refresh() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
aws-common/src/main/java/io/druid/common/aws/LazyFileSessionCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* Copyright (C) 2015 Metamarkets Group Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package io.druid.common.aws; | ||
|
||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
|
||
public class LazyFileSessionCredentialsProvider implements AWSCredentialsProvider | ||
{ | ||
private AWSCredentialsConfig config; | ||
private FileSessionCredentialsProvider provider; | ||
|
||
public LazyFileSessionCredentialsProvider(AWSCredentialsConfig config) { | ||
this.config = config; | ||
} | ||
|
||
private FileSessionCredentialsProvider getUnderlyingProvider() { | ||
if (provider == null) { | ||
synchronized (config) { | ||
if (provider == null) { | ||
provider = new FileSessionCredentialsProvider(config.getFileSessionCredentials()); | ||
} | ||
} | ||
} | ||
return provider; | ||
} | ||
|
||
@Override | ||
public com.amazonaws.auth.AWSCredentials getCredentials() | ||
{ | ||
return getUnderlyingProvider().getCredentials(); | ||
} | ||
|
||
@Override | ||
public void refresh() { | ||
getUnderlyingProvider().refresh(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.