|
14 | 14 | */ |
15 | 15 | package org.jnosql.diana.dynamodb; |
16 | 16 |
|
17 | | -import java.net.URI; |
18 | | - |
19 | 17 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
20 | 18 | import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; |
21 | 19 | import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; |
|
24 | 22 | import software.amazon.awssdk.services.dynamodb.DynamoDbClient; |
25 | 23 | import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder; |
26 | 24 |
|
27 | | -public class DynamoDBBuilderSync implements DynamoDBBuilder{ |
28 | | - |
29 | | - |
30 | | - private final DynamoDbClientBuilder dynamoDB = DynamoDbClient.builder(); |
31 | | - |
32 | | - private String awsAccessKey; |
33 | | - private String awsSecretAccess; |
34 | | - |
35 | | - |
36 | | - @Override |
37 | | - public void endpoint(String endpoint) { |
38 | | - dynamoDB.endpointOverride(URI.create(endpoint)); |
39 | | - } |
40 | | - |
41 | | - @Override |
42 | | - public void region(String region) { |
43 | | - dynamoDB.region(Region.of(region)); |
44 | | - } |
45 | | - |
46 | | - @Override |
47 | | - public void profile(String profile) { |
48 | | - dynamoDB.credentialsProvider(ProfileCredentialsProvider.builder() |
| 25 | +import java.net.URI; |
| 26 | + |
| 27 | +public class DynamoDBBuilderSync implements DynamoDBBuilder { |
| 28 | + |
| 29 | + |
| 30 | + private final DynamoDbClientBuilder dynamoDB = DynamoDbClient.builder(); |
| 31 | + |
| 32 | + private String awsAccessKey; |
| 33 | + private String awsSecretAccess; |
| 34 | + |
| 35 | + |
| 36 | + @Override |
| 37 | + public void endpoint(String endpoint) { |
| 38 | + dynamoDB.endpointOverride(URI.create(endpoint)); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void region(String region) { |
| 43 | + dynamoDB.region(Region.of(region)); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void profile(String profile) { |
| 48 | + dynamoDB.credentialsProvider(ProfileCredentialsProvider.builder() |
49 | 49 | .profileName(profile) |
50 | 50 | .build()); |
51 | | - |
52 | | - } |
53 | | - |
54 | | - public DynamoDbClient build() { |
55 | | - |
56 | | - boolean accessKey = awsAccessKey != null && !awsAccessKey.equals(""); |
57 | | - boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals(""); |
58 | | - |
59 | | - |
60 | | - if(accessKey && secretAccess){ |
61 | | - |
62 | | - AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(awsAccessKey,awsSecretAccess); |
63 | | - AwsCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials); |
64 | | - dynamoDB.credentialsProvider(staticCredentialsProvider); |
65 | | - } |
66 | | - |
67 | | - return dynamoDB.build(); |
68 | | - } |
69 | | - |
70 | | - @Override |
71 | | - public void awsAccessKey(String awsAccessKey) { |
72 | | - this.awsAccessKey = awsAccessKey; |
73 | | - } |
74 | | - |
75 | | - @Override |
76 | | - public void awsSecretAccess(String awsSecretAccess) { |
77 | | - this.awsSecretAccess = awsSecretAccess; |
78 | | - } |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + public DynamoDbClient build() { |
| 55 | + |
| 56 | + boolean accessKey = awsAccessKey != null && !awsAccessKey.equals(""); |
| 57 | + boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals(""); |
| 58 | + |
| 59 | + |
| 60 | + if (accessKey && secretAccess) { |
| 61 | + |
| 62 | + AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(awsAccessKey, awsSecretAccess); |
| 63 | + AwsCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials); |
| 64 | + dynamoDB.credentialsProvider(staticCredentialsProvider); |
| 65 | + } |
| 66 | + |
| 67 | + return dynamoDB.build(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void awsAccessKey(String awsAccessKey) { |
| 72 | + this.awsAccessKey = awsAccessKey; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void awsSecretAccess(String awsSecretAccess) { |
| 77 | + this.awsSecretAccess = awsSecretAccess; |
| 78 | + } |
79 | 79 | } |
0 commit comments