Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var http = require('http');
const {DefaultAzureCredential} = require('@azure/identity');
const {SecretClient} = require('@azure/keyvault-secrets');
// DefaultAzureCredential expects the following three environment variables:
// - AZURE_TENANT_ID: The tenant ID in Azure Active Directory
// - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
// - AZURE_CLIENT_SECRET: The client secret for the registered application
const credential = new DefaultAzureCredential();
const vaultName = process.env["KEYVAULT_NAME"] || "";
const url = `https://${vaultName}.vault.azure.net`;
const client = new SecretClient(url, credential);
const secretName = "MySecretName";
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
});
async function main(){
// Create a secret
const result = await client.setSecret(secretName, "MySecretValue");
console.log("Secret name: ", result.name);
// Read the secret we created
const secret = await client.getSecret(secretName);
console.log("Successfully retrieved 'MySecretName':", secret.value);
}
export async function login(): Promise {
const creds = await msRestNodeAuth.loginWithServicePrincipalSecret(clientId, secret, tenant)
const websites = new appservice.WebSiteManagementClient(creds as any, subscriptionId)
return {
websites,
webapps: new appservice.WebApps(websites),
secrets: new SecretClient(`https://majavashakki-vault.vault.azure.net`, new EnvironmentCredential()),
cosmosdb: new cosmosdb.CosmosDBManagementClient(creds as any, subscriptionId),
containerregistry: new ContainerRegistryManagementClient(creds as any, subscriptionId),
}
}