From ac272c7c7341cbbea350bd967a720be1a6258b5d Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Tue, 25 Jun 2024 16:19:04 +0200 Subject: [PATCH] Added azure-cli credential type. (#728) --- src/Sign.Cli/AzureCredentialOptions.cs | 3 ++- src/Sign.Cli/AzureCredentialType.cs | 1 + .../AzureCredentialOptionsTests.cs | 21 ++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Sign.Cli/AzureCredentialOptions.cs b/src/Sign.Cli/AzureCredentialOptions.cs index 5e36ee20..cec5da2d 100644 --- a/src/Sign.Cli/AzureCredentialOptions.cs +++ b/src/Sign.Cli/AzureCredentialOptions.cs @@ -14,6 +14,7 @@ namespace Sign.Cli internal sealed class AzureCredentialOptions { internal Option CredentialTypeOption { get; } = new Option(["--azure-credential-type", "-act"], Resources.CredentialTypeOptionDescription).FromAmong( + AzureCredentialType.AzureCli, AzureCredentialType.Environment); internal Option ManagedIdentityOption { get; } = new(["--azure-key-vault-managed-identity", "-kvm"], Resources.ManagedIdentityOptionDescription) { IsHidden = true }; internal Option TenantIdOption { get; } = new(["--azure-key-vault-tenant-id", "-kvt"], Resources.TenantIdOptionDescription); @@ -36,7 +37,7 @@ internal DefaultAzureCredentialOptions CreateDefaultAzureCredentialOptions(Parse string? credentialType = parseResult.GetValueForOption(CredentialTypeOption); if (credentialType is not null) { - options.ExcludeAzureCliCredential = true; + options.ExcludeAzureCliCredential = credentialType != AzureCredentialType.AzureCli; options.ExcludeAzureDeveloperCliCredential = true; options.ExcludeAzurePowerShellCredential = true; options.ExcludeEnvironmentCredential = credentialType != AzureCredentialType.Environment; diff --git a/src/Sign.Cli/AzureCredentialType.cs b/src/Sign.Cli/AzureCredentialType.cs index d9da1200..49388cd4 100644 --- a/src/Sign.Cli/AzureCredentialType.cs +++ b/src/Sign.Cli/AzureCredentialType.cs @@ -6,6 +6,7 @@ namespace Sign.Cli { internal static class AzureCredentialType { + public const string AzureCli = "azure-cli"; public const string Environment = "environment"; } } diff --git a/test/Sign.Cli.Test/AzureCredentialOptionsTests.cs b/test/Sign.Cli.Test/AzureCredentialOptionsTests.cs index 46d0327c..7a27cd30 100644 --- a/test/Sign.Cli.Test/AzureCredentialOptionsTests.cs +++ b/test/Sign.Cli.Test/AzureCredentialOptionsTests.cs @@ -124,7 +124,7 @@ public void CreateDefaultAzureCredentialOptions_WhenNoOptionsAreSpecified_Exclud } [Fact] - public void CreateDefaultAzureCredentialOptions_WhenEnvironmentIsSpecified_ExcludeOptionsHaveTheCorrectValues() + public void CreateDefaultAzureCredentialOptions_WhenEnvironmentCredentialTypeIsSpecified_ExcludeOptionsHaveTheCorrectValues() { ParseResult result = _parser.Parse(@"azure-key-vault -kvu https://keyvault.test -kvc a -act environment b"); @@ -141,5 +141,24 @@ public void CreateDefaultAzureCredentialOptions_WhenEnvironmentIsSpecified_Exclu Assert.True(credentialOptions.ExcludeVisualStudioCredential); Assert.True(credentialOptions.ExcludeWorkloadIdentityCredential); } + + [Fact] + public void CreateDefaultAzureCredentialOptions_WhenAzureCliCredentialTypeIsSpecified_ExcludeOptionsHaveTheCorrectValues() + { + ParseResult result = _parser.Parse(@"azure-key-vault -kvu https://keyvault.test -kvc a -act azure-cli b"); + + DefaultAzureCredentialOptions credentialOptions = _options.CreateDefaultAzureCredentialOptions(result); + + Assert.False(credentialOptions.ExcludeAzureCliCredential); + Assert.True(credentialOptions.ExcludeAzureDeveloperCliCredential); + Assert.True(credentialOptions.ExcludeAzurePowerShellCredential); + Assert.True(credentialOptions.ExcludeEnvironmentCredential); + Assert.True(credentialOptions.ExcludeInteractiveBrowserCredential); + Assert.True(credentialOptions.ExcludeManagedIdentityCredential); + Assert.True(credentialOptions.ExcludeSharedTokenCacheCredential); + Assert.True(credentialOptions.ExcludeVisualStudioCodeCredential); + Assert.True(credentialOptions.ExcludeVisualStudioCredential); + Assert.True(credentialOptions.ExcludeWorkloadIdentityCredential); + } } }