in components-starter/camel-google-secret-manager-starter/src/main/java/org/apache/camel/component/google/secret/manager/springboot/SpringBootGoogleSecretManagerPropertiesParser.java [41:91]
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
SecretManagerServiceClient client;
ConfigurableEnvironment environment = event.getEnvironment();
String projectId;
if (Boolean.parseBoolean(environment.getProperty("camel.component.google-secret-manager.early-resolve-properties"))) {
projectId = environment.getProperty("camel.vault.gcp.projectId");
boolean useDefaultInstance = Boolean.parseBoolean(environment.getProperty("camel.vault.gcp.useDefaultInstance"));
if (useDefaultInstance && ObjectHelper.isNotEmpty(projectId)) {
SecretManagerServiceSettings settings = null;
try {
settings = SecretManagerServiceSettings.newBuilder().build();
client = SecretManagerServiceClient.create(settings);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeCamelException(
"Using the GCP Secret Manager Properties Function in Spring Boot early resolver mode requires setting GCP project Id as application properties and use default instance option to true");
}
GoogleSecretManagerPropertiesFunction secretsManagerPropertiesFunction = new GoogleSecretManagerPropertiesFunction(client, projectId);
final Properties props = new Properties();
for (PropertySource mutablePropertySources : event.getEnvironment().getPropertySources()) {
if (mutablePropertySources instanceof MapPropertySource mapPropertySource) {
mapPropertySource.getSource().forEach((key, value) -> {
String stringValue = null;
if ((value instanceof OriginTrackedValue originTrackedValue &&
originTrackedValue.getValue() instanceof String v)) {
stringValue = v;
} else if (value instanceof String v) {
stringValue = v;
}
if (stringValue != null &&
stringValue.startsWith("{{gcp:") &&
stringValue.endsWith("}}")) {
LOG.debug("decrypting and overriding property {}", key);
try {
String element = secretsManagerPropertiesFunction.apply(stringValue
.replace("{{gcp:", "")
.replace("}}", ""));
props.put(key, element);
} catch (Exception e) {
// Log and do nothing
LOG.debug("failed to parse property {}. This exception is ignored.", key, e);
}
}
});
}
}
environment.getPropertySources().addFirst(new PropertiesPropertySource("overridden-camel-google-secret-manager-properties", props));
}
}