Skip to content

Handle negated profiles in S3 bucket multi-document YAML files#3225

Open
ryanjbaxter wants to merge 2 commits into
spring-cloud:4.3.xfrom
ryanjbaxter:aws-s3-negated-profile-document
Open

Handle negated profiles in S3 bucket multi-document YAML files#3225
ryanjbaxter wants to merge 2 commits into
spring-cloud:4.3.xfrom
ryanjbaxter:aws-s3-negated-profile-document

Conversation

@ryanjbaxter
Copy link
Copy Markdown
Contributor

Fixes #3224

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #3224 by restoring parity between the S3 backend and other backends (native/git) for multi-document YAML handling when spring.config.activate.on-profile uses negation and more complex profile expressions. It extends the S3 YAML document selection logic so documents activated by profile expressions (e.g., !my-profile, profile1 & !profile2) can be included/excluded correctly, and adds regression tests for these scenarios.

Changes:

  • Add S3 YAML document matching support for negated/complex spring.config.activate.on-profile expressions using org.springframework.core.env.Profiles.
  • Add new AWS S3 repository tests covering negated profiles, multiple negated documents, and complex expressions (including application-directory layout variants).
  • Add test YAML fixtures representing multi-document inputs with negated and complex profile expressions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java Adds expression-based YAML document matching for S3-backed multi-document YAML.
spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java Adds regression tests validating inclusion/exclusion for negated and complex profile expressions.
spring-cloud-config-server/src/test/resources/awss3/application-with-negated-profile.yaml Fixture: base + !my-profile activated document.
spring-cloud-config-server/src/test/resources/awss3/application-with-two-negated-profiles.yaml Fixture: base + two negated-profile documents.
spring-cloud-config-server/src/test/resources/awss3/application-with-complex-profile-expressions.yaml Fixture: base + multiple complex profile expressions (&, `

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment on lines +190 to +194
catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Did not find negated profile yaml document in non-profile specific file using application <"
+ application + "> label <" + label + ">.");
}

private static boolean isSimpleProfileName(String expression) {
return !expression.contains("!") && !expression.contains("&") && !expression.contains("|")
&& !expression.contains("(");
Comment on lines +177 to +187
// null profiles → no active profiles → "!my-profile" should always match
final Environment env = envRepo.findOne("application", null, null);

List<PropertySource> propertySources = env.getPropertySources();
Optional<PropertySource> negatedProfileSource = propertySources.stream()
.filter(ps -> ps.getSource().containsKey("demo.negatedProfileMarker"))
.findFirst();
assertThat(negatedProfileSource).as("negated profile document should be present when no profiles are active")
.isPresent();
assertThat(negatedProfileSource.get().getSource().get("demo.negatedProfileMarker"))
.isEqualTo("present-when-my-profile-is-not-active");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support on-profile with formulas for s3 backend

3 participants