@@ -6,11 +6,12 @@ import com.amazonaws.auth.AWSCredentialsProvider
6
6
import com.amazonaws.auth.AWSStaticCredentialsProvider
7
7
import com.amazonaws.auth.BasicAWSCredentials
8
8
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
9
- import com.amazonaws.client.builder.AwsClientBuilder
10
9
import com.amazonaws.client.builder.AwsSyncClientBuilder
10
+ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
11
11
import com.amazonaws.regions.Region
12
12
import com.amazonaws.regions.RegionUtils
13
13
14
+ @SuppressWarnings ([' FactoryMethodName' ])
14
15
class AwsClientUtil {
15
16
16
17
static final String DEFAULT_REGION = ' us-east-1'
@@ -19,7 +20,7 @@ class AwsClientUtil {
19
20
Region region = buildRegion(config, serviceConfig)
20
21
assert region. isServiceSupported(serviceName)
21
22
22
- AwsClientBuilder. EndpointConfiguration endpointConfiguration = buildEndpointConfiguration(config, serviceConfig)
23
+ EndpointConfiguration endpointConfiguration = buildEndpointConfiguration(config, serviceConfig)
23
24
24
25
if (endpointConfiguration) {
25
26
builder. withEndpointConfiguration(endpointConfiguration)
@@ -38,6 +39,7 @@ class AwsClientUtil {
38
39
* @param serviceConfig
39
40
* @return
40
41
*/
42
+ @SuppressWarnings ([' CyclomaticComplexity' , ' AbcMetric' , ' MethodSize' ])
41
43
static ClientConfiguration buildClientConfiguration (defaultConfig , serviceConfig ) {
42
44
Map config = [
43
45
connectionTimeout : defaultConfig. connectionTimeout ?: 0 ,
@@ -54,36 +56,85 @@ class AwsClientUtil {
54
56
proxyWorkstation : defaultConfig. proxyWorkstation ?: ' '
55
57
]
56
58
if (serviceConfig) {
57
- if (serviceConfig. connectionTimeout) config. connectionTimeout = serviceConfig. connectionTimeout
58
- if (serviceConfig. maxConnections) config. maxConnections = serviceConfig. maxConnections
59
- if (serviceConfig. maxErrorRetry) config. maxErrorRetry = serviceConfig. maxErrorRetry
60
- if (serviceConfig. protocol) config. protocol = serviceConfig. protocol
61
- if (serviceConfig. socketTimeout) config. socketTimeout = serviceConfig. socketTimeout
62
- if (serviceConfig. userAgent) config. userAgent = serviceConfig. userAgent
63
- if (serviceConfig. proxyDomain) config. proxyDomain = serviceConfig. proxyDomain
64
- if (serviceConfig. proxyHost) config. proxyHost = serviceConfig. proxyHost
65
- if (serviceConfig. proxyPassword) config. proxyPassword = serviceConfig. proxyPassword
66
- if (serviceConfig. proxyPort) config. proxyPort = serviceConfig. proxyPort
67
- if (serviceConfig. proxyUsername) config. proxyUsername = serviceConfig. proxyUsername
68
- if (serviceConfig. proxyWorkstation) config. proxyWorkstation = serviceConfig. proxyWorkstation
59
+ if (serviceConfig. connectionTimeout) {
60
+ config. connectionTimeout = serviceConfig. connectionTimeout
61
+ }
62
+ if (serviceConfig. maxConnections) {
63
+ config. maxConnections = serviceConfig. maxConnections
64
+ }
65
+ if (serviceConfig. maxErrorRetry) {
66
+ config. maxErrorRetry = serviceConfig. maxErrorRetry
67
+ }
68
+ if (serviceConfig. protocol) {
69
+ config. protocol = serviceConfig. protocol
70
+ }
71
+ if (serviceConfig. socketTimeout) {
72
+ config. socketTimeout = serviceConfig. socketTimeout
73
+ }
74
+ if (serviceConfig. userAgent) {
75
+ config. userAgent = serviceConfig. userAgent
76
+ }
77
+ if (serviceConfig. proxyDomain) {
78
+ config. proxyDomain = serviceConfig. proxyDomain
79
+ }
80
+ if (serviceConfig. proxyHost) {
81
+ config. proxyHost = serviceConfig. proxyHost
82
+ }
83
+ if (serviceConfig. proxyPassword) {
84
+ config. proxyPassword = serviceConfig. proxyPassword
85
+ }
86
+ if (serviceConfig. proxyPort) {
87
+ config. proxyPort = serviceConfig. proxyPort
88
+ }
89
+ if (serviceConfig. proxyUsername) {
90
+ config. proxyUsername = serviceConfig. proxyUsername
91
+ }
92
+ if (serviceConfig. proxyWorkstation) {
93
+ config. proxyWorkstation = serviceConfig. proxyWorkstation
94
+ }
69
95
}
70
96
71
97
ClientConfiguration clientConfiguration = new ClientConfiguration ()
72
- if (config. connectionTimeout) clientConfiguration. connectionTimeout = config. connectionTimeout
73
- if (config. maxConnections) clientConfiguration. maxConnections = config. maxConnections
74
- if (config. maxErrorRetry) clientConfiguration. maxErrorRetry = config. maxErrorRetry
98
+ if (config. connectionTimeout) {
99
+ clientConfiguration. connectionTimeout = config. connectionTimeout
100
+ }
101
+ if (config. maxConnections) {
102
+ clientConfiguration. maxConnections = config. maxConnections
103
+ }
104
+ if (config. maxErrorRetry) {
105
+ clientConfiguration. maxErrorRetry = config. maxErrorRetry
106
+ }
75
107
if (config. protocol) {
76
- if (config. protocol. toUpperCase() == ' HTTP' ) clientConfiguration. protocol = Protocol . HTTP
77
- else clientConfiguration. protocol = Protocol . HTTPS
78
- }
79
- if (config. socketTimeout) clientConfiguration. socketTimeout = config. socketTimeout
80
- if (config. userAgent) clientConfiguration. userAgent = config. userAgent
81
- if (config. proxyDomain) clientConfiguration. proxyDomain = config. proxyDomain
82
- if (config. proxyHost) clientConfiguration. proxyHost = config. proxyHost
83
- if (config. proxyPassword) clientConfiguration. proxyPassword = config. proxyPassword
84
- if (config. proxyPort) clientConfiguration. proxyPort = config. proxyPort
85
- if (config. proxyUsername) clientConfiguration. proxyUsername = config. proxyUsername
86
- if (config. proxyWorkstation) clientConfiguration. proxyWorkstation = config. proxyWorkstation
108
+ if (config. protocol. toUpperCase() == ' HTTP' ) {
109
+ clientConfiguration. protocol = Protocol . HTTP
110
+ } else {
111
+ clientConfiguration. protocol = Protocol . HTTPS
112
+ }
113
+ }
114
+ if (config. socketTimeout) {
115
+ clientConfiguration. socketTimeout = config. socketTimeout
116
+ }
117
+ if (config. userAgent) {
118
+ clientConfiguration. userAgent = config. userAgent
119
+ }
120
+ if (config. proxyDomain) {
121
+ clientConfiguration. proxyDomain = config. proxyDomain
122
+ }
123
+ if (config. proxyHost) {
124
+ clientConfiguration. proxyHost = config. proxyHost
125
+ }
126
+ if (config. proxyPassword) {
127
+ clientConfiguration. proxyPassword = config. proxyPassword
128
+ }
129
+ if (config. proxyPort) {
130
+ clientConfiguration. proxyPort = config. proxyPort
131
+ }
132
+ if (config. proxyUsername) {
133
+ clientConfiguration. proxyUsername = config. proxyUsername
134
+ }
135
+ if (config. proxyWorkstation) {
136
+ clientConfiguration. proxyWorkstation = config. proxyWorkstation
137
+ }
87
138
clientConfiguration
88
139
}
89
140
@@ -99,8 +150,12 @@ class AwsClientUtil {
99
150
secretKey : defaultConfig. secretKey ?: ' '
100
151
]
101
152
if (serviceConfig) {
102
- if (serviceConfig. accessKey) config. accessKey = serviceConfig. accessKey
103
- if (serviceConfig. secretKey) config. secretKey = serviceConfig. secretKey
153
+ if (serviceConfig. accessKey) {
154
+ config. accessKey = serviceConfig. accessKey
155
+ }
156
+ if (serviceConfig. secretKey) {
157
+ config. secretKey = serviceConfig. secretKey
158
+ }
104
159
}
105
160
106
161
if (! config. accessKey || ! config. secretKey) {
@@ -115,6 +170,7 @@ class AwsClientUtil {
115
170
* @param defaultConfig
116
171
* @param serviceConfig
117
172
*/
173
+ @SuppressWarnings ([' ElseBlockBraces' ])
118
174
static buildRegion (defaultConfig , serviceConfig ) {
119
175
String regionName = DEFAULT_REGION
120
176
if (serviceConfig?. region) {
@@ -125,15 +181,15 @@ class AwsClientUtil {
125
181
RegionUtils . getRegion(regionName)
126
182
}
127
183
128
- static AwsClientBuilder.EndpointConfiguration buildEndpointConfiguration (defaultConfig , serviceConfig ) {
184
+ @SuppressWarnings ([' ElseBlockBraces' ])
185
+ static EndpointConfiguration buildEndpointConfiguration (defaultConfig , serviceConfig ) {
129
186
Region region = buildRegion(defaultConfig, serviceConfig)
130
187
if (serviceConfig?. endpoint) {
131
- return new AwsClientBuilder. EndpointConfiguration (serviceConfig. endpoint as String , region. name)
188
+ return new EndpointConfiguration (serviceConfig. endpoint as String , region. name)
132
189
} else if (defaultConfig?. endpoint) {
133
- return new AwsClientBuilder. EndpointConfiguration (defaultConfig. endpoint as String , region. name)
190
+ return new EndpointConfiguration (defaultConfig. endpoint as String , region. name)
134
191
}
135
- return null
192
+ null
136
193
}
137
194
138
-
139
195
}
0 commit comments