Skip to content

Commit cc00cdc

Browse files
committed
Fixing merge
1 parent 68d1c1d commit cc00cdc

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java

+47-21
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
6262

6363
private final ConfigServerProperties serverProperties;
6464

65+
private final boolean useApplicationAsDirectory;
66+
6567
protected int order = Ordered.LOWEST_PRECEDENCE;
6668

6769
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) {
6875
this.s3Client = s3Client;
6976
this.bucketName = bucketName;
7077
this.serverProperties = server;
78+
this.useApplicationAsDirectory = useApplicationAsDirectory;
7179
}
7280

7381
@Override
@@ -213,7 +221,7 @@ private List<YamlS3ConfigFile> getNonProfileSpecificS3ConfigFileYaml(String appl
213221
if (profile != null) {
214222
try {
215223
YamlS3ConfigFile configFileDocument = new ProfileSpecificYamlDocumentS3ConfigFile(application, profile,
216-
label, bucketName, s3Client);
224+
label, bucketName, useApplicationAsDirectory, s3Client);
217225
configFileDocument.setShouldIncludeWithEmptyProperties(false);
218226
configFiles.add(configFileDocument);
219227
}
@@ -226,7 +234,7 @@ private List<YamlS3ConfigFile> getNonProfileSpecificS3ConfigFileYaml(String appl
226234
}
227235
try {
228236
YamlS3ConfigFile configFile = new NonProfileSpecificYamlDocumentS3ConfigFile(application, null, label,
229-
bucketName, s3Client);
237+
bucketName, useApplicationAsDirectory, s3Client);
230238
configFiles.add(configFile);
231239
}
232240
catch (Exception e) {
@@ -243,7 +251,7 @@ private List<YamlS3ConfigFile> getProfileSpecificS3ConfigFileYaml(String applica
243251
String label) {
244252
try {
245253
YamlS3ConfigFile configFile = new ProfileSpecificYamlS3ConfigFile(application, profile, label, bucketName,
246-
s3Client);
254+
useApplicationAsDirectory, s3Client);
247255
return List.of(configFile);
248256
}
249257
catch (Exception e) {
@@ -262,15 +270,17 @@ private S3ConfigFile getS3PropertiesOrJsonConfigFile(String application, String
262270
LOG.debug("Getting S3 config file for " + application + " " + profile + " " + label);
263271
}
264272
try {
265-
return new PropertyS3ConfigFile(application, profile, label, bucketName, s3Client);
273+
return new PropertyS3ConfigFile(application, profile, label, bucketName, useApplicationAsDirectory,
274+
s3Client);
266275
}
267276
catch (Exception propertyException) {
268277
if (LOG.isDebugEnabled()) {
269278
LOG.debug("Did not find properties file using application <" + application + "> profile <" + profile
270279
+ "> label <" + label + ">. Trying json extension", propertyException);
271280
}
272281
try {
273-
return new JsonS3ConfigFile(application, profile, label, bucketName, s3Client);
282+
return new JsonS3ConfigFile(application, profile, label, bucketName, useApplicationAsDirectory,
283+
s3Client);
274284
}
275285
catch (Exception jsonException) {
276286
if (LOG.isDebugEnabled()) {
@@ -330,12 +340,16 @@ abstract class S3ConfigFile {
330340

331341
private boolean shouldIncludeWithEmptyProperties = true;
332342

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) {
334347
this.application = application;
335348
this.profile = profile;
336349
this.label = label;
337350
this.bucketName = bucketName;
338351
this.s3Client = s3Client;
352+
this.useApplicationAsDirectory = useApplicationAsDirectory;
339353
}
340354

341355
String getVersion() {
@@ -396,6 +410,9 @@ String buildObjectKeyPrefix(boolean includeProfile) {
396410
objectKeyPrefix.append(label).append(PATH_SEPARATOR);
397411
}
398412
objectKeyPrefix.append(application);
413+
if (this.useApplicationAsDirectory) {
414+
objectKeyPrefix.append(PATH_SEPARATOR).append("application");
415+
}
399416
if (!ObjectUtils.isEmpty(profile) && includeProfile) {
400417
objectKeyPrefix.append("-").append(profile);
401418
}
@@ -404,6 +421,9 @@ String buildObjectKeyPrefix(boolean includeProfile) {
404421

405422
private String createPropertySourceName(String app, String profile) {
406423
StringBuilder propertySourceName = new StringBuilder().append("s3:").append(app);
424+
if (this.useApplicationAsDirectory) {
425+
propertySourceName.append(PATH_SEPARATOR).append("application");
426+
}
407427
if (profile != null) {
408428
propertySourceName.append("-").append(profile);
409429
}
@@ -414,8 +434,9 @@ private String createPropertySourceName(String app, String profile) {
414434

415435
class PropertyS3ConfigFile extends S3ConfigFile {
416436

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);
419440
this.properties = read();
420441
}
421442

@@ -446,13 +467,16 @@ class YamlS3ConfigFile extends S3ConfigFile {
446467

447468
final YamlProcessor.DocumentMatcher[] documentMatchers;
448469

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[] {});
451474
}
452475

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,
454478
final YamlProcessor.DocumentMatcher... documentMatchers) {
455-
super(application, profile, label, bucketName, s3Client);
479+
super(application, profile, label, bucketName, useApplicationAsDirectory, s3Client);
456480
this.documentMatchers = documentMatchers;
457481
this.properties = read();
458482

@@ -495,8 +519,8 @@ protected List<String> getExtensions() {
495519
class ProfileSpecificYamlDocumentS3ConfigFile extends YamlS3ConfigFile {
496520

497521
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,
500524
properties -> profileMatchesActivateProperty(profile, properties) ? YamlProcessor.MatchStatus.FOUND
501525
: YamlProcessor.MatchStatus.NOT_FOUND);
502526
}
@@ -516,18 +540,19 @@ protected String buildObjectKeyPrefix() {
516540
class NonProfileSpecificYamlDocumentS3ConfigFile extends YamlS3ConfigFile {
517541

518542
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);
522547
}
523548

524549
}
525550

526551
class ProfileSpecificYamlS3ConfigFile extends YamlS3ConfigFile {
527552

528553
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,
531556
properties -> !onProfilePropertyExists(properties) ? YamlProcessor.MatchStatus.ABSTAIN
532557
: profileMatchesActivateProperty(profile, properties) ? YamlProcessor.MatchStatus.FOUND
533558
: YamlProcessor.MatchStatus.NOT_FOUND);
@@ -539,8 +564,9 @@ class JsonS3ConfigFile extends YamlS3ConfigFile {
539564

540565
// YAML is a superset of JSON, which means you can parse JSON with a YAML parser
541566

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);
544570
this.properties = read();
545571
}
546572

spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.cloud.config.server.environment;
1818

1919
import java.io.IOException;
20-
import java.io.UnsupportedEncodingException;
2120
import java.nio.file.Files;
2221
import java.nio.file.Paths;
2322
import java.util.ArrayList;
@@ -47,6 +46,8 @@
4746
import org.springframework.cloud.config.environment.Environment;
4847
import org.springframework.cloud.config.environment.PropertySource;
4948
import org.springframework.cloud.config.server.config.ConfigServerProperties;
49+
import org.springframework.core.io.ClassPathResource;
50+
import org.springframework.core.io.Resource;
5051

5152
import static org.assertj.core.api.Assertions.assertThat;
5253
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;

0 commit comments

Comments
 (0)