export async function chooseStorageAccount()

in src/commands/utils/clusters.ts [769:821]


export async function chooseStorageAccount(
    diagnosticSettings: DiagnosticSettingsResourceCollection,
    placeholderText: string,
): Promise<string | void> {
    /*
        Check the diagnostic setting is 1 or more than 1:
          1. For the scenario of 1 storage account in diagnostic settings - Pick the storageId resource and get SAS.
          2. For the scenario for more than 1 then show VsCode quickPick to select and get SAS of selected.
    */
    if (!diagnosticSettings || !diagnosticSettings.value) return undefined;

    if (diagnosticSettings.value.length === 1) {
        // In case of only one storage account associated, use the one (1) as default storage account
        const selectedStorageAccount = diagnosticSettings.value![0].storageAccountId!;
        if (!selectedStorageAccount) {
            vscode.window.showInformationMessage("Diagnostic setting does not have storage account associated.");
            return;
        }
        const storageAccountName = parseResource(selectedStorageAccount).name;
        if (!storageAccountName) {
            vscode.window.showInformationMessage(`Storage ID is malformed: ${selectedStorageAccount}`);
            return;
        }
        vscode.window.showInformationMessage(`Using the only available storage account: ${storageAccountName}`);
        return selectedStorageAccount;
    }

    const storageAccountNameToStorageIdArray: { id: string; label: string }[] = [];

    diagnosticSettings.value?.forEach((item) => {
        if (item.storageAccountId) {
            const { name } = parseResource(item.storageAccountId!);
            if (!name) {
                vscode.window.showInformationMessage(`Storage Id is malformed: ${item.storageAccountId}`);
                return;
            }
            storageAccountNameToStorageIdArray.push({ id: item.storageAccountId, label: name });
        }
    });

    // accounts is now an array of {id, name}
    const accountQuickPicks = storageAccountNameToStorageIdArray;

    // Create quick pick for more than 1 storage account scenario.
    const selectedQuickPick = await vscode.window.showQuickPick(accountQuickPicks, {
        placeHolder: placeholderText,
        ignoreFocusOut: true,
    });

    if (selectedQuickPick) {
        return selectedQuickPick.id;
    }
}