Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensuring we are checking the storage accounts on the whole subscripti… #65

Merged
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/util/azure/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { StorageManagementClient } from '@azure/arm-storage';
import { filteredList, ListItem, newItemPrompt } from '../prompt/list';
import { newItemPrompt } from '../prompt/list';
import { Aborter, ServiceURL, SharedKeyCredential } from '@azure/storage-blob';
import { DeviceTokenCredentials } from '@azure/ms-rest-nodeauth';
import { AddOptions, Logger } from '../shared/types';
Expand All @@ -12,17 +12,6 @@ import { ResourceGroup } from './resource-group';
import { generateName } from '../prompt/name-generator';
import { spinner } from '../prompt/spinner';

interface AccountDetails extends ListItem {
id: string;
name: string;
location: string;
}

const accountPromptOptions = {
id: 'account',
message: 'Under which storage account should we put this static site?'
};

const newAccountPromptOptions = {
id: 'newAccount',
message: 'Enter a name for the new storage account:',
Expand All @@ -46,7 +35,8 @@ export async function getAccount(
let needToCreateAccount = false;

spinner.start('Fetching storage accounts');
const accounts = await client.storageAccounts.listByResourceGroup(resourceGroup.name);
// const accounts = await client.storageAccounts.listByResourceGroup(resourceGroup.name);
const accounts = await client.storageAccounts;
spinner.stop();

function getInitialAccountName() {
Expand All @@ -64,8 +54,9 @@ export async function getAccount(
newAccountPromptOptions.validate = validateAccountName;

if (accountName) {
const account = accounts.find(acc => acc.name === accountName);
if (!!account) {
const result = await accounts.checkNameAvailability(accountName);

if (!result.nameAvailable) {
// account exists
// TODO: check account configuration
logger.info(`Using existing account ${accountName}`);
Expand All @@ -82,13 +73,16 @@ export async function getAccount(

if (!options.manual) {
// quickstart - create w/ default name

accountName = await generateDefaultAccountName(initialName);
needToCreateAccount = true;
} else {
// select from list or create new
const result = await filteredList(accounts as AccountDetails[], accountPromptOptions, newAccountPromptOptions);
needToCreateAccount = !!result.newAccount;
accountName = result.newAccount || result.account.name;
const availableResult = await client.storageAccounts.checkNameAvailability(accountName);

if (!availableResult.nameAvailable) {
logger.info(`Account ${accountName} already exist on subscription`);
logger.info(`Using existing account ${accountName}`);
manekinekko marked this conversation as resolved.
Show resolved Hide resolved
} else {
needToCreateAccount = true;
}
}
}

Expand Down