support for products (#17)
This commit is contained in:
Родитель
cf848346ab
Коммит
f2a302a86b
38
package.json
38
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "vscode-apimanagement",
|
||||
"displayName": "Azure API Managment",
|
||||
"description": "An Azure API Management extension for Visual Studio Code.",
|
||||
"version": "0.1.0-alpha",
|
||||
"version": "0.1.1-alpha",
|
||||
"publisher": "ms-azuretools",
|
||||
"icon": "resources/azure-apim.png",
|
||||
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
|
||||
|
@ -45,9 +45,13 @@
|
|||
"onCommand:azureApiManagement.showApi",
|
||||
"onCommand:azureApiManagement.showArmApi",
|
||||
"onCommand:azureApiManagement.showArmApiOperation",
|
||||
"onCommand:azureApiManagement.showArmProduct",
|
||||
"onCommand:azureApiManagement.showServicePolicy",
|
||||
"onCommand:azureApiManagement.showApiPolicy",
|
||||
"onCommand:azureApiManagement.showOperationPolicy"
|
||||
"onCommand:azureApiManagement.showOperationPolicy",
|
||||
"onCommand:azureApiManagement.addApiToProduct",
|
||||
"onCommand:azureApiManagement.removeApiFromProduct",
|
||||
"onCommand:azureApiManagement.showProductPolicy"
|
||||
],
|
||||
"main": "main",
|
||||
"contributes": {
|
||||
|
@ -154,6 +158,11 @@
|
|||
"title": "%azureApiManagement.showArmApiOperation%",
|
||||
"category": "Azure API Management"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.showArmProduct",
|
||||
"title": "%azureApiManagement.showArmProduct%",
|
||||
"category": "Azure API Management"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.showServicePolicy",
|
||||
"title": "%azureApiManagement.showServicePolicy%",
|
||||
|
@ -168,6 +177,21 @@
|
|||
"command": "azureApiManagement.showOperationPolicy",
|
||||
"title": "%azureApiManagement.showOperationPolicy%",
|
||||
"category": "Azure API Management"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.addApiToProduct",
|
||||
"title": "%azureApiManagement.addApiToProduct%",
|
||||
"category": "Azure API Management"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.removeApiFromProduct",
|
||||
"title": "%azureApiManagement.removeApiFromProduct%",
|
||||
"category": "Azure API Management"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.showProductPolicy",
|
||||
"title": "%azureApiManagement.showProductPolicy%",
|
||||
"category": "Azure API Management"
|
||||
}
|
||||
],
|
||||
"viewsContainers": {
|
||||
|
@ -292,6 +316,16 @@
|
|||
"command": "azureApiManagement.testOperation",
|
||||
"when": "view == azureApiManagementExplorer && viewItem == azureApiManagementApiOperation",
|
||||
"group": "1@1"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.addApiToProduct",
|
||||
"when": "view == azureApiManagementExplorer && viewItem == azureApiManagementProductApis",
|
||||
"group": "1@1"
|
||||
},
|
||||
{
|
||||
"command": "azureApiManagement.removeApiFromProduct",
|
||||
"when": "view == azureApiManagementExplorer && viewItem == azureApiManagementProductApi",
|
||||
"group": "1@1"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -16,5 +16,9 @@
|
|||
"azureApiManagement.deleteApi": "Delete API",
|
||||
"azureApiManagement.deleteOperation": "Delete Operation",
|
||||
"azureApiManagement.testOperation": "Test Operation",
|
||||
"azureApiManagement.advancedCreationDescription":"Enables advanced creation of Azure API Management Instance, which will prompt for several additional values instead of using a default."
|
||||
"azureApiManagement.advancedCreationDescription":"Enables advanced creation of Azure API Management Instance, which will prompt for several additional values instead of using a default.",
|
||||
"azureApiManagement.addApiToProduct": "Add API to Product",
|
||||
"azureApiManagement.removeApiFromProduct": "Remove API from Product",
|
||||
"azureApiManagement.showProductPolicy": "Edit Product policy",
|
||||
"azureApiManagement.showArmProduct": "Edit Product"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
|
||||
<path d="M24.89,48.95,2.34,42.2A3.57,3.57,0,0,1,0,39.29v-29C0,8.76,1.46,7.82,2.93,7.42L25.55,0.95c.18,0,.9.18.9.37l1.43,47.28A4.66,4.66,0,0,1,24.89,48.95Z" fill="#3796c4"/>
|
||||
<path d="M48,42.29,27.37,48.85a1.66,1.66,0,0,1-2.18-1.64V1.53A.58.58,0,0,1,25.94,0.95L48,8.29c1,.3,2,1,2,1.91V39.95A2.41,2.41,0,0,1,48,42.29Zm-1-30-17-5v36l17-5Z" fill="#59b2d7"/>
|
||||
<polygon points="41.39 28.37 37.55 28.37 37.55 14.28 41.39 15.07" fill="#7fba00"/>
|
||||
<polygon points="43.32 27.81 35.41 28.16 39.54 36.4" fill="#7fba00"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 620 B |
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
|
||||
<path d="M24.89,48.95,2.34,42.2A3.57,3.57,0,0,1,0,39.29v-29C0,8.76,1.46,7.82,2.93,7.42L25.55,0.95c.18,0,.9.18.9.37l1.43,47.28A4.66,4.66,0,0,1,24.89,48.95Z" fill="#3796c4"/>
|
||||
<path d="M48,42.29,27.37,48.85a1.66,1.66,0,0,1-2.18-1.64V1.53A.58.58,0,0,1,25.94,0.95L48,8.29c1,.3,2,1,2,1.91V39.95A2.41,2.41,0,0,1,48,42.29Zm-1-30-17-5v36l17-5Z" fill="#59b2d7"/>
|
||||
<polygon points="41.39 28.37 37.55 28.37 37.55 14.28 41.39 15.07" fill="#7fba00"/>
|
||||
<polygon points="43.32 27.81 35.41 28.16 39.54 36.4" fill="#7fba00"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 620 B |
|
@ -0,0 +1,44 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ProgressLocation, window } from "vscode";
|
||||
import { ApiTreeItem } from "../explorer/ApiTreeItem";
|
||||
import { ProductApisTreeItem } from "../explorer/ProductApisTreeItem";
|
||||
import { ProductsTreeItem } from "../explorer/ProductsTreeItem";
|
||||
import { ProductTreeItem } from "../explorer/ProductTreeItem";
|
||||
import { ServiceTreeItem } from "../explorer/ServiceTreeItem";
|
||||
import { ext } from "../extensionVariables";
|
||||
import { localize } from "../localize";
|
||||
import { nonNullProp } from "../utils/nonNull";
|
||||
|
||||
// tslint:disable: no-any
|
||||
export async function addApiToProduct(node?: ProductApisTreeItem): Promise<void> {
|
||||
let productNode: ProductTreeItem;
|
||||
if (!node) {
|
||||
productNode = <ProductTreeItem>await ext.tree.showTreeItemPicker(ProductTreeItem.contextValue);
|
||||
node = productNode.productApisTreeItem;
|
||||
} else {
|
||||
productNode = <ProductTreeItem>node.parent;
|
||||
}
|
||||
|
||||
const serviceTreeItem = <ServiceTreeItem>(<ProductsTreeItem><unknown>productNode.parent).parent;
|
||||
|
||||
const apiTreeItem = <ApiTreeItem>await ext.tree.showTreeItemPicker(ApiTreeItem.contextValue, serviceTreeItem);
|
||||
|
||||
const apiName = nonNullProp(apiTreeItem.apiContract, "name");
|
||||
window.withProgress(
|
||||
{
|
||||
location: ProgressLocation.Notification,
|
||||
title: localize("addApiToProduct", `Adding API '${apiName}' to product ${node.root.productName} ...`),
|
||||
cancellable: false
|
||||
},
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
async () => { return node!.createChild({ apiName: apiName}); }
|
||||
).then(async () => {
|
||||
// tslint:disable:no-non-null-assertion
|
||||
await node!.refresh();
|
||||
window.showInformationMessage(localize("addedApiToProduct", `Added API '${apiName}' to product ${node!.root.productName}.`));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IServiceTreeRoot } from "./IServiceTreeRoot";
|
||||
|
||||
export interface IProductTreeRoot extends IServiceTreeRoot {
|
||||
productName: string;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { ProgressLocation, window } from "vscode";
|
||||
import { AzureParentTreeItem, AzureTreeItem, DialogResponses, UserCancelledError } from "vscode-azureextensionui";
|
||||
import { localize } from "../localize";
|
||||
import { nonNullProp } from "../utils/nonNull";
|
||||
import { treeUtils } from "../utils/treeUtils";
|
||||
import { IProductTreeRoot } from "./IProductTreeRoot";
|
||||
|
||||
export class ProductApiTreeItem extends AzureTreeItem<IProductTreeRoot> {
|
||||
public static contextValue: string = 'azureApiManagementProductApi';
|
||||
public contextValue: string = ProductApiTreeItem.contextValue;
|
||||
private _label: string;
|
||||
|
||||
constructor(
|
||||
parent: AzureParentTreeItem,
|
||||
public readonly productApiContract: ApiManagementModels.ApiContract) {
|
||||
super(parent);
|
||||
this._label = nonNullProp(productApiContract, 'displayName');
|
||||
}
|
||||
|
||||
public get label() : string {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
public get iconPath(): { light: string, dark: string } {
|
||||
return treeUtils.getThemedIconPath('api');
|
||||
}
|
||||
|
||||
public async deleteTreeItemImpl(): Promise<void> {
|
||||
const message: string = localize("confirmProductAPIRemove", `Are you sure you want to remove API '${this.productApiContract.displayName}' from product '${this.root.productName}'?`);
|
||||
const result = await window.showWarningMessage(message, { modal: true }, DialogResponses.deleteResponse, DialogResponses.cancel);
|
||||
if (result === DialogResponses.deleteResponse) {
|
||||
const deletingMessage: string = localize("removingProductAPI", `Removing API "${this.productApiContract.displayName}" from product '${this.root.productName}.'`);
|
||||
await window.withProgress({ location: ProgressLocation.Notification, title: deletingMessage }, async () => {
|
||||
await this.root.client.productApi.deleteMethod(this.root.resourceGroupName, this.root.serviceName, this.root.productName, nonNullProp(this.productApiContract, "name"));
|
||||
});
|
||||
// don't wait
|
||||
window.showInformationMessage(localize("removedProduct", `Successfully removed API "${this.productApiContract.displayName}" from product '${this.root.productName}'.`));
|
||||
|
||||
} else {
|
||||
throw new UserCancelledError();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { AzureParentTreeItem, AzureTreeItem, createTreeItemsWithErrorHandling } from "vscode-azureextensionui";
|
||||
import { topItemCount } from "../constants";
|
||||
import { localize } from "../localize";
|
||||
import { processError } from "../utils/errorUtil";
|
||||
import { treeUtils } from "../utils/treeUtils";
|
||||
import { IProductTreeRoot } from "./IProductTreeRoot";
|
||||
import { ProductApiTreeItem } from "./ProductApiTreeItem";
|
||||
|
||||
export class ProductApisTreeItem extends AzureParentTreeItem<IProductTreeRoot> {
|
||||
public get iconPath(): { light: string, dark: string } {
|
||||
return treeUtils.getThemedIconPath('list');
|
||||
}
|
||||
public static contextValue: string = 'azureApiManagementProductApis';
|
||||
public label: string = "Apis";
|
||||
public contextValue: string = ProductApisTreeItem.contextValue;
|
||||
public readonly childTypeLabel: string = localize('azureApiManagement.ProductApi', 'Product API');
|
||||
private _nextLink: string | undefined;
|
||||
|
||||
public hasMoreChildrenImpl(): boolean {
|
||||
return this._nextLink !== undefined;
|
||||
}
|
||||
|
||||
public async loadMoreChildrenImpl(clearCache: boolean): Promise<AzureTreeItem<IProductTreeRoot>[]> {
|
||||
if (clearCache) {
|
||||
this._nextLink = undefined;
|
||||
}
|
||||
|
||||
const productApisCollection: ApiManagementModels.ApiCollection = this._nextLink === undefined ?
|
||||
await this.root.client.productApi.listByProduct(this.root.resourceGroupName, this.root.serviceName, this.root.productName, {top: topItemCount}) :
|
||||
await this.root.client.productApi.listByProductNext(this._nextLink);
|
||||
|
||||
this._nextLink = productApisCollection.nextLink;
|
||||
|
||||
return createTreeItemsWithErrorHandling(
|
||||
this,
|
||||
productApisCollection,
|
||||
"invalidApiManagementProductApi",
|
||||
async (api: ApiManagementModels.ApiContract) => new ProductApiTreeItem(this, api),
|
||||
(api: ApiManagementModels.ApiContract) => {
|
||||
return api.name;
|
||||
});
|
||||
}
|
||||
|
||||
public async createChildImpl(showCreatingTreeItem: (label: string) => void, userOptions?: { apiName: string }): Promise<ProductApiTreeItem> {
|
||||
if (userOptions && userOptions.apiName) {
|
||||
const apiName = userOptions.apiName;
|
||||
showCreatingTreeItem(apiName);
|
||||
|
||||
try {
|
||||
const product = await this.root.client.productApi.createOrUpdate(this.root.resourceGroupName, this.root.serviceName, this.root.productName, apiName);
|
||||
return new ProductApiTreeItem(this, product);
|
||||
} catch (error) {
|
||||
throw new Error(processError(error, localize("addApiToProductFailed", `Failed to add '${apiName}' to product '${this.root.productName}'.`)));
|
||||
}
|
||||
} else {
|
||||
throw Error("Expected API name.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AzureTreeItem } from "vscode-azureextensionui";
|
||||
import { treeUtils } from "../utils/treeUtils";
|
||||
import { IProductTreeRoot } from "./IProductTreeRoot";
|
||||
|
||||
export class ProductPolicyTreeItem extends AzureTreeItem<IProductTreeRoot> {
|
||||
|
||||
public get iconPath(): { light: string, dark: string } {
|
||||
return treeUtils.getThemedIconPath('policy');
|
||||
}
|
||||
public static contextValue: string = 'azureApiManagementProductPolicy';
|
||||
public label: string = "Policy";
|
||||
public contextValue: string = ProductPolicyTreeItem.contextValue;
|
||||
public readonly commandId: string = 'azureApiManagement.showProductPolicy';
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { AzureParentTreeItem, AzureTreeItem, ISubscriptionRoot } from "vscode-azureextensionui";
|
||||
import { nonNullProp } from "../utils/nonNull";
|
||||
import { treeUtils } from "../utils/treeUtils";
|
||||
import { IProductTreeRoot } from "./IProductTreeRoot";
|
||||
import { IServiceTreeRoot } from "./IServiceTreeRoot";
|
||||
import { ProductApisTreeItem } from "./ProductApisTreeItem";
|
||||
import { ProductPolicyTreeItem } from "./ProductPolicyTreeItem";
|
||||
import { ProductsTreeItem } from "./ProductsTreeItem";
|
||||
|
||||
export class ProductTreeItem extends AzureParentTreeItem<IProductTreeRoot> {
|
||||
public static contextValue: string = 'azureApiManagementProductTreeItem';
|
||||
public contextValue: string = ProductTreeItem.contextValue;
|
||||
public readonly commandId: string = 'azureApiManagement.showArmProduct';
|
||||
public readonly policyTreeItem: ProductPolicyTreeItem;
|
||||
public readonly productApisTreeItem: ProductApisTreeItem;
|
||||
|
||||
private _label: string;
|
||||
private _root: IProductTreeRoot;
|
||||
|
||||
constructor(
|
||||
parent: ProductsTreeItem,
|
||||
public readonly productContract: ApiManagementModels.ProductContract) {
|
||||
super(parent);
|
||||
this._label = nonNullProp(this.productContract, 'displayName');
|
||||
this._root = this.createRoot(parent.root);
|
||||
|
||||
this.productApisTreeItem = new ProductApisTreeItem(this);
|
||||
this.policyTreeItem = new ProductPolicyTreeItem(this);
|
||||
}
|
||||
|
||||
public get label() : string {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
public get root(): IProductTreeRoot {
|
||||
return this._root;
|
||||
}
|
||||
|
||||
public get iconPath(): { light: string, dark: string } {
|
||||
return treeUtils.getThemedIconPath('product');
|
||||
}
|
||||
|
||||
public hasMoreChildrenImpl(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public async loadMoreChildrenImpl(): Promise<AzureTreeItem<IProductTreeRoot>[]> {
|
||||
return [this.productApisTreeItem, this.policyTreeItem];
|
||||
}
|
||||
|
||||
private createRoot(subRoot: ISubscriptionRoot): IProductTreeRoot {
|
||||
return Object.assign({}, <IServiceTreeRoot>subRoot, {
|
||||
productName: nonNullProp(this.productContract, 'name')
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { AzureParentTreeItem, AzureTreeItem, createTreeItemsWithErrorHandling } from "vscode-azureextensionui";
|
||||
import { topItemCount } from "../constants";
|
||||
import { treeUtils } from "../utils/treeUtils";
|
||||
import { IServiceTreeRoot } from "./IServiceTreeRoot";
|
||||
import { ProductTreeItem } from "./ProductTreeItem";
|
||||
|
||||
export class ProductsTreeItem extends AzureParentTreeItem<IServiceTreeRoot> {
|
||||
public get iconPath(): { light: string, dark: string } {
|
||||
return treeUtils.getThemedIconPath('list');
|
||||
}
|
||||
public static contextValue: string = 'azureApiManagementProducts';
|
||||
public label: string = "Products";
|
||||
public contextValue: string = ProductsTreeItem.contextValue;
|
||||
private _nextLink: string | undefined;
|
||||
|
||||
public hasMoreChildrenImpl(): boolean {
|
||||
return this._nextLink !== undefined;
|
||||
}
|
||||
|
||||
public async loadMoreChildrenImpl(clearCache: boolean): Promise<AzureTreeItem<IServiceTreeRoot>[]> {
|
||||
if (clearCache) {
|
||||
this._nextLink = undefined;
|
||||
}
|
||||
|
||||
const productCollection: ApiManagementModels.ProductCollection = this._nextLink === undefined ?
|
||||
await this.root.client.product.listByService(this.root.resourceGroupName, this.root.serviceName, {top: topItemCount}) :
|
||||
await this.root.client.product.listByServiceNext(this._nextLink);
|
||||
|
||||
this._nextLink = productCollection.nextLink;
|
||||
|
||||
return createTreeItemsWithErrorHandling(
|
||||
this,
|
||||
productCollection,
|
||||
"invalidApiManagementProduct",
|
||||
async (product: ApiManagementModels.ProductContract) => new ProductTreeItem(this, product),
|
||||
(product: ApiManagementModels.ProductContract) => {
|
||||
return product.name;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -16,6 +16,9 @@ import { ApisTreeItem } from "./ApisTreeItem";
|
|||
import { ApiTreeItem } from "./ApiTreeItem";
|
||||
import { IServiceTreeRoot } from "./IServiceTreeRoot";
|
||||
import { OperationPolicyTreeItem } from "./OperationPolicyTreeItem";
|
||||
import { ProductPolicyTreeItem } from "./ProductPolicyTreeItem";
|
||||
import { ProductsTreeItem } from "./ProductsTreeItem";
|
||||
import { ProductTreeItem } from "./ProductTreeItem";
|
||||
import { ServicePolicyTreeItem } from "./ServicePolicyTreeItem";
|
||||
|
||||
export class ServiceTreeItem extends AzureParentTreeItem<IServiceTreeRoot> {
|
||||
|
@ -36,6 +39,7 @@ export class ServiceTreeItem extends AzureParentTreeItem<IServiceTreeRoot> {
|
|||
public contextValue: string = ServiceTreeItem.contextValue;
|
||||
public readonly apisTreeItem: ApisTreeItem;
|
||||
public readonly servicePolicyTreeItem: ServicePolicyTreeItem;
|
||||
public readonly productsTreeItem: ProductsTreeItem;
|
||||
|
||||
private _root: IServiceTreeRoot;
|
||||
|
||||
|
@ -48,10 +52,11 @@ export class ServiceTreeItem extends AzureParentTreeItem<IServiceTreeRoot> {
|
|||
this._root = this.createRoot(parent.root, apiManagementClient);
|
||||
this.servicePolicyTreeItem = new ServicePolicyTreeItem(this);
|
||||
this.apisTreeItem = new ApisTreeItem(this);
|
||||
this.productsTreeItem = new ProductsTreeItem(this);
|
||||
}
|
||||
|
||||
public async loadMoreChildrenImpl(): Promise<AzureTreeItem<IServiceTreeRoot>[]> {
|
||||
return [this.apisTreeItem, this.servicePolicyTreeItem];
|
||||
return [this.apisTreeItem, this.productsTreeItem, this.servicePolicyTreeItem];
|
||||
}
|
||||
|
||||
public hasMoreChildrenImpl(): boolean {
|
||||
|
@ -85,9 +90,13 @@ export class ServiceTreeItem extends AzureParentTreeItem<IServiceTreeRoot> {
|
|||
|| expectedContextValue === ApiOperationTreeItem.contextValue
|
||||
|| expectedContextValue === OperationPolicyTreeItem.contextValue) {
|
||||
return this.apisTreeItem;
|
||||
}
|
||||
} else if (expectedContextValue === ProductTreeItem.contextValue
|
||||
|| expectedContextValue === ProductPolicyTreeItem.contextValue) {
|
||||
return this.productsTreeItem;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private createRoot(subRoot: ISubscriptionRoot, client: ApiManagementClient): IServiceTreeRoot {
|
||||
return Object.assign({}, subRoot, {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { AzureTreeItem } from "vscode-azureextensionui";
|
||||
import { IProductTreeRoot } from "../../IProductTreeRoot";
|
||||
import { BaseArmResourceEditor } from "./BaseArmResourceEditor";
|
||||
|
||||
// tslint:disable-next-line:no-any
|
||||
export class ProductResourceEditor extends BaseArmResourceEditor<IProductTreeRoot> {
|
||||
public entityType: string = "Product";
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public async getDataInternal(context: AzureTreeItem<IProductTreeRoot>): Promise<ApiManagementModels.ProductContract> {
|
||||
return await context.root.client.product.get(context.root.resourceGroupName, context.root.serviceName, context.root.productName);
|
||||
}
|
||||
|
||||
public async updateDataInternal(context: AzureTreeItem<IProductTreeRoot>, payload: ApiManagementModels.ProductContract): Promise<ApiManagementModels.ProductContract> {
|
||||
return await context.root.client.product.createOrUpdate(context.root.resourceGroupName, context.root.serviceName, context.root.productName, payload);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ApiManagementModels } from "azure-arm-apimanagement";
|
||||
import { AzureTreeItem } from "vscode-azureextensionui";
|
||||
import { emptyPolicyXml, policyFormat } from "../../../constants";
|
||||
import { IProductTreeRoot } from "../../IProductTreeRoot";
|
||||
import { BasePolicyEditor } from "./BasePolicyEditor";
|
||||
|
||||
export class ProductPolicyEditor extends BasePolicyEditor<IProductTreeRoot> {
|
||||
public async getPolicy(context: AzureTreeItem<IProductTreeRoot>): Promise<string> {
|
||||
const policy = await context.root.client.productPolicy.get(context.root.resourceGroupName, context.root.serviceName, context.root.productName, { format: policyFormat });
|
||||
return policy.value;
|
||||
}
|
||||
|
||||
public async updatePolicy(context: AzureTreeItem<IProductTreeRoot>, policy: ApiManagementModels.PolicyContract): Promise<string> {
|
||||
const policyResult = await context.root.client.productPolicy.createOrUpdate(context.root.resourceGroupName, context.root.serviceName, context.root.productName, policy);
|
||||
return policyResult.value;
|
||||
}
|
||||
|
||||
public getDefaultPolicy() : string {
|
||||
return emptyPolicyXml;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
import { AzureParentTreeItem, AzureTreeDataProvider, AzureTreeItem, AzureUserInput, createTelemetryReporter, IActionContext, registerCommand, registerEvent, registerUIExtensionVariables } from 'vscode-azureextensionui';
|
||||
import { addApiToProduct } from './commands/addApiToProduct';
|
||||
import { copySubscriptionKey } from './commands/copySubscriptionKey';
|
||||
import { createService } from './commands/createService';
|
||||
import { deleteNode } from './commands/deleteNode';
|
||||
|
@ -22,11 +23,17 @@ import { ApisTreeItem } from './explorer/ApisTreeItem';
|
|||
import { ApiTreeItem } from './explorer/ApiTreeItem';
|
||||
import { ApiResourceEditor } from './explorer/editors/arm/ApiResourceEditor';
|
||||
import { OperationResourceEditor } from './explorer/editors/arm/OperationResourceEditor';
|
||||
import { ProductResourceEditor } from './explorer/editors/arm/ProductResourceEditor';
|
||||
import { OpenApiEditor } from './explorer/editors/openApi/OpenApiEditor';
|
||||
import { ApiPolicyEditor } from './explorer/editors/policy/ApiPolicyEditor';
|
||||
import { OperationPolicyEditor } from './explorer/editors/policy/OperationPolicyEditor';
|
||||
import { ProductPolicyEditor } from './explorer/editors/policy/ProductPolicyEditor';
|
||||
import { ServicePolicyEditor } from './explorer/editors/policy/ServicePolicyEditor';
|
||||
import { OperationPolicyTreeItem } from './explorer/OperationPolicyTreeItem';
|
||||
import { ProductApisTreeItem } from './explorer/ProductApisTreeItem';
|
||||
import { ProductApiTreeItem } from './explorer/ProductApiTreeItem';
|
||||
import { ProductPolicyTreeItem } from './explorer/ProductPolicyTreeItem';
|
||||
import { ProductTreeItem } from './explorer/ProductTreeItem';
|
||||
import { ServicePolicyTreeItem } from './explorer/ServicePolicyTreeItem';
|
||||
import { ServiceTreeItem } from './explorer/ServiceTreeItem';
|
||||
import { ext } from './extensionVariables';
|
||||
|
@ -61,6 +68,8 @@ export function activateInternal(context: vscode.ExtensionContext) {
|
|||
registerCommand('azureApiManagement.testOperation', testOperation);
|
||||
registerCommand('azureApiManagement.importOpenApiByFile', async (node?: ApisTreeItem) => { await importOpenApi(node, false); });
|
||||
registerCommand('azureApiManagement.importOpenApiByLink', async (node?: ApisTreeItem) => { await importOpenApi(node, true); });
|
||||
registerCommand('azureApiManagement.removeApiFromProduct', async (node?: AzureTreeItem) => await deleteNode(ProductApiTreeItem.contextValue, node));
|
||||
registerCommand('azureApiManagement.addApiToProduct', async (node?: ProductApisTreeItem) => { await addApiToProduct(node); });
|
||||
|
||||
registerEditors(context);
|
||||
}
|
||||
|
@ -88,6 +97,17 @@ function registerEditors(context: vscode.ExtensionContext) : void {
|
|||
await operationResourceEditor.showEditor(node);
|
||||
}, doubleClickDebounceDelay);
|
||||
|
||||
const productResourceEditor: ProductResourceEditor = new ProductResourceEditor();
|
||||
context.subscriptions.push(productResourceEditor);
|
||||
registerEvent('azureApiManagement.ProductResourceEditor.onDidSaveTextDocument', vscode.workspace.onDidSaveTextDocument, async function (this: IActionContext, doc: vscode.TextDocument): Promise<void> { await productResourceEditor.onDidSaveTextDocument(this, context.globalState, doc); });
|
||||
|
||||
registerCommand('azureApiManagement.showArmProduct', async (node?: ProductTreeItem) => {
|
||||
if (!node) {
|
||||
node = <ProductTreeItem>await ext.tree.showTreeItemPicker(ProductTreeItem.contextValue);
|
||||
}
|
||||
await productResourceEditor.showEditor(node);
|
||||
}, doubleClickDebounceDelay);
|
||||
|
||||
const apiEditor: OpenApiEditor = new OpenApiEditor();
|
||||
context.subscriptions.push(apiEditor);
|
||||
registerEvent('azureApiManagement.apiEditor.onDidSaveTextDocument', vscode.workspace.onDidSaveTextDocument, async function (this: IActionContext, doc: vscode.TextDocument): Promise<void> { await apiEditor.onDidSaveTextDocument(this, context.globalState, doc); });
|
||||
|
@ -134,6 +154,18 @@ function registerEditors(context: vscode.ExtensionContext) : void {
|
|||
}
|
||||
await operationPolicyEditor.showEditor(node);
|
||||
}, doubleClickDebounceDelay);
|
||||
|
||||
const productPolicyEditor: ProductPolicyEditor = new ProductPolicyEditor();
|
||||
context.subscriptions.push(productPolicyEditor);
|
||||
registerEvent('azureApiManagement.productPolicyEditor.onDidSaveTextDocument', vscode.workspace.onDidSaveTextDocument, async function (this: IActionContext, doc: vscode.TextDocument): Promise<void> { await productPolicyEditor.onDidSaveTextDocument(this, context.globalState, doc); });
|
||||
|
||||
registerCommand('azureApiManagement.showProductPolicy', async (node?: ProductPolicyTreeItem) => {
|
||||
if (!node) {
|
||||
const productNode = <ProductTreeItem>await ext.tree.showTreeItemPicker(ProductTreeItem.contextValue);
|
||||
node = productNode.policyTreeItem;
|
||||
}
|
||||
await productPolicyEditor.showEditor(node);
|
||||
}, doubleClickDebounceDelay);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
|
|
|
@ -5,11 +5,16 @@
|
|||
|
||||
import { IApiTreeRoot } from "../explorer/IApiTreeRoot";
|
||||
import { IOperationTreeRoot } from "../explorer/IOperationTreeRoot";
|
||||
import { IProductTreeRoot } from "../explorer/IProductTreeRoot";
|
||||
import { IServiceTreeRoot } from "../explorer/IServiceTreeRoot";
|
||||
|
||||
export function nameUtil(root: IServiceTreeRoot | IApiTreeRoot | IOperationTreeRoot): string {
|
||||
export function nameUtil(root: IServiceTreeRoot | IApiTreeRoot | IOperationTreeRoot | IProductTreeRoot): string {
|
||||
let name = root.serviceName;
|
||||
|
||||
if (isProductRoot(root)) {
|
||||
name = `${name}-${root.productName}`;
|
||||
}
|
||||
|
||||
if (isApiRoot(root)) {
|
||||
name = `${name}-${root.apiName}`;
|
||||
}
|
||||
|
@ -21,10 +26,14 @@ export function nameUtil(root: IServiceTreeRoot | IApiTreeRoot | IOperationTreeR
|
|||
return name;
|
||||
}
|
||||
|
||||
function isApiRoot(root: IServiceTreeRoot | IApiTreeRoot | IOperationTreeRoot): root is IApiTreeRoot {
|
||||
function isApiRoot(root: IServiceTreeRoot | IApiTreeRoot | IOperationTreeRoot | IProductTreeRoot): root is IApiTreeRoot {
|
||||
return (<IApiTreeRoot>root).apiName !== undefined;
|
||||
}
|
||||
|
||||
function isOperationRoot(root: IServiceTreeRoot |IApiTreeRoot | IOperationTreeRoot): root is IOperationTreeRoot {
|
||||
function isOperationRoot(root: IServiceTreeRoot |IApiTreeRoot | IOperationTreeRoot | IProductTreeRoot): root is IOperationTreeRoot {
|
||||
return (<IOperationTreeRoot>root).opName !== undefined;
|
||||
}
|
||||
|
||||
function isProductRoot(root: IServiceTreeRoot |IApiTreeRoot | IOperationTreeRoot | IProductTreeRoot): root is IProductTreeRoot {
|
||||
return (<IProductTreeRoot>root).productName !== undefined;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче