@microsoft/vscode-azext-azureutils
Advanced tools
Comparing version
@@ -12,6 +12,7 @@ /*--------------------------------------------------------------------------------------------- | ||
import type { PagedAsyncIterableIterator } from '@azure/core-paging'; | ||
import { Disposable, Progress } from 'vscode'; | ||
import { Disposable, Progress, Uri } from 'vscode'; | ||
import type { AzExtParentTreeItem, AzExtServiceClientCredentials, AzExtServiceClientCredentialsT1, AzExtServiceClientCredentialsT2, AzExtTreeItem, AzureNameStep, AzureWizardExecuteStep, AzureWizardPromptStep, IActionContext, IAzureNamingRules, IAzureQuickPickItem, IAzureQuickPickOptions, IRelatedNameWizardContext, ISubscriptionActionContext, ISubscriptionContext, IWizardOptions, UIExtensionVariables } from '@microsoft/vscode-azext-utils'; | ||
import { ExtendedLocation, ResourceGroup } from '@azure/arm-resources'; | ||
import type { StorageAccount } from '@azure/arm-storage'; | ||
import type { AzureSubscription } from '@microsoft/vscode-azureresources-api'; | ||
@@ -433,1 +434,3 @@ export type OpenInPortalOptions = { | ||
export function getResourceGroupFromId(id: string): string; | ||
export declare function createPortalUri(subscription: AzureSubscription, id: string, options?: OpenInPortalOptions): Uri; |
@@ -26,2 +26,3 @@ "use strict"; | ||
__exportStar(require("./tree/SubscriptionTreeItemBase"), exports); | ||
__exportStar(require("./utils/createPortalUri"), exports); | ||
__exportStar(require("./utils/parseAzureResourceId"), exports); | ||
@@ -28,0 +29,0 @@ __exportStar(require("./utils/uiUtils"), exports); |
@@ -22,6 +22,3 @@ "use strict"; | ||
const localize_1 = require("../localize"); | ||
const randomUtils_1 = require("../utils/randomUtils"); | ||
const LocationListStep_1 = require("./LocationListStep"); | ||
const ResourceGroupListStep_1 = require("./ResourceGroupListStep"); | ||
const StorageAccountListStep_1 = require("./StorageAccountListStep"); | ||
class StorageAccountCreateStep extends vscode_azext_utils_1.AzureWizardExecuteStep { | ||
@@ -37,3 +34,3 @@ constructor(defaults) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const newName = yield this.generateRelatedName(wizardContext, wizardContext.newStorageAccountName, StorageAccountListStep_1.storageAccountNamingRules); | ||
const newName = wizardContext.newStorageAccountName; | ||
const newSkuName = `${this._defaults.performance}_${this._defaults.replication}`; | ||
@@ -50,3 +47,5 @@ const creatingStorageAccount = (0, localize_1.localize)('CreatingStorageAccount', 'Creating storage account "{0}" in location "{1}" with sku "{2}"...', newName, newLocation, newSkuName); | ||
location: newLocation, | ||
enableHttpsTrafficOnly: true | ||
enableHttpsTrafficOnly: true, | ||
defaultToOAuthAuthentication: true, | ||
allowBlobPublicAccess: false, | ||
}); | ||
@@ -57,48 +56,2 @@ const createdStorageAccount = (0, localize_1.localize)('CreatedStorageAccount', 'Successfully created storage account "{0}".', newName); | ||
} | ||
generateRelatedName(wizardContext, name, namingRules) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!Array.isArray(namingRules)) { | ||
namingRules = [namingRules]; | ||
} | ||
let preferredName = namingRules.some((n) => !!n.lowercaseOnly) ? name.toLowerCase() : name; | ||
for (let invalidCharsRegExp of namingRules.map((n) => n.invalidCharsRegExp)) { | ||
// Ensure the regExp uses the 'g' flag to replace _all_ invalid characters | ||
invalidCharsRegExp = new RegExp(invalidCharsRegExp, 'g'); | ||
preferredName = preferredName.replace(invalidCharsRegExp, ''); | ||
} | ||
const minLength = Math.max(...namingRules.map((n) => n.minLength)); | ||
const maxLength = Math.min(...namingRules.map((n) => n.maxLength)); | ||
const maxTries = 5; | ||
let count = 0; | ||
let newName; | ||
while (count < maxTries) { | ||
newName = this.generateSuffixedName(preferredName, minLength, maxLength); | ||
if (yield this.isRelatedNameAvailable(wizardContext, newName)) { | ||
return newName; | ||
} | ||
count += 1; | ||
} | ||
return undefined; | ||
}); | ||
} | ||
isRelatedNameAvailable(wizardContext, name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield ResourceGroupListStep_1.ResourceGroupListStep.isNameAvailable(wizardContext, name); | ||
}); | ||
} | ||
generateSuffixedName(preferredName, minLength, maxLength) { | ||
const suffix = randomUtils_1.randomUtils.getRandomHexString(); | ||
const minUnsuffixedLength = minLength - suffix.length; | ||
const maxUnsuffixedLength = maxLength - suffix.length; | ||
let unsuffixedName = preferredName; | ||
if (unsuffixedName.length > maxUnsuffixedLength) { | ||
unsuffixedName = preferredName.slice(0, maxUnsuffixedLength); | ||
} | ||
else { | ||
while (unsuffixedName.length < minUnsuffixedLength) { | ||
unsuffixedName += preferredName; | ||
} | ||
} | ||
return unsuffixedName + suffix; | ||
} | ||
shouldExecute(wizardContext) { | ||
@@ -105,0 +58,0 @@ return !wizardContext.storageAccount; |
{ | ||
"name": "@microsoft/vscode-azext-azureutils", | ||
"author": "Microsoft Corporation", | ||
"version": "0.3.8", | ||
"version": "0.3.9-beta", | ||
"description": "Common Azure utils for developing Azure extensions for VS Code", | ||
@@ -32,3 +32,4 @@ "tags": [ | ||
"pretest": "npm run build", | ||
"test": "node ./out/test/runTest.js" | ||
"test": "node ./out/test/runTest.js", | ||
"package": "npm pack" | ||
}, | ||
@@ -42,3 +43,3 @@ "dependencies": { | ||
"@azure/ms-rest-js": "^2.2.1", | ||
"@microsoft/vscode-azext-utils": "^0.4.0", | ||
"@microsoft/vscode-azext-utils": "^0.4.3", | ||
"semver": "^7.3.7", | ||
@@ -51,4 +52,5 @@ "vscode-nls": "^5.0.1" | ||
"@azure/ms-rest-nodeauth": "^3.1.1", | ||
"@microsoft/eslint-config-azuretools": "^0.1.0", | ||
"@microsoft/vscode-azext-dev": "^0.1.4", | ||
"@microsoft/eslint-config-azuretools": "^0.2.0", | ||
"@microsoft/vscode-azext-dev": "^0.2.0", | ||
"@microsoft/vscode-azureresources-api": "^2.0.3", | ||
"@types/mocha": "^7.0.2", | ||
@@ -58,5 +60,5 @@ "@types/node": "^14.0.0", | ||
"@types/vscode": "1.64.0", | ||
"@typescript-eslint/eslint-plugin": "^4.28.3", | ||
"@typescript-eslint/eslint-plugin": "^5.53.0", | ||
"@vscode/test-electron": "^2.1.5", | ||
"eslint": "^7.19.0", | ||
"eslint": "^8.34.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -63,0 +65,0 @@ "glob": "^7.1.6", |
31
3.33%129822
-0.86%19
5.56%2087
-1.42%