Skip to content

Commit

Permalink
Merge branch '4.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Nov 29, 2023
2 parents dc9d207 + 8a409cd commit c4f1720
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class AwsSecretsManagerEnvironmentProperties implements EnvironmentReposi
*/
private String defaultLabel;

/**
* Do not set staging label when fetching the secret values.
*/
private boolean ignoreLabel;

/**
* The order of the environment repository.
*/
Expand Down Expand Up @@ -105,6 +110,14 @@ public void setDefaultLabel(String defaultLabel) {
this.defaultLabel = defaultLabel;
}

public boolean isIgnoreLabel() {
return this.ignoreLabel;
}

public void setIgnoreLabel(boolean ignoreLabel) {
this.ignoreLabel = ignoreLabel;
}

public int getOrder() {
return order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Environment findOne(String application, String profileList, String label)
final String defaultApplication = configServerProperties.getDefaultApplicationName();
final String defaultProfile = configServerProperties.getDefaultProfile();
final String defaultLabel = environmentProperties.getDefaultLabel();
final boolean ignoreLabel = environmentProperties.isIgnoreLabel();

if (ObjectUtils.isEmpty(application)) {
application = defaultApplication;
Expand All @@ -82,7 +83,10 @@ public Environment findOne(String application, String profileList, String label)
profileList = defaultProfile;
}

if (StringUtils.isEmpty(label)) {
if (ignoreLabel) {
label = null;
}
else if (StringUtils.isEmpty(label)) {
label = defaultLabel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
private final AwsSecretsManagerEnvironmentRepository labeledRepository = new AwsSecretsManagerEnvironmentRepository(
smClient, configServerProperties, labeledEnvironmentProperties);

private final AwsSecretsManagerEnvironmentProperties ignoreLabelEnvironmentProperties = new AwsSecretsManagerEnvironmentProperties() {{
setIgnoreLabel(true);
}};

private final AwsSecretsManagerEnvironmentRepository ignoreLabelRepository = new AwsSecretsManagerEnvironmentRepository(
smClient, configServerProperties, ignoreLabelEnvironmentProperties);

private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);

private final List<String> toBeRemoved = new ArrayList<>();
Expand Down Expand Up @@ -1827,6 +1834,47 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNoDef
assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
}

@Test
public void testFindOneWithExistingApplicationAndExistingProfileAndExistingLabelWhenIgnoreLabelIsSet() {
String application = "foo";
String profile = "prod";
String label = "release";
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);

String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/";
PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdReleaseProperties());

String fooPropertiesName = "aws:secrets:/secret/foo/";
PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooReleaseProperties());

String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
getFooDefaultReleaseProperties());

String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
getApplicationProdReleaseProperties());

String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
getApplicationDefaultReleaseProperties());

String applicationPropertiesName = "aws:secrets:/secret/application/";
PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
getApplicationReleaseProperties());

Environment expectedEnv = new Environment(application, profiles, null, null, null);
expectedEnv.addAll(Arrays.asList(
fooProdProperties, applicationProdProperties, fooDefaultProperties,
applicationDefaultProperties, fooProperties, applicationProperties));

putSecrets(expectedEnv);

Environment resultEnv = ignoreLabelRepository.findOne(application, profile, label);

assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
}

@Test
public void testFindOneWithNullApplicationAndNullProfile() {
String application = null;
Expand Down

0 comments on commit c4f1720

Please sign in to comment.