embulk-input-dynamodb 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -3
  3. data/build.gradle +29 -5
  4. data/circle.yml +8 -0
  5. data/config/checkstyle/checkstyle.xml +128 -0
  6. data/config/checkstyle/default.xml +108 -0
  7. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  8. data/gradle/wrapper/gradle-wrapper.properties +2 -2
  9. data/lib/embulk/input/dynamodb.rb +1 -1
  10. data/src/main/scala/org/embulk/input/dynamodb/AttributeValueHelper.scala +41 -0
  11. data/src/main/scala/org/embulk/input/dynamodb/AwsCredentials.scala +71 -0
  12. data/src/main/scala/org/embulk/input/{DynamoDBUtil.scala → dynamodb/DynamoDBUtil.scala} +54 -62
  13. data/src/main/scala/org/embulk/input/{DynamodbInputPlugin.scala → dynamodb/DynamodbInputPlugin.scala} +14 -8
  14. data/src/main/scala/org/embulk/input/{Filter.scala → dynamodb/Filter.scala} +2 -2
  15. data/src/main/scala/org/embulk/input/{FilterConfig.scala → dynamodb/FilterConfig.scala} +1 -1
  16. data/src/main/scala/org/embulk/input/{PluginTask.scala → dynamodb/PluginTask.scala} +10 -2
  17. data/src/test/resources/json/test.json +50 -0
  18. data/src/test/resources/json/test.template +27 -0
  19. data/src/test/resources/yaml/authMethodBasic.yml +20 -0
  20. data/src/test/resources/yaml/authMethodBasic_Error.yml +18 -0
  21. data/src/test/resources/yaml/authMethodEnv.yml +18 -0
  22. data/src/test/resources/yaml/authMethodProfile.yml +19 -0
  23. data/src/test/resources/yaml/notSetAuthMethod.yml +19 -0
  24. data/src/test/scala/org/embulk/input/dynamodb/AttributeValueHelperTest.scala +192 -0
  25. data/src/test/scala/org/embulk/input/dynamodb/AwsCredentialsTest.scala +135 -0
  26. metadata +29 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5bff72dc25c3fe5ce57da31798ac74d2ac7e8bf
4
- data.tar.gz: a35560d2b4a29e5d5d71d2d2656210da7653e19b
3
+ metadata.gz: fb06f7f31e946edcde0e6fde44443d11c20b2f1b
4
+ data.tar.gz: 83f448ad04d7f262c9a1438c79091ce1c6ac2765
5
5
  SHA512:
6
- metadata.gz: 41fd0fdc599929929d81519aefb58c72cb250f66650f31b8305d08ed26f77d41fe08fb8df275ada2383f388c6629a7d55c6b4211a519f74382781e6667cc85a6
7
- data.tar.gz: d0f608e76092fe34e150a4d3e4076c7a3f94e36d6990f64d721c2628702492456e7d48cd713bca5e8442cab958e4e82d7d695fab5901d0d3c75ac3d5f340cd1a
6
+ metadata.gz: 00544333da3be446d2e479fe1055f5599ea50655f0ba77d6ba465b0d4a0b58316675ac269a0299aaddd8469599b6d43dc02f05fb9b2d07b5daa25d68b4448f9f
7
+ data.tar.gz: 8960d06019a11c3e291f7724b0404e9dbd44df041a91cbe4bdaccb9b2e430a5213d60ff597aafab99ff9d6daa3409bead9b634126fa59a2712338e3084c6f318
data/README.md CHANGED
@@ -9,19 +9,34 @@
9
9
 
10
10
 
11
11
  ## Configuration
12
- - **access_key**: AWS access key (string, optional)
13
- - **secret_key**: AWS secret key (string, optional)
14
- If you don't specify keys, I'll use the profile configuration file for the default profile.
12
+ - **auth_method**: AWS Credential Type.
13
+ Available values options are: `basic`, `env`, `instance`, `profile`, `properties`
14
+ - **basic**: AWS access key and secret access key
15
+ - **env**: Environment variables
16
+ - **instance**: EC2 Instance Metadata Service
17
+ - **profile**: Profile configuration file
18
+ - **properties**: Java system properties
19
+ - If **auth_method** is set `basic`
20
+ - **access_key**: AWS access key (string, required)
21
+ - **secret_key**: AWS secret key (string, required)
22
+ - If **auth_method** is set `profile`
23
+ - **profile_name**: The name of a local configuration profile (string, optional)
15
24
  - **region**: Region Name (string, default: ap-northeast-1)
16
25
  - **table**: Table Name (string, required)
17
26
  - **scan_limit**: DynamoDB 1time Scan Query size limit (Int, optional)
18
27
  - **record_limit**: Max Record Search limit (Long, optional)
28
+ - **columns**: a key-value pairs where key is a column name and value is options for the column (required)
29
+ - **name**: Column name.
30
+ - **type**: Column values are converted to this embulk type.
31
+ Available values options are: `boolean`, `long`, `double`, `string`, `json`
32
+ - **filters**: query filter (optional)
19
33
 
20
34
  ## Example
21
35
 
22
36
  ```yaml
23
37
  in:
24
38
  type: dynamodb
39
+ auth_method: basic
25
40
  access_key: YOUR_ACCESS_KEY
26
41
  secret_key: YOUR_SECRET_KEY
27
42
  region: ap-northeast-1
@@ -31,6 +46,7 @@ in:
31
46
  - {name: ColumnB, type: double}
32
47
  - {name: ColumnC, type: string}
33
48
  - {name: ColumnD, type: boolean}
49
+ - {name: ColumnE, type: json}
34
50
  filters:
35
51
  - {name: ColumnA, type: long, condition: BETWEEN, value: 10000, value2: 20000}
36
52
  - {name: ColumnC, type: string, condition: EQ, value: foobar}
data/build.gradle CHANGED
@@ -2,6 +2,7 @@ plugins {
2
2
  id "com.jfrog.bintray" version "1.1"
3
3
  id "com.github.jruby-gradle.base" version "0.1.5"
4
4
  id "scala"
5
+ id "checkstyle"
5
6
  }
6
7
 
7
8
  import com.github.jrubygradle.JRubyExec
@@ -13,16 +14,22 @@ configurations {
13
14
  provided
14
15
  }
15
16
 
16
- version = "0.0.3"
17
+ version = "0.1.0"
18
+
19
+ sourceCompatibility = 1.7
20
+ targetCompatibility = 1.7
17
21
 
18
22
  dependencies {
19
- compile "org.scala-lang:scala-library:2.11.5"
23
+ compile "org.scala-lang:scala-library:2.11.7"
24
+
25
+ compile "org.embulk:embulk-core:0.8.6"
26
+ provided "org.embulk:embulk-core:0.8.6"
20
27
 
21
- compile "org.embulk:embulk-core:0.4.10"
22
- provided "org.embulk:embulk-core:0.4.10"
28
+ compile "com.amazonaws:aws-java-sdk-dynamodb:1.10.43"
23
29
 
24
- compile "com.amazonaws:aws-java-sdk-dynamodb:1.9.22"
25
30
  testCompile "junit:junit:4.+"
31
+ testCompile "org.embulk:embulk-standards:0.8.6"
32
+ testCompile "org.embulk:embulk-core:0.8.6:tests"
26
33
  }
27
34
 
28
35
  compileScala {
@@ -48,6 +55,23 @@ task classpath(type: Copy, dependsOn: ["jar"]) {
48
55
  }
49
56
  clean { delete 'classpath' }
50
57
 
58
+ checkstyle {
59
+ configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
60
+ toolVersion = '6.14.1'
61
+ }
62
+ checkstyleMain {
63
+ configFile = file("${project.rootDir}/config/checkstyle/default.xml")
64
+ ignoreFailures = true
65
+ }
66
+ checkstyleTest {
67
+ configFile = file("${project.rootDir}/config/checkstyle/default.xml")
68
+ ignoreFailures = true
69
+ }
70
+ task checkstyle(type: Checkstyle) {
71
+ classpath = sourceSets.main.output + sourceSets.test.output
72
+ source = sourceSets.main.allJava + sourceSets.test.allJava
73
+ }
74
+
51
75
  task gem(type: JRubyExec, dependsOn: ["build", "gemspec", "classpath"]) {
52
76
  jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
53
77
  script "build/gemspec"
data/circle.yml ADDED
@@ -0,0 +1,8 @@
1
+ general:
2
+ artifacts:
3
+ - "~/embulk-input-dynamodb/build/reports/tests"
4
+
5
+ test:
6
+ post:
7
+ - mkdir -p $CIRCLE_TEST_REPORTS/junit/
8
+ - find . -type f -regex ".*/test-results/*/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
@@ -0,0 +1,128 @@
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
+ <module name="Checker">
6
+ <!-- https://github.com/facebook/presto/blob/master/src/checkstyle/checks.xml -->
7
+ <module name="FileTabCharacter"/>
8
+ <module name="NewlineAtEndOfFile">
9
+ <property name="lineSeparator" value="lf"/>
10
+ </module>
11
+ <module name="RegexpMultiline">
12
+ <property name="format" value="\r"/>
13
+ <property name="message" value="Line contains carriage return"/>
14
+ </module>
15
+ <module name="RegexpMultiline">
16
+ <property name="format" value=" \n"/>
17
+ <property name="message" value="Line has trailing whitespace"/>
18
+ </module>
19
+ <module name="RegexpMultiline">
20
+ <property name="format" value="\{\n\n"/>
21
+ <property name="message" value="Blank line after opening brace"/>
22
+ </module>
23
+ <module name="RegexpMultiline">
24
+ <property name="format" value="\n\n\s*\}"/>
25
+ <property name="message" value="Blank line before closing brace"/>
26
+ </module>
27
+ <module name="RegexpMultiline">
28
+ <property name="format" value="\n\n\n"/>
29
+ <property name="message" value="Multiple consecutive blank lines"/>
30
+ </module>
31
+ <module name="RegexpMultiline">
32
+ <property name="format" value="\n\n\Z"/>
33
+ <property name="message" value="Blank line before end of file"/>
34
+ </module>
35
+ <module name="RegexpMultiline">
36
+ <property name="format" value="Preconditions\.checkNotNull"/>
37
+ <property name="message" value="Use of checkNotNull"/>
38
+ </module>
39
+
40
+ <module name="TreeWalker">
41
+ <module name="EmptyBlock">
42
+ <property name="option" value="text"/>
43
+ <property name="tokens" value="
44
+ LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
45
+ LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
46
+ </module>
47
+ <module name="EmptyStatement"/>
48
+ <module name="EmptyForInitializerPad"/>
49
+ <module name="EmptyForIteratorPad">
50
+ <property name="option" value="space"/>
51
+ </module>
52
+ <module name="MethodParamPad">
53
+ <property name="allowLineBreaks" value="true"/>
54
+ <property name="option" value="nospace"/>
55
+ </module>
56
+ <module name="ParenPad"/>
57
+ <module name="TypecastParenPad"/>
58
+ <module name="NeedBraces"/>
59
+ <module name="LeftCurly">
60
+ <property name="option" value="nl"/>
61
+ <property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
62
+ </module>
63
+ <module name="LeftCurly">
64
+ <property name="option" value="eol"/>
65
+ <property name="tokens" value="
66
+ LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
67
+ LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
68
+ </module>
69
+ <module name="RightCurly">
70
+ <property name="option" value="alone"/>
71
+ </module>
72
+ <module name="GenericWhitespace"/>
73
+ <module name="WhitespaceAfter"/>
74
+ <module name="NoWhitespaceBefore"/>
75
+
76
+ <module name="UpperEll"/>
77
+ <module name="DefaultComesLast"/>
78
+ <module name="ArrayTypeStyle"/>
79
+ <module name="MultipleVariableDeclarations"/>
80
+ <module name="ModifierOrder"/>
81
+ <module name="OneStatementPerLine"/>
82
+ <module name="StringLiteralEquality"/>
83
+ <module name="MutableException"/>
84
+ <module name="EqualsHashCode"/>
85
+ <module name="InnerAssignment"/>
86
+ <module name="InterfaceIsType"/>
87
+ <module name="HideUtilityClassConstructor"/>
88
+
89
+ <module name="MemberName"/>
90
+ <module name="LocalVariableName"/>
91
+ <module name="LocalFinalVariableName"/>
92
+ <module name="TypeName"/>
93
+ <module name="PackageName"/>
94
+ <module name="ParameterName"/>
95
+ <module name="StaticVariableName"/>
96
+ <module name="ClassTypeParameterName">
97
+ <property name="format" value="^[A-Z][0-9]?$"/>
98
+ </module>
99
+ <module name="MethodTypeParameterName">
100
+ <property name="format" value="^[A-Z][0-9]?$"/>
101
+ </module>
102
+
103
+ <module name="AvoidStarImport"/>
104
+ <module name="RedundantImport"/>
105
+ <module name="UnusedImports"/>
106
+ <module name="ImportOrder">
107
+ <property name="groups" value="*,javax,java"/>
108
+ <property name="separated" value="true"/>
109
+ <property name="option" value="bottom"/>
110
+ <property name="sortStaticImportsAlphabetically" value="true"/>
111
+ </module>
112
+
113
+ <module name="WhitespaceAround">
114
+ <property name="allowEmptyConstructors" value="true"/>
115
+ <property name="allowEmptyMethods" value="true"/>
116
+ <property name="ignoreEnhancedForColon" value="false"/>
117
+ <property name="tokens" value="
118
+ ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
119
+ BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
120
+ LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
121
+ LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
122
+ LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
123
+ LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
124
+ PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
125
+ STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
126
+ </module>
127
+ </module>
128
+ </module>
@@ -0,0 +1,108 @@
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
+ <module name="ClassTypeParameterName">
87
+ <property name="format" value="^[A-Z][0-9]?$"/>
88
+ </module>
89
+ <module name="MethodTypeParameterName">
90
+ <property name="format" value="^[A-Z][0-9]?$"/>
91
+ </module>
92
+
93
+ <module name="WhitespaceAround">
94
+ <property name="allowEmptyConstructors" value="true"/>
95
+ <property name="allowEmptyMethods" value="true"/>
96
+ <property name="ignoreEnhancedForColon" value="false"/>
97
+ <property name="tokens" value="
98
+ ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
99
+ BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
100
+ LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
101
+ LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
102
+ LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
103
+ LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
104
+ PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
105
+ STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
106
+ </module>
107
+ </module>
108
+ </module>
Binary file
@@ -1,6 +1,6 @@
1
- #Mon Mar 09 00:45:24 JST 2015
1
+ #Wed Jan 13 12:41:02 JST 2016
2
2
  distributionBase=GRADLE_USER_HOME
3
3
  distributionPath=wrapper/dists
4
4
  zipStoreBase=GRADLE_USER_HOME
5
5
  zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip
@@ -1,3 +1,3 @@
1
1
  Embulk::JavaPlugin.register_input(
2
- "dynamodb", "org.embulk.input.DynamodbInputPlugin",
2
+ "dynamodb", "org.embulk.input.dynamodb.DynamodbInputPlugin",
3
3
  File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,41 @@
1
+ package org.embulk.input.dynamodb
2
+
3
+ import com.amazonaws.services.dynamodbv2.model.AttributeValue
4
+ import org.msgpack.value.{Value, ValueFactory}
5
+
6
+ import scala.util.Try
7
+
8
+ object AttributeValueHelper {
9
+
10
+ // referring aws-scala
11
+ def decodeToValue(value: AttributeValue): Value = {
12
+ import scala.collection.JavaConverters._
13
+
14
+ // FIXME: Need Encode?
15
+ lazy val _bin = Option(value.getB).map(v => ValueFactory.newBinary(v.array))
16
+ lazy val _bool = Option(value.getBOOL).map(v => ValueFactory.newBoolean(v))
17
+ lazy val _num = Option(value.getN).map(v =>
18
+ Try(v.toLong).map(ValueFactory.newInteger).getOrElse(ValueFactory.newFloat(v.toDouble)))
19
+ lazy val _str = Option(value.getS).map(v => ValueFactory.newString(v))
20
+ lazy val _nil = Option(value.getNULL).map(v => ValueFactory.newNil)
21
+
22
+ lazy val _list = Option(value.getL).map(l =>
23
+ ValueFactory.newArray(l.asScala.map(v => decodeToValue(v)).asJava))
24
+ lazy val _ss = Option(value.getSS).map(l =>
25
+ ValueFactory.newArray(l.asScala.map(v => ValueFactory.newString(v)).asJava))
26
+ lazy val _ns = Option(value.getNS).map(l =>
27
+ ValueFactory.newArray(l.asScala.map(v =>
28
+ Try(v.toLong).map(ValueFactory.newInteger).getOrElse(ValueFactory.newFloat(v.toDouble))).asJava))
29
+ // FIXME: Need Encode?
30
+ lazy val _bs = Option(value.getBS).map(l =>
31
+ ValueFactory.newArray(l.asScala.map(v => ValueFactory.newBinary(v.array)).asJava))
32
+ lazy val _map = Option(value.getM).map(m =>
33
+ ValueFactory.newMap(m.asScala.map(v => ValueFactory.newString(v._1) -> decodeToValue(v._2)).asJava))
34
+
35
+ _bin.orElse(_bool).orElse(_num).orElse(_str).orElse(_nil)
36
+ .orElse(_list).orElse(_ss).orElse(_ns).orElse(_bs).orElse(_map) match {
37
+ case None => ValueFactory.newNil
38
+ case Some(j) => j
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,71 @@
1
+ package org.embulk.input.dynamodb
2
+
3
+ import com.amazonaws.auth._
4
+ import com.amazonaws.auth.profile.ProfileCredentialsProvider
5
+ import com.google.common.base.Optional
6
+ import org.embulk.config.ConfigException
7
+
8
+ object AwsCredentials {
9
+ def getCredentialsProvider(task: PluginTask): AWSCredentialsProvider = {
10
+ if (!task.getAuthMethod.isPresent) {
11
+ // backward compatibility
12
+ if (task.getAccessKey.isPresent && task.getSecretKey.isPresent) {
13
+ new AWSCredentialsProvider {
14
+ override def refresh(): Unit = {}
15
+
16
+ override def getCredentials: AWSCredentials = {
17
+ new BasicAWSCredentials(
18
+ task.getAccessKey.get(),
19
+ task.getSecretKey.get())
20
+ }
21
+ }
22
+ } else {
23
+ new ProfileCredentialsProvider()
24
+ }
25
+ } else {
26
+ val cred = task.getAuthMethod.get() match {
27
+ case "basic" =>
28
+ val accessKey = require(task.getAccessKey, "'access_key'")
29
+ val secretKey = require(task.getSecretKey, "'secret_key'")
30
+
31
+ new BasicAWSCredentials(accessKey, secretKey)
32
+
33
+ case "env" =>
34
+ new EnvironmentVariableCredentialsProvider().getCredentials
35
+
36
+ case "instance" =>
37
+ new InstanceProfileCredentialsProvider().getCredentials
38
+
39
+ case "profile" =>
40
+ val profileName = task.getProfileName.or("default")
41
+
42
+ try {
43
+ new ProfileCredentialsProvider(profileName).getCredentials
44
+ } catch {
45
+ case e: IllegalArgumentException =>
46
+ throw new ConfigException(s"No AWS profile named $profileName")
47
+ }
48
+
49
+ case "properties" =>
50
+ new SystemPropertiesCredentialsProvider().getCredentials
51
+
52
+ case _ =>
53
+ throw new ConfigException(s"Unknown 'auth_method' ${task.getAuthMethod.get()}")
54
+ }
55
+
56
+ new AWSCredentialsProvider {
57
+ override def refresh(): Unit = {}
58
+
59
+ override def getCredentials: AWSCredentials = { cred }
60
+ }
61
+ }
62
+ }
63
+
64
+ private def require[A](value: Optional[A], message: String): A = {
65
+ if (value.isPresent) {
66
+ value.get()
67
+ } else {
68
+ throw new ConfigException("Required option is not set: " + message)
69
+ }
70
+ }
71
+ }