This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 0f0d7907eca CAMEL-19325: Add default identity support (#10002)
0f0d7907eca is described below
commit 0f0d7907ecace4e869416e375c60b8e1e540c8b7
Author: Andreas Klug <[email protected]>
AuthorDate: Sat May 6 09:08:29 2023 +0200
CAMEL-19325: Add default identity support (#10002)
Co-authored-by: Andreas Klug (BD/XDE1) <[email protected]>
---
components/camel-azure/camel-azure-cosmosdb/pom.xml | 4 ++++
.../component/azure/cosmosdb/CosmosDbComponent.java | 3 ---
.../component/azure/cosmosdb/CosmosDbConfiguration.java | 16 +++++++++++++++-
.../azure/cosmosdb/client/CosmosDbClientFactory.java | 10 ++++++++--
4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/components/camel-azure/camel-azure-cosmosdb/pom.xml
b/components/camel-azure/camel-azure-cosmosdb/pom.xml
index bcb14ffcff5..579a3ed7e74 100644
--- a/components/camel-azure/camel-azure-cosmosdb/pom.xml
+++ b/components/camel-azure/camel-azure-cosmosdb/pom.xml
@@ -52,6 +52,10 @@
<groupId>com.azure</groupId>
<artifactId>azure-cosmos</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.azure</groupId>
+ <artifactId>azure-identity</artifactId>
+ </dependency>
<!-- extras -->
<dependency>
diff --git
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponent.java
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponent.java
index 7ff3f0273d1..21486ea59d6 100644
---
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponent.java
+++
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponent.java
@@ -82,9 +82,6 @@ public class CosmosDbComponent extends DefaultComponent {
if (ObjectHelper.isEmpty(configuration.getDatabaseEndpoint())) {
throw new IllegalArgumentException("Azure CosmosDB database
endpoint must be specified.");
}
- if (ObjectHelper.isEmpty(configuration.getAccountKey())) {
- throw new IllegalArgumentException("Azure CosmosDB account key
must be specified.");
- }
}
}
}
diff --git
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java
index bb17deaf247..a504dae6976 100644
---
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java
+++
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java
@@ -35,8 +35,11 @@ public class CosmosDbConfiguration implements Cloneable {
@UriPath
private String containerName;
@UriParam(label = "security", secret = true)
- @Metadata(required = true)
+ @Metadata(required = false)
private String accountKey;
+ @UriParam(label = "security", secret = false)
+ @Metadata(required = false)
+ private boolean useDefaultIdentity;
@UriParam(label = "common")
@Metadata(required = true)
private String databaseEndpoint;
@@ -126,6 +129,17 @@ public class CosmosDbConfiguration implements Cloneable {
this.accountKey = accountKey;
}
+ /**
+ * Indicates whether to use the default identity mechanism instead of the
access key.
+ */
+ public boolean isUseDefaultIdentity() {
+ return useDefaultIdentity;
+ }
+
+ public void setUseDefaultIdentity(boolean useDefaultIdentity) {
+ this.useDefaultIdentity = useDefaultIdentity;
+ }
+
/**
* Sets the Azure Cosmos database endpoint the component will connect to.
*/
diff --git
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java
index 192aea01b40..a11ff24d7c5 100644
---
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java
+++
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java
@@ -22,6 +22,7 @@ import java.util.stream.Stream;
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
+import com.azure.identity.DefaultAzureCredentialBuilder;
import org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration;
import org.apache.camel.util.ObjectHelper;
@@ -41,8 +42,8 @@ public final class CosmosDbClientFactory {
}
private static CosmosClientBuilder createBasicClient(final
CosmosDbConfiguration configuration) {
+
CosmosClientBuilder builder = new CosmosClientBuilder()
- .key(configuration.getAccountKey())
.endpoint(configuration.getDatabaseEndpoint())
.contentResponseOnWriteEnabled(configuration.isContentResponseOnWriteEnabled())
.consistencyLevel(configuration.getConsistencyLevel())
@@ -55,7 +56,12 @@ public final class CosmosDbClientFactory {
.map(String::trim)
.collect(Collectors.toList()));
}
-
+ if (configuration.isUseDefaultIdentity()) {
+ final DefaultAzureCredentialBuilder defaultAzureCredentialBuilder
= new DefaultAzureCredentialBuilder();
+ builder.credential(defaultAzureCredentialBuilder.build());
+ } else {
+ builder.key(configuration.getAccountKey());
+ }
return builder;
}
}