File tree Expand file tree Collapse file tree 2 files changed +29
-17
lines changed Expand file tree Collapse file tree 2 files changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -11,16 +11,30 @@ import (
11
11
var DynamoDB * dynamodb.DynamoDB
12
12
13
13
// GetDynamoSession returns a new dynamodb session
14
- func GetDynamoSession (accessKeyID , secretAccessKey , region string ) * dynamodb.DynamoDB {
15
- token := ""
16
- creds := credentials .NewStaticCredentials (accessKeyID , secretAccessKey , token )
17
- _ , err := creds .Get ()
18
- if err != nil {
19
- panic (err )
14
+ func GetDynamoSession (accessKeyID , secretAccessKey , region string ) (* dynamodb.DynamoDB , error ) {
15
+ sessionConfig := session.Options {}
16
+ if accessKeyID != "" || secretAccessKey != "" {
17
+ token := ""
18
+ creds := credentials .NewStaticCredentials (accessKeyID , secretAccessKey , token )
19
+ _ , err := creds .Get ()
20
+ if err != nil {
21
+ return nil , err
22
+ }
23
+ sessionConfig .Config .Credentials = creds
20
24
}
21
25
22
- DynamoDB = dynamodb .New (session .New (& aws.Config {Region : & region }))
23
- return DynamoDB
26
+ if region != "" {
27
+ sessionConfig .Config .Region = & region
28
+ } else {
29
+ sessionConfig .SharedConfigState = session .SharedConfigEnable
30
+ }
31
+
32
+ session , err := session .NewSessionWithOptions (sessionConfig )
33
+ if err != nil {
34
+ return nil , err
35
+ }
36
+ DynamoDB = dynamodb .New (session )
37
+ return DynamoDB , nil
24
38
}
25
39
26
40
// ListTable returns all table names from dynamoDB
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"os"
6
7
"os/signal"
@@ -214,17 +215,14 @@ func main() {
214
215
},
215
216
},
216
217
Action : func (c * cli.Context ) error {
217
- if region == "" {
218
- fmt .Println ("Must provide aws config region" )
219
- } else if accessKeyID == "" {
220
- fmt .Println ("Must provide aws config access key id" )
221
- } else if secretAccessKey == "" {
222
- fmt .Println ("Must provide aws config secret access key" )
223
- } else {
224
- db .GetDynamoSession (accessKeyID , secretAccessKey , region )
218
+ if ! ((accessKeyID == "" && secretAccessKey == "" ) || (accessKeyID != "" && secretAccessKey != "" )) {
219
+ return errors .New ("Must provide access key id and secret access key at the same time" )
220
+ } else if _ , err := db .GetDynamoSession (accessKeyID , secretAccessKey , region ); err == nil {
225
221
runPrompt (tablePrefix )
222
+ return nil
223
+ } else {
224
+ return err
226
225
}
227
- return nil
228
226
},
229
227
}
230
228
You can’t perform that action at this time.
0 commit comments