embulk-output-dynamodb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/CHANGELOG.md +1 -0
- data/README.md +210 -0
- data/build.gradle +92 -0
- data/config/checkstyle/checkstyle.xml +130 -0
- data/config/checkstyle/default.xml +110 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +160 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/output/dynamodb.rb +3 -0
- data/settings.gradle +2 -0
- data/src/main/java/org/embulk/output/dynamodb/AwsCredentials.java +182 -0
- data/src/main/java/org/embulk/output/dynamodb/AwsCredentialsTask.java +39 -0
- data/src/main/java/org/embulk/output/dynamodb/DynamodbOutputPlugin.java +425 -0
- data/src/main/java/org/embulk/output/dynamodb/DynamodbUtils.java +361 -0
- data/src/test/java/org/embulk/output/dynamodb/TestDynamodbOutputPlugin.java +249 -0
- data/src/test/java/org/embulk/output/dynamodb/TestDynamodbUtils.java +10 -0
- data/src/test/resources/sample_01.csv +5 -0
- metadata +100 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE module PUBLIC
|
3
|
+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
4
|
+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
5
|
+
<!--
|
6
|
+
This is a subset of ./checkstyle.xml which allows some loose styles
|
7
|
+
-->
|
8
|
+
<module name="Checker">
|
9
|
+
<module name="FileTabCharacter"/>
|
10
|
+
<module name="NewlineAtEndOfFile">
|
11
|
+
<property name="lineSeparator" value="lf"/>
|
12
|
+
</module>
|
13
|
+
<module name="RegexpMultiline">
|
14
|
+
<property name="format" value="\r"/>
|
15
|
+
<property name="message" value="Line contains carriage return"/>
|
16
|
+
</module>
|
17
|
+
<module name="RegexpMultiline">
|
18
|
+
<property name="format" value=" \n"/>
|
19
|
+
<property name="message" value="Line has trailing whitespace"/>
|
20
|
+
</module>
|
21
|
+
<module name="RegexpMultiline">
|
22
|
+
<property name="format" value="\n\n\n"/>
|
23
|
+
<property name="message" value="Multiple consecutive blank lines"/>
|
24
|
+
</module>
|
25
|
+
<module name="RegexpMultiline">
|
26
|
+
<property name="format" value="\n\n\Z"/>
|
27
|
+
<property name="message" value="Blank line before end of file"/>
|
28
|
+
</module>
|
29
|
+
|
30
|
+
<module name="TreeWalker">
|
31
|
+
<module name="EmptyBlock">
|
32
|
+
<property name="option" value="text"/>
|
33
|
+
<property name="tokens" value="
|
34
|
+
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
35
|
+
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
|
36
|
+
</module>
|
37
|
+
<module name="EmptyStatement"/>
|
38
|
+
<module name="EmptyForInitializerPad"/>
|
39
|
+
<module name="EmptyForIteratorPad">
|
40
|
+
<property name="option" value="space"/>
|
41
|
+
</module>
|
42
|
+
<module name="MethodParamPad">
|
43
|
+
<property name="allowLineBreaks" value="true"/>
|
44
|
+
<property name="option" value="nospace"/>
|
45
|
+
</module>
|
46
|
+
<module name="ParenPad"/>
|
47
|
+
<module name="TypecastParenPad"/>
|
48
|
+
<module name="NeedBraces"/>
|
49
|
+
<module name="LeftCurly">
|
50
|
+
<property name="option" value="nl"/>
|
51
|
+
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
|
52
|
+
</module>
|
53
|
+
<module name="LeftCurly">
|
54
|
+
<property name="option" value="eol"/>
|
55
|
+
<property name="tokens" value="
|
56
|
+
LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
|
57
|
+
LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
|
58
|
+
</module>
|
59
|
+
<module name="RightCurly">
|
60
|
+
<property name="option" value="alone"/>
|
61
|
+
</module>
|
62
|
+
<module name="GenericWhitespace"/>
|
63
|
+
<module name="WhitespaceAfter"/>
|
64
|
+
<module name="NoWhitespaceBefore"/>
|
65
|
+
|
66
|
+
<module name="UpperEll"/>
|
67
|
+
<module name="DefaultComesLast"/>
|
68
|
+
<module name="ArrayTypeStyle"/>
|
69
|
+
<module name="MultipleVariableDeclarations"/>
|
70
|
+
<module name="ModifierOrder"/>
|
71
|
+
<module name="OneStatementPerLine"/>
|
72
|
+
<module name="StringLiteralEquality"/>
|
73
|
+
<module name="MutableException"/>
|
74
|
+
<module name="EqualsHashCode"/>
|
75
|
+
<module name="InnerAssignment"/>
|
76
|
+
<module name="InterfaceIsType"/>
|
77
|
+
<module name="HideUtilityClassConstructor"/>
|
78
|
+
|
79
|
+
<module name="MemberName"/>
|
80
|
+
<module name="LocalVariableName"/>
|
81
|
+
<module name="LocalFinalVariableName"/>
|
82
|
+
<module name="TypeName"/>
|
83
|
+
<module name="PackageName"/>
|
84
|
+
<module name="ParameterName"/>
|
85
|
+
<module name="StaticVariableName">
|
86
|
+
<property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
|
87
|
+
</module>
|
88
|
+
<module name="ClassTypeParameterName">
|
89
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
90
|
+
</module>
|
91
|
+
<module name="MethodTypeParameterName">
|
92
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
93
|
+
</module>
|
94
|
+
|
95
|
+
<module name="WhitespaceAround">
|
96
|
+
<property name="allowEmptyConstructors" value="true"/>
|
97
|
+
<property name="allowEmptyMethods" value="true"/>
|
98
|
+
<property name="ignoreEnhancedForColon" value="false"/>
|
99
|
+
<property name="tokens" value="
|
100
|
+
ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
|
101
|
+
BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
|
102
|
+
LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
103
|
+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
104
|
+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
|
105
|
+
LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
|
106
|
+
PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
|
107
|
+
STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
|
108
|
+
</module>
|
109
|
+
</module>
|
110
|
+
</module>
|
Binary file
|
data/gradlew
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
##############################################################################
|
4
|
+
##
|
5
|
+
## Gradle start up script for UN*X
|
6
|
+
##
|
7
|
+
##############################################################################
|
8
|
+
|
9
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
10
|
+
DEFAULT_JVM_OPTS=""
|
11
|
+
|
12
|
+
APP_NAME="Gradle"
|
13
|
+
APP_BASE_NAME=`basename "$0"`
|
14
|
+
|
15
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
16
|
+
MAX_FD="maximum"
|
17
|
+
|
18
|
+
warn ( ) {
|
19
|
+
echo "$*"
|
20
|
+
}
|
21
|
+
|
22
|
+
die ( ) {
|
23
|
+
echo
|
24
|
+
echo "$*"
|
25
|
+
echo
|
26
|
+
exit 1
|
27
|
+
}
|
28
|
+
|
29
|
+
# OS specific support (must be 'true' or 'false').
|
30
|
+
cygwin=false
|
31
|
+
msys=false
|
32
|
+
darwin=false
|
33
|
+
case "`uname`" in
|
34
|
+
CYGWIN* )
|
35
|
+
cygwin=true
|
36
|
+
;;
|
37
|
+
Darwin* )
|
38
|
+
darwin=true
|
39
|
+
;;
|
40
|
+
MINGW* )
|
41
|
+
msys=true
|
42
|
+
;;
|
43
|
+
esac
|
44
|
+
|
45
|
+
# Attempt to set APP_HOME
|
46
|
+
# Resolve links: $0 may be a link
|
47
|
+
PRG="$0"
|
48
|
+
# Need this for relative symlinks.
|
49
|
+
while [ -h "$PRG" ] ; do
|
50
|
+
ls=`ls -ld "$PRG"`
|
51
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
52
|
+
if expr "$link" : '/.*' > /dev/null; then
|
53
|
+
PRG="$link"
|
54
|
+
else
|
55
|
+
PRG=`dirname "$PRG"`"/$link"
|
56
|
+
fi
|
57
|
+
done
|
58
|
+
SAVED="`pwd`"
|
59
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
60
|
+
APP_HOME="`pwd -P`"
|
61
|
+
cd "$SAVED" >/dev/null
|
62
|
+
|
63
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
64
|
+
|
65
|
+
# Determine the Java command to use to start the JVM.
|
66
|
+
if [ -n "$JAVA_HOME" ] ; then
|
67
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
68
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
69
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
70
|
+
else
|
71
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
72
|
+
fi
|
73
|
+
if [ ! -x "$JAVACMD" ] ; then
|
74
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
75
|
+
|
76
|
+
Please set the JAVA_HOME variable in your environment to match the
|
77
|
+
location of your Java installation."
|
78
|
+
fi
|
79
|
+
else
|
80
|
+
JAVACMD="java"
|
81
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
82
|
+
|
83
|
+
Please set the JAVA_HOME variable in your environment to match the
|
84
|
+
location of your Java installation."
|
85
|
+
fi
|
86
|
+
|
87
|
+
# Increase the maximum file descriptors if we can.
|
88
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
89
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
90
|
+
if [ $? -eq 0 ] ; then
|
91
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
92
|
+
MAX_FD="$MAX_FD_LIMIT"
|
93
|
+
fi
|
94
|
+
ulimit -n $MAX_FD
|
95
|
+
if [ $? -ne 0 ] ; then
|
96
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
97
|
+
fi
|
98
|
+
else
|
99
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
100
|
+
fi
|
101
|
+
fi
|
102
|
+
|
103
|
+
# For Darwin, add options to specify how the application appears in the dock
|
104
|
+
if $darwin; then
|
105
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
106
|
+
fi
|
107
|
+
|
108
|
+
# For Cygwin, switch paths to Windows format before running java
|
109
|
+
if $cygwin ; then
|
110
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
111
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
112
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
113
|
+
|
114
|
+
# We build the pattern for arguments to be converted via cygpath
|
115
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
116
|
+
SEP=""
|
117
|
+
for dir in $ROOTDIRSRAW ; do
|
118
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
119
|
+
SEP="|"
|
120
|
+
done
|
121
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
122
|
+
# Add a user-defined pattern to the cygpath arguments
|
123
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
124
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
125
|
+
fi
|
126
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
127
|
+
i=0
|
128
|
+
for arg in "$@" ; do
|
129
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
130
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
131
|
+
|
132
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
133
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
134
|
+
else
|
135
|
+
eval `echo args$i`="\"$arg\""
|
136
|
+
fi
|
137
|
+
i=$((i+1))
|
138
|
+
done
|
139
|
+
case $i in
|
140
|
+
(0) set -- ;;
|
141
|
+
(1) set -- "$args0" ;;
|
142
|
+
(2) set -- "$args0" "$args1" ;;
|
143
|
+
(3) set -- "$args0" "$args1" "$args2" ;;
|
144
|
+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
145
|
+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
146
|
+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
147
|
+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
148
|
+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
149
|
+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
150
|
+
esac
|
151
|
+
fi
|
152
|
+
|
153
|
+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
154
|
+
function splitJvmOpts() {
|
155
|
+
JVM_OPTS=("$@")
|
156
|
+
}
|
157
|
+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
158
|
+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
159
|
+
|
160
|
+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
data/gradlew.bat
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
@if "%DEBUG%" == "" @echo off
|
2
|
+
@rem ##########################################################################
|
3
|
+
@rem
|
4
|
+
@rem Gradle startup script for Windows
|
5
|
+
@rem
|
6
|
+
@rem ##########################################################################
|
7
|
+
|
8
|
+
@rem Set local scope for the variables with windows NT shell
|
9
|
+
if "%OS%"=="Windows_NT" setlocal
|
10
|
+
|
11
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
12
|
+
set DEFAULT_JVM_OPTS=
|
13
|
+
|
14
|
+
set DIRNAME=%~dp0
|
15
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
16
|
+
set APP_BASE_NAME=%~n0
|
17
|
+
set APP_HOME=%DIRNAME%
|
18
|
+
|
19
|
+
@rem Find java.exe
|
20
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
21
|
+
|
22
|
+
set JAVA_EXE=java.exe
|
23
|
+
%JAVA_EXE% -version >NUL 2>&1
|
24
|
+
if "%ERRORLEVEL%" == "0" goto init
|
25
|
+
|
26
|
+
echo.
|
27
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
28
|
+
echo.
|
29
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
30
|
+
echo location of your Java installation.
|
31
|
+
|
32
|
+
goto fail
|
33
|
+
|
34
|
+
:findJavaFromJavaHome
|
35
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
36
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
37
|
+
|
38
|
+
if exist "%JAVA_EXE%" goto init
|
39
|
+
|
40
|
+
echo.
|
41
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
42
|
+
echo.
|
43
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
44
|
+
echo location of your Java installation.
|
45
|
+
|
46
|
+
goto fail
|
47
|
+
|
48
|
+
:init
|
49
|
+
@rem Get command-line arguments, handling Windowz variants
|
50
|
+
|
51
|
+
if not "%OS%" == "Windows_NT" goto win9xME_args
|
52
|
+
if "%@eval[2+2]" == "4" goto 4NT_args
|
53
|
+
|
54
|
+
:win9xME_args
|
55
|
+
@rem Slurp the command line arguments.
|
56
|
+
set CMD_LINE_ARGS=
|
57
|
+
set _SKIP=2
|
58
|
+
|
59
|
+
:win9xME_args_slurp
|
60
|
+
if "x%~1" == "x" goto execute
|
61
|
+
|
62
|
+
set CMD_LINE_ARGS=%*
|
63
|
+
goto execute
|
64
|
+
|
65
|
+
:4NT_args
|
66
|
+
@rem Get arguments from the 4NT Shell from JP Software
|
67
|
+
set CMD_LINE_ARGS=%$
|
68
|
+
|
69
|
+
:execute
|
70
|
+
@rem Setup the command line
|
71
|
+
|
72
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
73
|
+
|
74
|
+
@rem Execute Gradle
|
75
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
76
|
+
|
77
|
+
:end
|
78
|
+
@rem End local scope for the variables with windows NT shell
|
79
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
80
|
+
|
81
|
+
:fail
|
82
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
83
|
+
rem the _cmd.exe /c_ return code!
|
84
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
85
|
+
exit /b 1
|
86
|
+
|
87
|
+
:mainEnd
|
88
|
+
if "%OS%"=="Windows_NT" endlocal
|
89
|
+
|
90
|
+
:omega
|
data/settings.gradle
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
package org.embulk.output.dynamodb;
|
2
|
+
|
3
|
+
import com.amazonaws.auth.AWSCredentials;
|
4
|
+
import com.amazonaws.auth.AWSCredentialsProvider;
|
5
|
+
import com.amazonaws.auth.AWSSessionCredentials;
|
6
|
+
import com.amazonaws.auth.AWSSessionCredentialsProvider;
|
7
|
+
import com.amazonaws.auth.AnonymousAWSCredentials;
|
8
|
+
import com.amazonaws.auth.BasicAWSCredentials;
|
9
|
+
import com.amazonaws.auth.BasicSessionCredentials;
|
10
|
+
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
|
11
|
+
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
|
12
|
+
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
|
13
|
+
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
|
14
|
+
import com.amazonaws.auth.profile.ProfilesConfigFile;
|
15
|
+
import com.google.common.base.Optional;
|
16
|
+
import org.embulk.config.ConfigException;
|
17
|
+
import org.embulk.spi.Exec;
|
18
|
+
import org.embulk.spi.unit.LocalFile;
|
19
|
+
import org.slf4j.Logger;
|
20
|
+
|
21
|
+
public abstract class AwsCredentials
|
22
|
+
{
|
23
|
+
private AwsCredentials()
|
24
|
+
{
|
25
|
+
}
|
26
|
+
|
27
|
+
public static AWSCredentialsProvider getAWSCredentialsProvider(AwsCredentialsTask task)
|
28
|
+
{
|
29
|
+
switch (task.getAuthMethod()) {
|
30
|
+
case "basic":
|
31
|
+
// for backward compatibility
|
32
|
+
if (!task.getAccessKeyId().isPresent() && !task.getAccessKeyId().isPresent()) {
|
33
|
+
final Logger log = Exec.getLogger(AwsCredentials.class);
|
34
|
+
log.warn("Both access_key_id and secret_access_key are not set. Assuming that 'auth_method: anonymous' option is set.");
|
35
|
+
log.warn("If you intentionally use anonymous authentication, please set 'auth_method: anonymous' option.");
|
36
|
+
log.warn("This behavior will be removed in a futurte release.");
|
37
|
+
reject(task.getSessionToken(), "session_token");
|
38
|
+
reject(task.getProfileFile(), "profile_file");
|
39
|
+
reject(task.getProfileName(), "profile_name");
|
40
|
+
return new AWSCredentialsProvider() {
|
41
|
+
@Override
|
42
|
+
public AWSCredentials getCredentials()
|
43
|
+
{
|
44
|
+
return new AnonymousAWSCredentials();
|
45
|
+
}
|
46
|
+
|
47
|
+
@Override
|
48
|
+
public void refresh()
|
49
|
+
{
|
50
|
+
}
|
51
|
+
};
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
String accessKeyId = require(task.getAccessKeyId(), "'access_key_id', 'secret_access_key'");
|
55
|
+
String secretAccessKey = require(task.getSecretAccessKey(), "'secret_access_key'");
|
56
|
+
reject(task.getSessionToken(), "session_token");
|
57
|
+
reject(task.getProfileFile(), "profile_file");
|
58
|
+
reject(task.getProfileName(), "profile_name");
|
59
|
+
final BasicAWSCredentials creds = new BasicAWSCredentials(accessKeyId, secretAccessKey);
|
60
|
+
return new AWSCredentialsProvider() {
|
61
|
+
@Override
|
62
|
+
public AWSCredentials getCredentials()
|
63
|
+
{
|
64
|
+
return creds;
|
65
|
+
}
|
66
|
+
|
67
|
+
@Override
|
68
|
+
public void refresh()
|
69
|
+
{
|
70
|
+
}
|
71
|
+
};
|
72
|
+
}
|
73
|
+
|
74
|
+
case "env":
|
75
|
+
reject(task.getAccessKeyId(), "access_key_id");
|
76
|
+
reject(task.getSecretAccessKey(), "secret_access_key");
|
77
|
+
reject(task.getSessionToken(), "session_token");
|
78
|
+
reject(task.getProfileFile(), "profile_file");
|
79
|
+
reject(task.getProfileName(), "profile_name");
|
80
|
+
return overwriteBasicCredentials(task, new EnvironmentVariableCredentialsProvider().getCredentials());
|
81
|
+
|
82
|
+
case "instance":
|
83
|
+
reject(task.getAccessKeyId(), "access_key_id");
|
84
|
+
reject(task.getSecretAccessKey(), "secret_access_key");
|
85
|
+
reject(task.getSessionToken(), "session_token");
|
86
|
+
reject(task.getProfileFile(), "profile_file");
|
87
|
+
reject(task.getProfileName(), "profile_name");
|
88
|
+
return new InstanceProfileCredentialsProvider();
|
89
|
+
|
90
|
+
case "profile":
|
91
|
+
{
|
92
|
+
reject(task.getAccessKeyId(), "access_key_id");
|
93
|
+
reject(task.getSecretAccessKey(), "secret_access_key");
|
94
|
+
reject(task.getSessionToken(), "session_token");
|
95
|
+
|
96
|
+
String profileName = task.getProfileName().or("default");
|
97
|
+
ProfileCredentialsProvider provider;
|
98
|
+
if (task.getProfileFile().isPresent()) {
|
99
|
+
ProfilesConfigFile file = new ProfilesConfigFile(task.getProfileFile().get().getFile());
|
100
|
+
provider = new ProfileCredentialsProvider(file, profileName);
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
provider = new ProfileCredentialsProvider(profileName);
|
104
|
+
}
|
105
|
+
task.setProfileName(Optional.<String>absent());
|
106
|
+
task.setProfileFile(Optional.<LocalFile>absent());
|
107
|
+
|
108
|
+
return overwriteBasicCredentials(task, provider.getCredentials());
|
109
|
+
}
|
110
|
+
|
111
|
+
case "properties":
|
112
|
+
reject(task.getAccessKeyId(), "access_key_id");
|
113
|
+
reject(task.getSecretAccessKey(), "secret_access_key");
|
114
|
+
reject(task.getSessionToken(), "session_token");
|
115
|
+
reject(task.getProfileFile(), "profile_file");
|
116
|
+
reject(task.getProfileName(), "profile_name");
|
117
|
+
return overwriteBasicCredentials(task, new SystemPropertiesCredentialsProvider().getCredentials());
|
118
|
+
|
119
|
+
case "session":
|
120
|
+
{
|
121
|
+
String accessKeyId = require(task.getAccessKeyId(), "'access_key_id', 'secret_access_key', 'session_token'");
|
122
|
+
String secretAccessKey = require(task.getSecretAccessKey(), "'secret_access_key', 'session_token'");
|
123
|
+
String sessionToken = require(task.getSessionToken(), "'session_token'");
|
124
|
+
reject(task.getProfileFile(), "profile_file");
|
125
|
+
reject(task.getProfileName(), "profile_name");
|
126
|
+
final AWSSessionCredentials creds = new BasicSessionCredentials(accessKeyId, secretAccessKey, sessionToken);
|
127
|
+
return new AWSSessionCredentialsProvider() {
|
128
|
+
@Override
|
129
|
+
public AWSSessionCredentials getCredentials()
|
130
|
+
{
|
131
|
+
return creds;
|
132
|
+
}
|
133
|
+
|
134
|
+
@Override
|
135
|
+
public void refresh()
|
136
|
+
{
|
137
|
+
}
|
138
|
+
};
|
139
|
+
}
|
140
|
+
|
141
|
+
default:
|
142
|
+
throw new ConfigException(String.format("Unknwon auth_method '%s'. Supported methods are basic, instance, profile, properties, and session.",
|
143
|
+
task.getAuthMethod()));
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
private static AWSCredentialsProvider overwriteBasicCredentials(AwsCredentialsTask task, final AWSCredentials creds)
|
148
|
+
{
|
149
|
+
task.setAuthMethod("basic");
|
150
|
+
task.setAccessKeyId(Optional.of(creds.getAWSAccessKeyId()));
|
151
|
+
task.setSecretAccessKey(Optional.of(creds.getAWSSecretKey()));
|
152
|
+
return new AWSCredentialsProvider() {
|
153
|
+
@Override
|
154
|
+
public AWSCredentials getCredentials()
|
155
|
+
{
|
156
|
+
return creds;
|
157
|
+
}
|
158
|
+
|
159
|
+
@Override
|
160
|
+
public void refresh()
|
161
|
+
{
|
162
|
+
}
|
163
|
+
};
|
164
|
+
}
|
165
|
+
|
166
|
+
private static <T> T require(Optional<T> value, String message)
|
167
|
+
{
|
168
|
+
if (value.isPresent()) {
|
169
|
+
return value.get();
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
throw new ConfigException("Required option is not set: " + message);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
private static <T> void reject(Optional<T> value, String message)
|
177
|
+
{
|
178
|
+
if (value.isPresent()) {
|
179
|
+
throw new ConfigException("Invalid option is set: " + message);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|