Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.aws.secretsmanager.SecretsManagerPropertiesFunction;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -80,23 +80,21 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);

if (stringValue != null &&
stringValue.startsWith("{{aws:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
String element = secretsManagerPropertiesFunction.apply(stringValue
.replace("{{aws:", "")
.replace("}}", ""));
props.put(key, element);
EarlyResolutionPropertySources.putIfAbsent(props, key, element);
Comment thread
davsclaus marked this conversation as resolved.
} catch (Exception e) {
if (ignoreResolutionFailures) {
LOG.warn("Failed to resolve property {} from the vault; the placeholder is left "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.azure.security.keyvault.secrets.SecretClientBuilder;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.azure.key.vault.KeyVaultPropertiesFunction;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -90,22 +90,20 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);
if (stringValue != null &&
stringValue.startsWith("{{azure:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
String element = keyVaultPropertiesFunction.apply(stringValue
.replace("{{azure:", "")
.replace("}}", ""));
props.put(key, element);
EarlyResolutionPropertySources.putIfAbsent(props, key, element);
Comment thread
davsclaus marked this conversation as resolved.
} catch (Exception e) {
if (ignoreResolutionFailures) {
LOG.warn("Failed to resolve property {} from the vault; the placeholder is left "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import org.apache.camel.component.cyberark.vault.CyberArkVaultPropertiesFunction;
import org.apache.camel.component.cyberark.vault.client.ConjurClient;
import org.apache.camel.component.cyberark.vault.client.ConjurClientFactory;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -78,23 +78,21 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);

if (stringValue != null &&
stringValue.startsWith("{{cyberark:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
String element = cyberArkVaultPropertiesFunction.apply(stringValue
.replace("{{cyberark:", "")
.replace("}}", ""));
props.put(key, element);
EarlyResolutionPropertySources.putIfAbsent(props, key, element);
Comment thread
davsclaus marked this conversation as resolved.
} catch (Exception e) {
if (ignoreResolutionFailures) {
LOG.warn("Failed to resolve property {} from the vault; the placeholder is left "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.google.secret.manager.GoogleSecretManagerPropertiesFunction;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -66,22 +66,20 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);
if (stringValue != null &&
stringValue.startsWith("{{gcp:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
String element = secretsManagerPropertiesFunction.apply(stringValue
.replace("{{gcp:", "")
.replace("}}", ""));
props.put(key, element);
EarlyResolutionPropertySources.putIfAbsent(props, key, element);
Comment thread
davsclaus marked this conversation as resolved.
} catch (Exception e) {
if (ignoreResolutionFailures) {
LOG.warn("Failed to resolve property {} from the vault; the placeholder is left "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.hashicorp.vault.HashicorpVaultPropertiesFunction;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -70,20 +70,18 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);

if (stringValue != null &&
stringValue.startsWith("{{hashicorp:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
props.put(key, hashicorpVaultPropertiesFunction.apply(stringValue
EarlyResolutionPropertySources.putIfAbsent(props, key, hashicorpVaultPropertiesFunction.apply(stringValue
Comment thread
davsclaus marked this conversation as resolved.
.replace("{{hashicorp:", "")
.replace("}}", "")));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.hashicorp.vault.springboot;

import java.util.Map;

import org.apache.camel.test.infra.hashicorp.vault.services.HashicorpServiceFactory;
import org.apache.camel.test.infra.hashicorp.vault.services.HashicorpVaultService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.bootstrap.DefaultBootstrapContext;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.StandardEnvironment;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

class SpringBootHashicorpVaultPropertiesParserPrecedenceTest {

@RegisterExtension
static HashicorpVaultService service = HashicorpServiceFactory.createService();

@BeforeAll
static void setupVaultConnection() {
System.setProperty("camel.vault.hashicorp.host", service.host());
System.setProperty("camel.vault.hashicorp.port", String.valueOf(service.port()));
System.setProperty("camel.vault.hashicorp.scheme", "http");
System.setProperty("camel.vault.hashicorp.token", service.token());
}

@Test
void shouldSkipMissingLowerPrecedencePlaceholderWhenHigherPrecedenceDefinesPlainValue() {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("config", Map.of(
"camel.component.hashicorp-vault.early-resolve-properties", "true",
"camel.vault.hashicorp.host", service.host(),
"camel.vault.hashicorp.port", String.valueOf(service.port()),
"camel.vault.hashicorp.scheme", "http",
"camel.vault.hashicorp.token", service.token())));
environment.getPropertySources().addFirst(new MapPropertySource("precedence-high", Map.of(
"precedence.test.key", "plain-value-from-high")));
environment.getPropertySources().addLast(new MapPropertySource("precedence-low", Map.of(
"precedence.test.key", "{{hashicorp:does-not-exist#field}}")));

SpringBootHashicorpVaultPropertiesParser parser = new SpringBootHashicorpVaultPropertiesParser();
ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
new DefaultBootstrapContext(), new SpringApplication(Object.class), new String[] {}, environment);

assertThatCode(() -> parser.onApplicationEvent(event)).doesNotThrowAnyException();
assertThat(environment.getProperty("precedence.test.key")).isEqualTo("plain-value-from-high");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import com.ibm.cloud.secrets_manager_sdk.secrets_manager.v2.SecretsManager;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.ibm.secrets.manager.IBMSecretsManagerPropertiesFunction;
import org.apache.camel.spring.boot.EarlyResolutionPropertySources;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -64,22 +64,20 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
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;
}
String stringValue = EarlyResolutionPropertySources.asString(value);
if (stringValue != null &&
stringValue.startsWith("{{ibm:") &&
stringValue.endsWith("}}")) {
if (EarlyResolutionPropertySources.shouldSkipBecauseHigherPrecedenceDefines(
event.getEnvironment().getPropertySources(), mutablePropertySources, key, LOG)) {
return;
}
LOG.debug("decrypting and overriding property {}", key);
try {
String element = secretsManagerPropertiesFunction.apply(stringValue
.replace("{{ibm:", "")
.replace("}}", ""));
props.put(key, element);
EarlyResolutionPropertySources.putIfAbsent(props, key, element);
Comment thread
davsclaus marked this conversation as resolved.
} catch (Exception e) {
if (ignoreResolutionFailures) {
LOG.warn("Failed to resolve property {} from the vault; the placeholder is left "
Expand Down
Loading
Loading