Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getStorageAccountKey(subscriptionId: string, resourceGroupName: string, accountName: string, credentials: ServiceClientCredentials) {
const context = new StorageManagementClientContext(this.credentials, subscriptionId);
const storageAccounts = new StorageAccounts(context);
const accounts = await storageAccounts.list();
if (!accounts.find((account) => account.name === accountName)) {
throw new Error(`Couldn't find storage account with name ${accountName}`);
}
const { keys } = await storageAccounts.listKeys(resourceGroupName, accountName);
return keys[0].value;
}
}
private async getKey(): Promise {
const context = new StorageManagementClientContext(this.credentials, this.subscriptionId)
const storageAccounts = new StorageAccounts(context);
const keys = await storageAccounts.listKeys(this.resourceGroup, this.storageAccountName);
return keys.keys[0].value;
}