@@ -83,24 +83,44 @@ public AwsSettings(string accessKey, string secretKey, AwsRegion region, string
83
83
/// <summary>
84
84
/// Initialize the object.
85
85
/// </summary>
86
- /// <param name="hostname">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
87
- /// <param name="ssl">Enable or disable SSL.</param>
88
86
/// <param name="accessKey">Access key with which to access AWS S3.</param>
89
87
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
90
88
/// <param name="region">AWS region.</param>
91
89
/// <param name="bucket">Bucket in which to store BLOBs.</param>
92
- public AwsSettings ( string hostname , bool ssl , string accessKey , string secretKey , AwsRegion region , string bucket )
90
+ public AwsSettings ( string accessKey , string secretKey , string region , string bucket )
93
91
{
94
- if ( String . IsNullOrEmpty ( hostname ) ) throw new ArgumentNullException ( nameof ( hostname ) ) ;
95
92
if ( String . IsNullOrEmpty ( accessKey ) ) throw new ArgumentNullException ( nameof ( accessKey ) ) ;
96
93
if ( String . IsNullOrEmpty ( secretKey ) ) throw new ArgumentNullException ( nameof ( secretKey ) ) ;
94
+ if ( String . IsNullOrEmpty ( region ) ) throw new ArgumentNullException ( nameof ( region ) ) ;
97
95
if ( String . IsNullOrEmpty ( bucket ) ) throw new ArgumentNullException ( nameof ( bucket ) ) ;
98
- Hostname = hostname ;
99
- Ssl = ssl ;
96
+ AccessKey = accessKey ;
97
+ SecretKey = secretKey ;
98
+ Bucket = bucket ;
99
+
100
+ if ( ! ValidateRegion ( region ) ) throw new ArgumentException ( "Unable to validate region: " + region ) ;
101
+ Region = GetRegionFromString ( region ) ;
102
+ }
103
+
104
+ /// <summary>
105
+ /// Initialize the object.
106
+ /// </summary>
107
+ /// <param name="accessKey">Access key with which to access AWS S3.</param>
108
+ /// <param name="secretKey">Secret key with which to access AWS S3.</param>
109
+ /// <param name="region">AWS region.</param>
110
+ /// <param name="bucket">Bucket in which to store BLOBs.</param>
111
+ /// <param name="ssl">Enable or disable SSL.</param>
112
+ public AwsSettings ( string accessKey , string secretKey , AwsRegion region , string bucket , bool ssl )
113
+ {
114
+ if ( String . IsNullOrEmpty ( accessKey ) ) throw new ArgumentNullException ( nameof ( accessKey ) ) ;
115
+ if ( String . IsNullOrEmpty ( secretKey ) ) throw new ArgumentNullException ( nameof ( secretKey ) ) ;
116
+ if ( String . IsNullOrEmpty ( bucket ) ) throw new ArgumentNullException ( nameof ( bucket ) ) ;
117
+ Hostname = null ;
118
+ Ssl = true ;
100
119
AccessKey = accessKey ;
101
120
SecretKey = secretKey ;
102
121
Region = region ;
103
122
Bucket = bucket ;
123
+ Ssl = ssl ;
104
124
}
105
125
106
126
/// <summary>
@@ -110,75 +130,19 @@ public AwsSettings(string hostname, bool ssl, string accessKey, string secretKey
110
130
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
111
131
/// <param name="region">AWS region.</param>
112
132
/// <param name="bucket">Bucket in which to store BLOBs.</param>
113
- public AwsSettings ( string accessKey , string secretKey , string region , string bucket )
133
+ public AwsSettings ( string accessKey , string secretKey , string region , string bucket , bool ssl )
114
134
{
115
135
if ( String . IsNullOrEmpty ( accessKey ) ) throw new ArgumentNullException ( nameof ( accessKey ) ) ;
116
136
if ( String . IsNullOrEmpty ( secretKey ) ) throw new ArgumentNullException ( nameof ( secretKey ) ) ;
117
137
if ( String . IsNullOrEmpty ( region ) ) throw new ArgumentNullException ( nameof ( region ) ) ;
118
138
if ( String . IsNullOrEmpty ( bucket ) ) throw new ArgumentNullException ( nameof ( bucket ) ) ;
119
139
AccessKey = accessKey ;
120
- SecretKey = secretKey ;
140
+ SecretKey = secretKey ;
121
141
Bucket = bucket ;
142
+ Ssl = ssl ;
122
143
123
144
if ( ! ValidateRegion ( region ) ) throw new ArgumentException ( "Unable to validate region: " + region ) ;
124
-
125
- switch ( region )
126
- {
127
- case "APNortheast1" :
128
- Region = AwsRegion . APNortheast1 ;
129
- break ;
130
- case "APSouth1" :
131
- Region = AwsRegion . APSouth1 ;
132
- break ;
133
- case "APSoutheast1" :
134
- Region = AwsRegion . APSoutheast1 ;
135
- break ;
136
- case "APSoutheast2" :
137
- Region = AwsRegion . APSoutheast2 ;
138
- break ;
139
- case "CACentral1" :
140
- Region = AwsRegion . CACentral1 ;
141
- break ;
142
- case "CNNorth1" :
143
- Region = AwsRegion . CNNorth1 ;
144
- break ;
145
- case "EUCentral1" :
146
- Region = AwsRegion . EUCentral1 ;
147
- break ;
148
- case "EUNorth1" :
149
- Region = AwsRegion . EUNorth1 ;
150
- break ;
151
- case "EUWest1" :
152
- Region = AwsRegion . EUWest1 ;
153
- break ;
154
- case "EUWest2" :
155
- Region = AwsRegion . EUWest2 ;
156
- break ;
157
- case "EUWest3" :
158
- Region = AwsRegion . EUWest3 ;
159
- break ;
160
- case "SAEast1" :
161
- Region = AwsRegion . SAEast1 ;
162
- break ;
163
- case "USEast1" :
164
- Region = AwsRegion . USEast1 ;
165
- break ;
166
- case "USEast2" :
167
- Region = AwsRegion . USEast2 ;
168
- break ;
169
- case "USGovCloudEast1" :
170
- Region = AwsRegion . USGovCloudEast1 ;
171
- break ;
172
- case "USGovCloudWest1" :
173
- Region = AwsRegion . USGovCloudWest1 ;
174
- break ;
175
- case "USWest1" :
176
- Region = AwsRegion . USWest1 ;
177
- break ;
178
- case "USWest2" :
179
- Region = AwsRegion . USWest2 ;
180
- break ;
181
- }
145
+ Region = GetRegionFromString ( region ) ;
182
146
}
183
147
184
148
/// <summary>
@@ -190,78 +154,18 @@ public AwsSettings(string accessKey, string secretKey, string region, string buc
190
154
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
191
155
/// <param name="region">AWS region.</param>
192
156
/// <param name="bucket">Bucket in which to store BLOBs.</param>
193
- public AwsSettings ( string hostname , bool ssl , string accessKey , string secretKey , string region , string bucket )
157
+ public AwsSettings ( string hostname , bool ssl , string accessKey , string secretKey , AwsRegion region , string bucket )
194
158
{
195
159
if ( String . IsNullOrEmpty ( hostname ) ) throw new ArgumentNullException ( nameof ( hostname ) ) ;
196
160
if ( String . IsNullOrEmpty ( accessKey ) ) throw new ArgumentNullException ( nameof ( accessKey ) ) ;
197
161
if ( String . IsNullOrEmpty ( secretKey ) ) throw new ArgumentNullException ( nameof ( secretKey ) ) ;
198
- if ( String . IsNullOrEmpty ( region ) ) throw new ArgumentNullException ( nameof ( region ) ) ;
199
162
if ( String . IsNullOrEmpty ( bucket ) ) throw new ArgumentNullException ( nameof ( bucket ) ) ;
200
163
Hostname = hostname ;
201
164
Ssl = ssl ;
202
165
AccessKey = accessKey ;
203
166
SecretKey = secretKey ;
167
+ Region = region ;
204
168
Bucket = bucket ;
205
-
206
- if ( ! ValidateRegion ( region ) ) throw new ArgumentException ( "Unable to validate region: " + region ) ;
207
-
208
- switch ( region )
209
- {
210
- case "APNortheast1" :
211
- Region = AwsRegion . APNortheast1 ;
212
- break ;
213
- case "APSouth1" :
214
- Region = AwsRegion . APSouth1 ;
215
- break ;
216
- case "APSoutheast1" :
217
- Region = AwsRegion . APSoutheast1 ;
218
- break ;
219
- case "APSoutheast2" :
220
- Region = AwsRegion . APSoutheast2 ;
221
- break ;
222
- case "CACentral1" :
223
- Region = AwsRegion . CACentral1 ;
224
- break ;
225
- case "CNNorth1" :
226
- Region = AwsRegion . CNNorth1 ;
227
- break ;
228
- case "EUCentral1" :
229
- Region = AwsRegion . EUCentral1 ;
230
- break ;
231
- case "EUNorth1" :
232
- Region = AwsRegion . EUNorth1 ;
233
- break ;
234
- case "EUWest1" :
235
- Region = AwsRegion . EUWest1 ;
236
- break ;
237
- case "EUWest2" :
238
- Region = AwsRegion . EUWest2 ;
239
- break ;
240
- case "EUWest3" :
241
- Region = AwsRegion . EUWest3 ;
242
- break ;
243
- case "SAEast1" :
244
- Region = AwsRegion . SAEast1 ;
245
- break ;
246
- case "USEast1" :
247
- Region = AwsRegion . USEast1 ;
248
- break ;
249
- case "USEast2" :
250
- Region = AwsRegion . USEast2 ;
251
- break ;
252
- case "USGovCloudEast1" :
253
- Region = AwsRegion . USGovCloudEast1 ;
254
- break ;
255
- case "USGovCloudWest1" :
256
- Region = AwsRegion . USGovCloudWest1 ;
257
- break ;
258
- case "USWest1" :
259
- Region = AwsRegion . USWest1 ;
260
- break ;
261
- case "USWest2" :
262
- Region = AwsRegion . USWest2 ;
263
- break ;
264
- }
265
169
}
266
170
267
171
#endregion
@@ -348,6 +252,51 @@ private List<String> ValidRegions()
348
252
return ret ;
349
253
}
350
254
255
+ private AwsRegion GetRegionFromString ( string region )
256
+ {
257
+ switch ( region )
258
+ {
259
+ case "APNortheast1" :
260
+ return AwsRegion . APNortheast1 ;
261
+ case "APSouth1" :
262
+ return AwsRegion . APSouth1 ;
263
+ case "APSoutheast1" :
264
+ return AwsRegion . APSoutheast1 ;
265
+ case "APSoutheast2" :
266
+ return AwsRegion . APSoutheast2 ;
267
+ case "CACentral1" :
268
+ return AwsRegion . CACentral1 ;
269
+ case "CNNorth1" :
270
+ return AwsRegion . CNNorth1 ;
271
+ case "EUCentral1" :
272
+ return AwsRegion . EUCentral1 ;
273
+ case "EUNorth1" :
274
+ return AwsRegion . EUNorth1 ;
275
+ case "EUWest1" :
276
+ return AwsRegion . EUWest1 ;
277
+ case "EUWest2" :
278
+ return AwsRegion . EUWest2 ;
279
+ case "EUWest3" :
280
+ return AwsRegion . EUWest3 ;
281
+ case "SAEast1" :
282
+ return AwsRegion . SAEast1 ;
283
+ case "USEast1" :
284
+ return AwsRegion . USEast1 ;
285
+ case "USEast2" :
286
+ return AwsRegion . USEast2 ;
287
+ case "USGovCloudEast1" :
288
+ return AwsRegion . USGovCloudEast1 ;
289
+ case "USGovCloudWest1" :
290
+ return AwsRegion . USGovCloudWest1 ;
291
+ case "USWest1" :
292
+ return AwsRegion . USWest1 ;
293
+ case "USWest2" :
294
+ return AwsRegion . USWest2 ;
295
+ default :
296
+ throw new ArgumentException ( "Unknown region: " + region ) ;
297
+ }
298
+ }
299
+
351
300
#endregion
352
301
}
353
302
}
0 commit comments