@Test void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); when(smClient.getSecretValue(any(GetSecretValueRequest.class))) .thenReturn(secretValueResult); AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator( smClient, properties); PropertySource propertySource = locator.locate(env); assertThat(propertySource.getName()).isEqualTo("aws-secrets-manager"); }
@Override public PropertySource<?> locate(Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return null; } ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = properties.getName(); if (appName == null) { appName = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); String prefix = this.properties.getPrefix(); String appContext = prefix + "/" + appName; addProfiles(this.contexts, appContext, profiles); this.contexts.add(appContext); String defaultContext = prefix + "/" + this.properties.getDefaultContext(); addProfiles(this.contexts, defaultContext, profiles); this.contexts.add(defaultContext); CompositePropertySource composite = new CompositePropertySource( this.propertySourceName); for (String propertySourceContext : this.contexts) { try { composite.addPropertySource(create(propertySourceContext)); } catch (Exception e) { if (this.properties.isFailFast()) { logger.error( "Fail fast is set and there was an error reading configuration from AWS Secrets Manager:\n" + e.getMessage()); ReflectionUtils.rethrowRuntimeException(e); } else { logger.warn("Unable to load AWS secret from " + propertySourceContext, e); } } } return composite; }
AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator { @Override public PropertySource<?> locate(Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return null; } ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = properties.getName(); if (appName == null) { appName = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); String prefix = this.properties.getPrefix(); String appContext = prefix + "/" + appName; addProfiles(this.contexts, appContext, profiles); this.contexts.add(appContext); String defaultContext = prefix + "/" + this.properties.getDefaultContext(); addProfiles(this.contexts, defaultContext, profiles); this.contexts.add(defaultContext); CompositePropertySource composite = new CompositePropertySource( this.propertySourceName); for (String propertySourceContext : this.contexts) { try { composite.addPropertySource(create(propertySourceContext)); } catch (Exception e) { if (this.properties.isFailFast()) { logger.error( "Fail fast is set and there was an error reading configuration from AWS Secrets Manager:\n" + e.getMessage()); ReflectionUtils.rethrowRuntimeException(e); } else { logger.warn("Unable to load AWS secret from " + propertySourceContext, e); } } } return composite; } }
AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator { @Override public PropertySource<?> locate(Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return null; } ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = properties.getName(); if (appName == null) { appName = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); String prefix = this.properties.getPrefix(); String appContext = prefix + "/" + appName; addProfiles(this.contexts, appContext, profiles); this.contexts.add(appContext); String defaultContext = prefix + "/" + this.properties.getDefaultContext(); addProfiles(this.contexts, defaultContext, profiles); this.contexts.add(defaultContext); CompositePropertySource composite = new CompositePropertySource( this.propertySourceName); for (String propertySourceContext : this.contexts) { try { composite.addPropertySource(create(propertySourceContext)); } catch (Exception e) { if (this.properties.isFailFast()) { logger.error( "Fail fast is set and there was an error reading configuration from AWS Secrets Manager:\n" + e.getMessage()); ReflectionUtils.rethrowRuntimeException(e); } else { logger.warn("Unable to load AWS secret from " + propertySourceContext, e); } } } return composite; } AwsSecretsManagerPropertySourceLocator(String propertySourceName,
			AWSSecretsManager smClient, AwsSecretsManagerProperties properties);  AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient,
			AwsSecretsManagerProperties properties); }
AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator { @Override public PropertySource<?> locate(Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return null; } ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = properties.getName(); if (appName == null) { appName = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); String prefix = this.properties.getPrefix(); String appContext = prefix + "/" + appName; addProfiles(this.contexts, appContext, profiles); this.contexts.add(appContext); String defaultContext = prefix + "/" + this.properties.getDefaultContext(); addProfiles(this.contexts, defaultContext, profiles); this.contexts.add(defaultContext); CompositePropertySource composite = new CompositePropertySource( this.propertySourceName); for (String propertySourceContext : this.contexts) { try { composite.addPropertySource(create(propertySourceContext)); } catch (Exception e) { if (this.properties.isFailFast()) { logger.error( "Fail fast is set and there was an error reading configuration from AWS Secrets Manager:\n" + e.getMessage()); ReflectionUtils.rethrowRuntimeException(e); } else { logger.warn("Unable to load AWS secret from " + propertySourceContext, e); } } } return composite; } AwsSecretsManagerPropertySourceLocator(String propertySourceName,
			AWSSecretsManager smClient, AwsSecretsManagerProperties properties);  AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient,
			AwsSecretsManagerProperties properties); List<String> getContexts(); @Override PropertySource<?> locate(Environment environment); }
AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator { @Override public PropertySource<?> locate(Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return null; } ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = properties.getName(); if (appName == null) { appName = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); String prefix = this.properties.getPrefix(); String appContext = prefix + "/" + appName; addProfiles(this.contexts, appContext, profiles); this.contexts.add(appContext); String defaultContext = prefix + "/" + this.properties.getDefaultContext(); addProfiles(this.contexts, defaultContext, profiles); this.contexts.add(defaultContext); CompositePropertySource composite = new CompositePropertySource( this.propertySourceName); for (String propertySourceContext : this.contexts) { try { composite.addPropertySource(create(propertySourceContext)); } catch (Exception e) { if (this.properties.isFailFast()) { logger.error( "Fail fast is set and there was an error reading configuration from AWS Secrets Manager:\n" + e.getMessage()); ReflectionUtils.rethrowRuntimeException(e); } else { logger.warn("Unable to load AWS secret from " + propertySourceContext, e); } } } return composite; } AwsSecretsManagerPropertySourceLocator(String propertySourceName,
			AWSSecretsManager smClient, AwsSecretsManagerProperties properties);  AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient,
			AwsSecretsManagerProperties properties); List<String> getContexts(); @Override PropertySource<?> locate(Environment environment);  }