Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function listResourceGroups(creds: AzureCliCredentials): Promise {
function getUrl(subscriptionId: string): string {
return `https://management.azure.com/subscriptions/${subscriptionId}/resourcegroups?api-version=2018-05-01`;
}
try {
console.log(">>>>>>> List Resource groups <<<<<<<<<<<");
// Setting the resource to ARM endpoint.
creds.resource = "https://management.azure.com";
const client = new ServiceClient(creds);
console.log(">>> Subscription associated with the access token: '%s'.",
creds.tokenInfo.subscription);
const request: RequestPrepareOptions = {
url: getUrl(creds.subscriptionInfo.id),
method: "GET"
};
console.log(">>> Request url: '%s'.", request.url);
const res = await client.sendRequest(request);
console.log("List of resource groups from subscriptionId '%s': \n%O",
creds.subscriptionInfo.id, res.parsedBody);
// Let us change the subscriptionId, which should trigger refreshing the access token.
const subscriptions = await AzureCliCredentials.listAllSubscriptions();
creds.subscriptionInfo = subscriptions[1];
console.log(">>> The new subscription id associated with the credential object is: '%s'.",
creds.subscriptionInfo.id);
async function listKeyVaultSecrets(creds: AzureCliCredentials): Promise {
function getKVUrl(kvAccountName: string): string {
return `https://${kvAccountName}.vault.azure.net/secrets?api-version=7.0`;
}
try {
console.log(">>>>>>> KeyVault <<<<<<<<<<<");
const client = new ServiceClient(creds);
console.log(">>> Subscription associated with the access token: '%s'.",
creds.tokenInfo.subscription);
const request: RequestPrepareOptions = {
url: getKVUrl(keyvaultAccountName),
method: "GET"
};
console.log(">>> Request url: '%s'.", request.url);
const res = await client.sendRequest(request);
console.log("List of secrets from keyvault account '%s': \n%O",
keyvaultAccountName, res.parsedBody);
} catch (err) {
console.log(err);
}
}