@@ -62,12 +62,20 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
62
62
63
63
private final ConfigServerProperties serverProperties ;
64
64
65
+ private final boolean useApplicationAsDirectory ;
66
+
65
67
protected int order = Ordered .LOWEST_PRECEDENCE ;
66
68
67
69
public AwsS3EnvironmentRepository (S3Client s3Client , String bucketName , ConfigServerProperties server ) {
70
+ this (s3Client , bucketName , false , server );
71
+ }
72
+
73
+ public AwsS3EnvironmentRepository (S3Client s3Client , String bucketName , boolean useApplicationAsDirectory ,
74
+ ConfigServerProperties server ) {
68
75
this .s3Client = s3Client ;
69
76
this .bucketName = bucketName ;
70
77
this .serverProperties = server ;
78
+ this .useApplicationAsDirectory = useApplicationAsDirectory ;
71
79
}
72
80
73
81
@ Override
@@ -213,7 +221,7 @@ private List<YamlS3ConfigFile> getNonProfileSpecificS3ConfigFileYaml(String appl
213
221
if (profile != null ) {
214
222
try {
215
223
YamlS3ConfigFile configFileDocument = new ProfileSpecificYamlDocumentS3ConfigFile (application , profile ,
216
- label , bucketName , s3Client );
224
+ label , bucketName , useApplicationAsDirectory , s3Client );
217
225
configFileDocument .setShouldIncludeWithEmptyProperties (false );
218
226
configFiles .add (configFileDocument );
219
227
}
@@ -226,7 +234,7 @@ private List<YamlS3ConfigFile> getNonProfileSpecificS3ConfigFileYaml(String appl
226
234
}
227
235
try {
228
236
YamlS3ConfigFile configFile = new NonProfileSpecificYamlDocumentS3ConfigFile (application , null , label ,
229
- bucketName , s3Client );
237
+ bucketName , useApplicationAsDirectory , s3Client );
230
238
configFiles .add (configFile );
231
239
}
232
240
catch (Exception e ) {
@@ -243,7 +251,7 @@ private List<YamlS3ConfigFile> getProfileSpecificS3ConfigFileYaml(String applica
243
251
String label ) {
244
252
try {
245
253
YamlS3ConfigFile configFile = new ProfileSpecificYamlS3ConfigFile (application , profile , label , bucketName ,
246
- s3Client );
254
+ useApplicationAsDirectory , s3Client );
247
255
return List .of (configFile );
248
256
}
249
257
catch (Exception e ) {
@@ -262,15 +270,17 @@ private S3ConfigFile getS3PropertiesOrJsonConfigFile(String application, String
262
270
LOG .debug ("Getting S3 config file for " + application + " " + profile + " " + label );
263
271
}
264
272
try {
265
- return new PropertyS3ConfigFile (application , profile , label , bucketName , s3Client );
273
+ return new PropertyS3ConfigFile (application , profile , label , bucketName , useApplicationAsDirectory ,
274
+ s3Client );
266
275
}
267
276
catch (Exception propertyException ) {
268
277
if (LOG .isDebugEnabled ()) {
269
278
LOG .debug ("Did not find properties file using application <" + application + "> profile <" + profile
270
279
+ "> label <" + label + ">. Trying json extension" , propertyException );
271
280
}
272
281
try {
273
- return new JsonS3ConfigFile (application , profile , label , bucketName , s3Client );
282
+ return new JsonS3ConfigFile (application , profile , label , bucketName , useApplicationAsDirectory ,
283
+ s3Client );
274
284
}
275
285
catch (Exception jsonException ) {
276
286
if (LOG .isDebugEnabled ()) {
@@ -330,12 +340,16 @@ abstract class S3ConfigFile {
330
340
331
341
private boolean shouldIncludeWithEmptyProperties = true ;
332
342
333
- protected S3ConfigFile (String application , String profile , String label , String bucketName , S3Client s3Client ) {
343
+ private final boolean useApplicationAsDirectory ;
344
+
345
+ protected S3ConfigFile (String application , String profile , String label , String bucketName ,
346
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
334
347
this .application = application ;
335
348
this .profile = profile ;
336
349
this .label = label ;
337
350
this .bucketName = bucketName ;
338
351
this .s3Client = s3Client ;
352
+ this .useApplicationAsDirectory = useApplicationAsDirectory ;
339
353
}
340
354
341
355
String getVersion () {
@@ -396,6 +410,9 @@ String buildObjectKeyPrefix(boolean includeProfile) {
396
410
objectKeyPrefix .append (label ).append (PATH_SEPARATOR );
397
411
}
398
412
objectKeyPrefix .append (application );
413
+ if (this .useApplicationAsDirectory ) {
414
+ objectKeyPrefix .append (PATH_SEPARATOR ).append ("application" );
415
+ }
399
416
if (!ObjectUtils .isEmpty (profile ) && includeProfile ) {
400
417
objectKeyPrefix .append ("-" ).append (profile );
401
418
}
@@ -404,6 +421,9 @@ String buildObjectKeyPrefix(boolean includeProfile) {
404
421
405
422
private String createPropertySourceName (String app , String profile ) {
406
423
StringBuilder propertySourceName = new StringBuilder ().append ("s3:" ).append (app );
424
+ if (this .useApplicationAsDirectory ) {
425
+ propertySourceName .append (PATH_SEPARATOR ).append ("application" );
426
+ }
407
427
if (profile != null ) {
408
428
propertySourceName .append ("-" ).append (profile );
409
429
}
@@ -414,8 +434,9 @@ private String createPropertySourceName(String app, String profile) {
414
434
415
435
class PropertyS3ConfigFile extends S3ConfigFile {
416
436
417
- PropertyS3ConfigFile (String application , String profile , String label , String bucketName , S3Client s3Client ) {
418
- super (application , profile , label , bucketName , s3Client );
437
+ PropertyS3ConfigFile (String application , String profile , String label , String bucketName ,
438
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
439
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client );
419
440
this .properties = read ();
420
441
}
421
442
@@ -446,13 +467,16 @@ class YamlS3ConfigFile extends S3ConfigFile {
446
467
447
468
final YamlProcessor .DocumentMatcher [] documentMatchers ;
448
469
449
- YamlS3ConfigFile (String application , String profile , String label , String bucketName , S3Client s3Client ) {
450
- this (application , profile , label , bucketName , s3Client , new YamlProcessor .DocumentMatcher [] {});
470
+ YamlS3ConfigFile (String application , String profile , String label , String bucketName ,
471
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
472
+ this (application , profile , label , bucketName , useApplicationAsDirectory , s3Client ,
473
+ new YamlProcessor .DocumentMatcher [] {});
451
474
}
452
475
453
- YamlS3ConfigFile (String application , String profile , String label , String bucketName , S3Client s3Client ,
476
+ YamlS3ConfigFile (String application , String profile , String label , String bucketName ,
477
+ boolean useApplicationAsDirectory , S3Client s3Client ,
454
478
final YamlProcessor .DocumentMatcher ... documentMatchers ) {
455
- super (application , profile , label , bucketName , s3Client );
479
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client );
456
480
this .documentMatchers = documentMatchers ;
457
481
this .properties = read ();
458
482
@@ -495,8 +519,8 @@ protected List<String> getExtensions() {
495
519
class ProfileSpecificYamlDocumentS3ConfigFile extends YamlS3ConfigFile {
496
520
497
521
ProfileSpecificYamlDocumentS3ConfigFile (String application , String profile , String label , String bucketName ,
498
- S3Client s3Client ) {
499
- super (application , profile , label , bucketName , s3Client ,
522
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
523
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client ,
500
524
properties -> profileMatchesActivateProperty (profile , properties ) ? YamlProcessor .MatchStatus .FOUND
501
525
: YamlProcessor .MatchStatus .NOT_FOUND );
502
526
}
@@ -516,18 +540,19 @@ protected String buildObjectKeyPrefix() {
516
540
class NonProfileSpecificYamlDocumentS3ConfigFile extends YamlS3ConfigFile {
517
541
518
542
NonProfileSpecificYamlDocumentS3ConfigFile (String application , String profile , String label , String bucketName ,
519
- S3Client s3Client ) {
520
- super (application , profile , label , bucketName , s3Client , properties -> !onProfilePropertyExists (properties )
521
- ? YamlProcessor .MatchStatus .FOUND : YamlProcessor .MatchStatus .NOT_FOUND );
543
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
544
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client ,
545
+ properties -> !onProfilePropertyExists (properties ) ? YamlProcessor .MatchStatus .FOUND
546
+ : YamlProcessor .MatchStatus .NOT_FOUND );
522
547
}
523
548
524
549
}
525
550
526
551
class ProfileSpecificYamlS3ConfigFile extends YamlS3ConfigFile {
527
552
528
553
ProfileSpecificYamlS3ConfigFile (String application , String profile , String label , String bucketName ,
529
- S3Client s3Client ) {
530
- super (application , profile , label , bucketName , s3Client ,
554
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
555
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client ,
531
556
properties -> !onProfilePropertyExists (properties ) ? YamlProcessor .MatchStatus .ABSTAIN
532
557
: profileMatchesActivateProperty (profile , properties ) ? YamlProcessor .MatchStatus .FOUND
533
558
: YamlProcessor .MatchStatus .NOT_FOUND );
@@ -539,8 +564,9 @@ class JsonS3ConfigFile extends YamlS3ConfigFile {
539
564
540
565
// YAML is a superset of JSON, which means you can parse JSON with a YAML parser
541
566
542
- JsonS3ConfigFile (String application , String profile , String label , String bucketName , S3Client s3Client ) {
543
- super (application , profile , label , bucketName , s3Client );
567
+ JsonS3ConfigFile (String application , String profile , String label , String bucketName ,
568
+ boolean useApplicationAsDirectory , S3Client s3Client ) {
569
+ super (application , profile , label , bucketName , useApplicationAsDirectory , s3Client );
544
570
this .properties = read ();
545
571
}
546
572
0 commit comments