Initial implementation to support multiple labels for credhub (#2568)

Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
Ryan Baxter
2024-10-02 10:15:57 -04:00
committed by GitHub
parent 73f4bf56dc
commit 13dd2ca6dc
2 changed files with 28 additions and 3 deletions

View File

@@ -77,11 +77,14 @@ public class CredhubEnvironmentRepository implements EnvironmentRepository, Orde
List<String> applications = normalize(application, DEFAULT_APPLICATION);
List<String> profiles = normalize(profile, DEFAULT_PROFILE);
List<String> labels = normalize(label, this.defaultLabel);
Environment environment = new Environment(application, split(profile), label, null, null);
for (String prof : profiles) {
for (String app : applications) {
addPropertySource(environment, app, prof, label);
for (String l : labels) {
for (String prof : profiles) {
for (String app : applications) {
addPropertySource(environment, app, prof, l);
}
}
}

View File

@@ -121,6 +121,28 @@ public class CredhubEnvironmentRepositoryTests {
assertThat(environment.getPropertySources().get(1).getSource()).isEqualTo(Map.of("k1", "v1"));
}
@Test
public void shouldRetrieveGivenLabelsProfiles() {
stubCredentials("/myApp/prod/myLabel", credential("c1", "k1", "v1"));
stubCredentials("/myApp/cloud/mySecondLabel", credential("c2", "k2", "v2"));
stubCredentials("/myApp/prod/myThirdLabel", credential("c3", "k3", "v3"));
Environment environment = this.credhubEnvironmentRepository.findOne("myApp", "prod,cloud",
"myLabel,mySecondLabel");
assertThat(environment.getName()).isEqualTo("myApp");
assertThat(environment.getProfiles()).containsExactly("prod", "cloud");
assertThat(environment.getLabel()).isEqualTo("myLabel,mySecondLabel");
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getPropertySources().get(0).getName()).isEqualTo("credhub-myApp-cloud-mySecondLabel");
assertThat(environment.getPropertySources().get(0).getSource()).isEqualTo(Map.of("k2", "v2"));
assertThat(environment.getPropertySources().get(1).getName()).isEqualTo("credhub-myApp-prod-myLabel");
assertThat(environment.getPropertySources().get(1).getSource()).isEqualTo(Map.of("k1", "v1"));
}
@Test
public void shouldRetrieveGivenMultipleApplicationNames() {
stubCredentials("/app1/default/myLabel", credential("c1", "k1", "v1"));