From 857df947bd772aebfaea3a161fd18a13bdf7732b Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 6 Nov 2024 08:41:26 -0500 Subject: [PATCH 1/2] Use azure cli credentials if client and key are not configured --- src/main/java/gyro/azure/AzureCredentials.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/gyro/azure/AzureCredentials.java b/src/main/java/gyro/azure/AzureCredentials.java index 8b1df928..e5ace11c 100644 --- a/src/main/java/gyro/azure/AzureCredentials.java +++ b/src/main/java/gyro/azure/AzureCredentials.java @@ -24,6 +24,7 @@ import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder; import com.azure.core.management.AzureEnvironment; import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.AzureCliCredentialBuilder; import com.azure.identity.ClientSecretCredentialBuilder; import com.azure.resourcemanager.AzureResourceManager; import com.azure.resourcemanager.communication.CommunicationManager; @@ -132,6 +133,10 @@ public T createClient(Class clientClass) { } public TokenCredential getTokenCredential(String tenant, String client, String key) { + if (client == null || key == null) { + return new AzureCliCredentialBuilder().build(); + } + return new ClientSecretCredentialBuilder() .clientId(ObjectUtils.to(String.class, client)) .clientSecret(ObjectUtils.to(String.class, key)) From 160623299f7cf60505d636e499f3928c570705cb Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 6 Nov 2024 11:16:39 -0500 Subject: [PATCH 2/2] tenant can be null too --- src/main/java/gyro/azure/AzureCredentials.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gyro/azure/AzureCredentials.java b/src/main/java/gyro/azure/AzureCredentials.java index e5ace11c..f476ab25 100644 --- a/src/main/java/gyro/azure/AzureCredentials.java +++ b/src/main/java/gyro/azure/AzureCredentials.java @@ -133,7 +133,7 @@ public T createClient(Class clientClass) { } public TokenCredential getTokenCredential(String tenant, String client, String key) { - if (client == null || key == null) { + if (tenant == null || client == null || key == null) { return new AzureCliCredentialBuilder().build(); }