Skip to content

Commit

Permalink
allow AzureKeyVaultClient to take in custom credential (#3846)
Browse files Browse the repository at this point in the history
### Description

Allow creating AzureKeyVaultClient with custom credentials

### Other changes


### Tested


### Related issues

### Backwards compatibility
  • Loading branch information
zviadm authored Nov 12, 2020
1 parent 007d2e0 commit f9bb0a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/contractkit/src/utils/azure-key-vault-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultAzureCredential } from '@azure/identity'
import { DefaultAzureCredential, TokenCredential } from '@azure/identity'
import { CryptographyClient, KeyClient, KeyVaultKey } from '@azure/keyvault-keys'
import { SecretClient } from '@azure/keyvault-secrets'
import { BigNumber } from 'bignumber.js'
Expand All @@ -12,7 +12,7 @@ export class AzureKeyVaultClient {
private readonly vaultName: string
// Unique URI of the Azure Key Vault
private readonly vaultUri: string
private readonly credential: DefaultAzureCredential
private readonly credential: TokenCredential
private readonly keyClient: KeyClient
private readonly SIGNING_ALGORITHM: string = 'ECDSA256'
private cryptographyClientSet: Map<string, CryptographyClient> = new Map<
Expand All @@ -21,12 +21,12 @@ export class AzureKeyVaultClient {
>()
private readonly secretClient: SecretClient

constructor(vaultName: string) {
constructor(vaultName: string, credential?: TokenCredential) {
this.vaultName = vaultName
this.vaultUri = `https://${this.vaultName}.vault.azure.net`
// DefaultAzureCredential supports service principal or managed identity
// If using a service principal, you must set the appropriate environment vars
this.credential = new DefaultAzureCredential()
this.credential = credential || new DefaultAzureCredential()
this.keyClient = new KeyClient(this.vaultUri, this.credential)
this.secretClient = new SecretClient(this.vaultUri, this.credential)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9bb0a8

Please sign in to comment.