Ansar
Ansar

Reputation: 3

Is there a way to set Environment Variables for Azure Key vault using some API within the source code (not through cli)?

I was trying to set following env variable. But I wanted to do so with api if possible. I couldn't find anything, just wanted to make sure if I can.

AZURE_CLIENT_ID - service principal's app id AZURE_TENANT_ID - id of the principal's Azure Active Directory tenant AZURE_CLIENT_SECRET - one of the service principal's client secrets

Upvotes: 0

Views: 1313

Answers (1)

SwethaKandikonda
SwethaKandikonda

Reputation: 8254

As mentioned by @Vineesh Vijayan, you can use the Azure key vault which lets you retrieve key-value pairs. After creating the key vault resource, you can add your environment variables by Adding secret to Key Vault. Make sure you add the dependencies in pom.xml.

And now you can retrieve the stored keys after Authenticating your key vault using the below line.

KeyVaultKey retrievedKey = keyClient.getKey(keyName);

In Case you trying to Get Secrets using rest API, you can use

GET {vaultBaseUrl}/secrets/{secret-name}/{secret-version}?api-version=7.3

REFERENCES: Azure Key Vault Secret client library for Java

Upvotes: 0

Related Questions