in src/commands/periscope/helpers/periscopehelper.ts [21:78]
export async function getStorageInfo(
sessionProvider: ReadyAzureSessionProvider,
kubectl: k8s.APIAvailable<k8s.KubectlV1>,
clusterNode: AksClusterTreeNode,
diagnosticStorageAccountId: string,
clusterKubeConfig: string,
): Promise<Errorable<PeriscopeStorage>> {
try {
const { resourceGroupName, name: accountName } = parseResource(diagnosticStorageAccountId);
if (!resourceGroupName || !accountName) {
return {
succeeded: false,
error: `Invalid storage id ${diagnosticStorageAccountId} associated with the cluster`,
};
}
// Get keys from storage client.
const storageClient = getStorageManagementClient(sessionProvider, clusterNode.subscriptionId);
const storageAccKeyList = await storageClient.storageAccounts.listKeys(resourceGroupName, accountName);
if (storageAccKeyList.keys === undefined) {
return { succeeded: false, error: "No keys found for storage account." };
}
const storageKeyObject = storageAccKeyList.keys.find((it) => it.keyName === "key1");
if (storageKeyObject === undefined) {
return { succeeded: false, error: "No key with name 'key1' found for storage account." };
}
const storageKey = storageKeyObject.value;
if (storageKey === undefined) {
return { succeeded: false, error: "Storage key with name 'key1' has no value." };
}
const acctProperties = await storageClient.storageAccounts.getProperties(resourceGroupName, accountName);
const blobEndpoint = acctProperties.primaryEndpoints?.blob;
if (blobEndpoint === undefined) {
return { succeeded: false, error: "Unable to retrieve blob endpoint from storage account." };
}
// Get container name from cluster-info default behaviour was APIServerName without
const containerName = await extractContainerName(kubectl, clusterKubeConfig);
if (failed(containerName)) return containerName;
const clusterStorageInfo = {
containerName: containerName.result,
storageName: accountName,
storageKey: storageKey,
blobEndpoint,
storageDeploymentSas: getSASKey(accountName, storageKey, LinkDuration.DownloadNow),
sevenDaysSasKey: getSASKey(accountName, storageKey, LinkDuration.Shareable),
};
return { succeeded: true, result: clusterStorageInfo };
} catch (e) {
return { succeeded: false, error: `Storage associated with cluster had following error: ${e}` };
}
}