-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prioritize AzureCliCredential for secret-manager
- Loading branch information
Showing
4 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/SecretManager/Microsoft.DncEng.SecretManager/ITokenCredentialProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
|
||
namespace Microsoft.DncEng.SecretManager; | ||
|
||
public interface ITokenCredentialProvider | ||
{ | ||
public Task<TokenCredential> GetCredentialAsync(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/SecretManager/Microsoft.DncEng.SecretManager/SecretManagerCredentialProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Identity; | ||
|
||
namespace Microsoft.DncEng.SecretManager; | ||
|
||
public sealed class SecretManagerCredentialProvider : ITokenCredentialProvider | ||
{ | ||
// Expect AzureCliCredential for CI and local dev environments. | ||
// Use InteractiveBrowserCredential as a fallback for local dev environments. | ||
private readonly Lazy<TokenCredential> _credential = new(() => | ||
new ChainedTokenCredential( | ||
new AzureCliCredential(new AzureCliCredentialOptions { TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" }), | ||
new InteractiveBrowserCredential(new InteractiveBrowserCredentialOptions() { TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" }) | ||
)); | ||
|
||
public Task<TokenCredential> GetCredentialAsync() | ||
{ | ||
return Task.FromResult(_credential.Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters