Skip to content

Commit

Permalink
Update to new azure-sdk-for-js (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba authored Aug 26, 2020
1 parent 348bf91 commit ce8b82b
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 301 deletions.
439 changes: 243 additions & 196 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"icon": "resources/resourceGroup.png",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"engines": {
"vscode": "^1.41.0"
"vscode": "^1.48.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -264,8 +264,7 @@
"@types/gulp": "^4.0.6",
"@types/mocha": "^7.0.2",
"@types/node": "^12.0.0",
"@types/request-promise": "^4.1.46",
"@types/vscode": "1.41.0",
"@types/vscode": "1.48.0",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"mocha": "^7.1.1",
Expand All @@ -276,18 +275,17 @@
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "^3.8.3",
"vsce": "^1.71.0",
"vscode-azureextensiondev": "^0.4.0",
"vscode-azureextensiondev": "^0.5.0",
"vscode-test": "^1.3.0",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
},
"dependencies": {
"azure-arm-resource": "^3.0.0-preview",
"@azure/arm-resources": "^3.0.0",
"@azure/ms-rest-js": "^2.0.7",
"fs-extra": "^8.1.0",
"jsonc-parser": "^2.2.1",
"ms-rest": "^2.5.3",
"request-promise": "^4.2.4",
"vscode-azureextensionui": "^0.33.5",
"vscode-azureextensionui": "^0.34.0",
"vscode-nls": "^4.1.1"
},
"extensionDependencies": [
Expand Down
33 changes: 2 additions & 31 deletions src/commands/tags/TagFileSystem.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 { ResourceManagementClient } from "azure-arm-resource";
import { ResourceManagementClient } from "@azure/arm-resources";
import * as jsonc from 'jsonc-parser';
import * as os from "os";
import { commands, Diagnostic, FileStat, FileType, MessageItem, Uri, window } from "vscode";
Expand All @@ -12,7 +12,6 @@ import { ext } from "../../extensionVariables";
import { ResourceGroupTreeItem } from "../../tree/ResourceGroupTreeItem";
import { ResourceTreeItem } from "../../tree/ResourceTreeItem";
import { localize } from "../../utils/localize";
import { requestUtils } from "../../utils/requestUtils";
import { getTagDiagnostics } from "./getTagDiagnostics";

const insertKeyHere: string = localize('insertTagName', '<Insert tag name>');
Expand Down Expand Up @@ -79,11 +78,7 @@ export class TagFileSystem extends AzExtTreeFileSystem<ResourceGroupTreeItem | R
}

const client: ResourceManagementClient = createAzureClient(node.root, ResourceManagementClient);
if (node instanceof ResourceGroupTreeItem) {
await client.resourceGroups.update(node.name, { tags });
} else {
await updateResourceTags(node, tags);
}
await client.tags.updateAtScope(node.id, { properties: { tags }, operation: 'Replace' });

const updatedMessage: string = isResourceGroup ?
localize('updatedTagsGroup', 'Successfully updated tags for resource group "{0}".', node.name) :
Expand All @@ -108,27 +103,3 @@ export class TagFileSystem extends AzExtTreeFileSystem<ResourceGroupTreeItem | R
return `// ${comment}${os.EOL}${JSON.stringify(tags, undefined, 4)}`;
}
}

interface ITagProperties {
properties: {
tags: {};
};
}

/**
* Doesn't seem to be supported for the "azure-arm-resource" npm package. Might be supported in the new "@azure/arm-resource" once we switch over (https://github.com/microsoft/vscode-azuretools/issues/510)
* Docs: https://docs.microsoft.com/rest/api/resources/tags/updateatscope
*/
async function updateResourceTags(node: ResourceTreeItem, tags: {}): Promise<void> {
const urlPath: string = `${node.id}/providers/Microsoft.Resources/tags/default?api-version=2019-10-01`;
const request: requestUtils.Request = await requestUtils.getDefaultAzureRequest(urlPath, node.root, 'PATCH');
request.headers['Content-Type'] = 'application/json';
request.body = JSON.stringify({
operation: 'Replace',
properties: {
tags
}
});
const result: ITagProperties = <ITagProperties>JSON.parse(await requestUtils.sendRequest(request));
node.data.tags = result.properties.tags;
}
8 changes: 4 additions & 4 deletions src/tree/ResourceGroupTreeItem.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 { ResourceManagementClient, ResourceModels } from "azure-arm-resource";
import { ResourceManagementClient, ResourceManagementModels } from "@azure/arm-resources";
import { FileChangeType } from "vscode";
import { AzExtTreeItem, AzureParentTreeItem, createAzureClient, TreeItemIconPath } from "vscode-azureextensionui";
import { ext } from "../extensionVariables";
Expand All @@ -16,13 +16,13 @@ export class ResourceGroupTreeItem extends AzureParentTreeItem {
public static contextValue: string = 'azureResourceGroup';
public readonly contextValue: string = ResourceGroupTreeItem.contextValue;
public readonly childTypeLabel: string = localize('resource', 'Resource');
public data: ResourceModels.ResourceGroup;
public data: ResourceManagementModels.ResourceGroup;
public readonly cTime: number = Date.now();
public mTime: number = Date.now();

private _nextLink: string | undefined;

constructor(parent: AzureParentTreeItem, rg: ResourceModels.ResourceGroup) {
constructor(parent: AzureParentTreeItem, rg: ResourceManagementModels.ResourceGroup) {
super(parent);
this.data = rg;
ext.tagFS.fireSoon({ type: FileChangeType.Changed, item: this });
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ResourceGroupTreeItem extends AzureParentTreeItem {
}

const client: ResourceManagementClient = createAzureClient(this.root, ResourceManagementClient);
const resources: ResourceModels.ResourceListResult = this._nextLink ? await client.resources.listByResourceGroupNext(this._nextLink) : await client.resources.listByResourceGroup(this.name);
const resources: ResourceManagementModels.ResourceListResult = this._nextLink ? await client.resources.listByResourceGroupNext(this._nextLink) : await client.resources.listByResourceGroup(this.name);
this._nextLink = resources.nextLink;
return await this.createTreeItemsWithErrorHandling(
resources,
Expand Down
6 changes: 3 additions & 3 deletions src/tree/ResourceTreeItem.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 { ResourceModels } from "azure-arm-resource";
import { ResourceManagementModels } from "@azure/arm-resources";
import * as path from 'path';
import { FileChangeType } from "vscode";
import { AzureParentTreeItem, AzureTreeItem, TreeItemIconPath } from "vscode-azureextensionui";
Expand All @@ -14,12 +14,12 @@ import { treeUtils } from "../utils/treeUtils";
export class ResourceTreeItem extends AzureTreeItem {
public static contextValue: string = 'azureResource';
public readonly contextValue: string = ResourceTreeItem.contextValue;
public data: ResourceModels.GenericResource;
public data: ResourceManagementModels.GenericResource;
public readonly commandId: string = 'azureResourceGroups.revealResource';
public readonly cTime: number = Date.now();
public mTime: number = Date.now();

constructor(parent: AzureParentTreeItem, resource: ResourceModels.GenericResource) {
constructor(parent: AzureParentTreeItem, resource: ResourceManagementModels.GenericResource) {
super(parent);
this.data = resource;
ext.tagFS.fireSoon({ type: FileChangeType.Changed, item: this });
Expand Down
4 changes: 2 additions & 2 deletions src/tree/SubscriptionTreeItem.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 { ResourceManagementClient, ResourceModels } from 'azure-arm-resource';
import { ResourceManagementClient, ResourceManagementModels } from '@azure/arm-resources';
import { AzExtTreeItem, AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, createAzureClient, ICreateChildImplContext, IResourceGroupWizardContext, LocationListStep, ResourceGroupCreateStep, ResourceGroupNameStep, SubscriptionTreeItemBase } from 'vscode-azureextensionui';
import { localize } from '../utils/localize';
import { nonNullProp } from '../utils/nonNull';
Expand All @@ -24,7 +24,7 @@ export class SubscriptionTreeItem extends SubscriptionTreeItemBase {
}

const client: ResourceManagementClient = createAzureClient(this.root, ResourceManagementClient);
const rgs: ResourceModels.ResourceGroupListResult = this._nextLink ? await client.resourceGroups.listNext(this._nextLink) : await client.resourceGroups.list();
const rgs: ResourceManagementModels.ResourceGroupListResult = this._nextLink ? await client.resourceGroups.listNext(this._nextLink) : await client.resourceGroups.list();
this._nextLink = rgs.nextLink;
return await this.createTreeItemsWithErrorHandling(
rgs,
Expand Down
56 changes: 0 additions & 56 deletions src/utils/requestUtils.ts

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"node_modules/@types/*",
"*"
]
}
},
"skipLibCheck": true // https://github.com/Azure/ms-rest-js/issues/367
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit ce8b82b

Please sign in to comment.