Skip to content

Commit

Permalink
feat: data plane view support (#209)
Browse files Browse the repository at this point in the history
* feat: rbac demo

* feat: support api server

* feat: update

* feat: ready

* feat: update

* feat: update

* test: update test case

* feat: add feautres

* docs: strings

* test: update

* feat: update command

* feat: change to b type

* feat: adjust treeitem view structure

* feat: update

* feat: update

* feat: separate defines

* feat: update

* feat: update

* test: add test cases

* test: add test cases

* fix: update the code according to comments

* fix: update code according to comments

* feat: update code

* feat: update

* feat: update

* fix: update

* test: fix comments and test cases

* test: update

* fix: update the uistring
  • Loading branch information
wenytang-ms authored Aug 23, 2024
1 parent b120891 commit 9ff2c47
Show file tree
Hide file tree
Showing 45 changed files with 1,488 additions and 188 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 63 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,44 @@
"command": "azure-api-center.selectTenant",
"title": "%azure-api-center.commands.selectTenant.title%",
"category": "Azure API Center"
},
{
"command": "azure-api-center.apiCenterWorkspace.addApis",
"title": "%azure-api-center.commands.apiCenterWorkspace.addApis.title%",
"icon": "$(add)",
"category": "Azure API Center"
},
{
"command": "azure-api-center.apiCenterWorkspace.refresh",
"title": "%azure-api-center.commands.apiCenterTreeView.refresh.title%",
"icon": "$(refresh)",
"category": "Azure API Center"
},
{
"command": "azure-api-center.apiCenterWorkspace.collapse",
"title": "%azure-api-center.commands.apiCenterWorkspace.collapse.title%",
"icon": "$(collapse-all)",
"category": "Azure API Center"
},
{
"command": "azure-api-center.apiCenterWorkspace.removeApi",
"title": "%azure-api-center.commands.apiCenterWorkspace.removeApis.title%",
"icon": "$(close)",
"category": "Azure API Center"
}
],
"views": {
"api-center-treeview": [
{
"id": "apiCenterTreeView",
"name": "API Center",
"name": "%azure-api-center.views.api-center-treeview.controlplane.title%",
"icon": "media/api-center-icon.svg",
"contextualTitle": "Azure API Center"
},
{
"id": "apiCenterWorkspace",
"name": "%azure-api-center.views.api-center-treeview.dataplane.title%",
"visibility": "visible"
}
]
},
Expand All @@ -191,6 +220,21 @@
"command": "azure-api-center.apiCenterTreeView.refresh",
"when": "view == apiCenterTreeView",
"group": "navigation"
},
{
"command": "azure-api-center.apiCenterWorkspace.addApis",
"when": "view == apiCenterWorkspace",
"group": "navigation@2"
},
{
"command": "azure-api-center.apiCenterWorkspace.refresh",
"when": "view == apiCenterWorkspace",
"group": "navigation@1"
},
{
"command": "azure-api-center.apiCenterWorkspace.collapse",
"when": "view == apiCenterWorkspace",
"group": "navigation@3"
}
],
"view/item/context": [
Expand All @@ -201,15 +245,15 @@
},
{
"command": "azure-api-center.open-api-docs",
"when": "view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi"
"when": "(view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi) || (view == apiCenterWorkspace && viewItem == azureApiCenterApiVersionDataPlaneDefinitionTreeItem-openapi)"
},
{
"command": "azure-api-center.open-postman",
"when": "view == apiCenterTreeView && viewItem =~ /never/"
},
{
"command": "azure-api-center.generate-api-client",
"when": "view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi"
"when": "(view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi) || (view == apiCenterWorkspace && viewItem == azureApiCenterApiVersionDataPlaneDefinitionTreeItem-openapi)"
},
{
"command": "azure-api-center.importOpenApiByFile",
Expand All @@ -221,7 +265,7 @@
},
{
"command": "azure-api-center.exportApi",
"when": "view == apiCenterTreeView && viewItem =~ /azureApiCenterApiVersionDefinitionTreeItem/"
"when": "(view == apiCenterTreeView && viewItem =~ /azureApiCenterApiVersionDefinitionTreeItem/) || (view == apiCenterWorkspace && viewItem =~ /azureApiCenterApiVersionDataPlaneDefinitionTreeItem/)"
},
{
"command": "azure-api-center.showOpenApi",
Expand All @@ -233,7 +277,7 @@
},
{
"command": "azure-api-center.generateMarkdownDocument",
"when": "view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi"
"when": "(view == apiCenterTreeView && viewItem == azureApiCenterApiVersionDefinitionTreeItem-openapi) || (view == apiCenterWorkspace && viewItem == azureApiCenterApiVersionDataPlaneDefinitionTreeItem-openapi)"
},
{
"command": "azure-api-center.registerApi",
Expand Down Expand Up @@ -277,6 +321,11 @@
"command": "azure-api-center.deleteCustomFunction",
"when": "view == apiCenterTreeView && viewItem == azureApiCenterFunction",
"group": "function@1"
},
{
"command": "azure-api-center.apiCenterWorkspace.removeApi",
"when": "view == apiCenterWorkspace && viewItem == azureApiCenterDataPlane",
"group": "inline@0"
}
],
"copilot": [
Expand Down Expand Up @@ -358,6 +407,14 @@
{
"command": "azure-api-center.deleteCustomFunction",
"when": "never"
},
{
"command": "azure-api-center.apiCenterWorkspace.removeApi",
"when": "never"
},
{
"command": "azure-api-center.apiCenterWorkspace.collapse",
"when": "never"
}
]
},
Expand All @@ -384,6 +441,7 @@
],
"configuration": [
{
"title": "Azure Api Center",
"properties": {
"azure-api-center.selectedSubscriptions": {
"type": "array",
Expand Down
7 changes: 6 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
"azure-api-center.commands.deleteCustomFunction.title": "Delete",
"azure-api-center.chatParticipants.apicenter.description": "Build, discover, and consume great APIs.",
"azure-api-center.chatParticipants.apicenter.commands.list.description": "List available APIs.",
"azure-api-center.chatParticipants.apicenter.commands.find.description": "Find an API given a search query."
"azure-api-center.chatParticipants.apicenter.commands.find.description": "Find an API given a search query.",
"azure-api-center.commands.apiCenterWorkspace.collapse.title": "Collapse",
"azure-api-center.views.api-center-treeview.controlplane.title": "Azure API Center",
"azure-api-center.views.api-center-treeview.dataplane.title": "API Center Data View",
"azure-api-center.commands.apiCenterWorkspace.addApis.title": "Connect to an API Center",
"azure-api-center.commands.apiCenterWorkspace.removeApis.title": "Disconnect from API Center"
}
58 changes: 58 additions & 0 deletions src/azure/ApiCenter/ApiCenterDataPlaneAPIs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { RequestPrepareOptions, ServiceClient } from "@azure/ms-rest-js";
import { ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { ApiCenterApiVersionDefinitionExport, DataPlaneApiCenterApi, DataPlaneApiCenterApiVersion, DataPlaneApiCenterApiVersionDefinition } from "../ApiCenter/contracts";
import { APICenterDataPlaneRestAPIs } from "./ApiCenterRestAPIs";
export interface DataPlaneAccount {
readonly domain: string;
readonly tenantId: string;
readonly clientId: string;
}
export class ApiCenterDataPlaneService {
private susbcriptionContext: ISubscriptionContext;
constructor(susbcriptionContext: ISubscriptionContext) {
this.susbcriptionContext = susbcriptionContext;
};
public async getApiCenterApis(): Promise<{ value: DataPlaneApiCenterApi[]; nextLink: string }> {
const client = new ServiceClient(this.susbcriptionContext.credentials);
let url = APICenterDataPlaneRestAPIs.ListApis(this.susbcriptionContext.subscriptionPath);
const options: RequestPrepareOptions = {
method: "GET",
url: url,
};
const response = await client.sendRequest(options);
return response.parsedBody;
};
public async getAPiCenterApiVersions(apiName: string): Promise<{ value: DataPlaneApiCenterApiVersion[]; nextLink: string }> {
const client = new ServiceClient(this.susbcriptionContext.credentials);
let url = APICenterDataPlaneRestAPIs.ListApiVersions(this.susbcriptionContext.subscriptionPath, apiName);
const options: RequestPrepareOptions = {
method: "GET",
url: url,
};
const response = await client.sendRequest(options);
return response.parsedBody;
};
public async getApiCenterApiDefinitions(apiName: string, apiVersion: string): Promise<{ value: DataPlaneApiCenterApiVersionDefinition[]; nextLink: string }> {
const client = new ServiceClient(this.susbcriptionContext.credentials);
let url = APICenterDataPlaneRestAPIs.ListApiDefinitions(this.susbcriptionContext.subscriptionPath, apiName, apiVersion);
const options: RequestPrepareOptions = {
method: "GET",
url: url,
};
const response = await client.sendRequest(options);
return response.parsedBody;
};
public async exportSpecification(apiName: string,
apiVersionName: string,
apiCenterApiVersionDefinitionName: string): Promise<ApiCenterApiVersionDefinitionExport> {
const client = new ServiceClient(this.susbcriptionContext.credentials);
const options: RequestPrepareOptions = {
method: "POST",
url: APICenterDataPlaneRestAPIs.ExportApiDefinitions(this.susbcriptionContext.subscriptionPath, apiName, apiVersionName, apiCenterApiVersionDefinitionName),
};
const response = await client.sendRequest(options);
return response.parsedBody;
}
}
10 changes: 10 additions & 0 deletions src/azure/ApiCenter/ApiCenterRestAPIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export const APICenterRestAPIs = {
ImportRuleset: (subscriptionId: string, resourceGroupName: string, apiCenterName: string, restApiVersion: string) => `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.ApiCenter/services/${apiCenterName}/workspaces/default/analyzerConfigs/spectral-openapi/importRuleset?api-version=${restApiVersion}`,
ExportRuleset: (subscriptionId: string, resourceGroupName: string, apiCenterName: string, restApiVersion: string) => `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.ApiCenter/services/${apiCenterName}/workspaces/default/analyzerConfigs/spectral-openapi/exportRuleset?api-version=${restApiVersion}`,
};

export const APICenterDataPlaneRestAPIs = {
GetApi: (domain: string, apiName: string) => `https://${domain}/workspaces/default/apis/${apiName}`,
ListApis: (domain: string) => `https://${domain}/workspaces/default/apis`,
ListAllApis: (domain: string) => `https://${domain}/apis`,
GetApiVersion: (domain: string, apiName: string, versionName: string) => `https://${domain}/workspaces/default/apis/${apiName}/versions/${versionName}`,
ListApiVersions: (domain: string, apiName: string) => `https://${domain}/workspaces/default/apis/${apiName}/versions`,
ListApiDefinitions: (domain: string, apiName: string, apiVersion: string) => `https://${domain}/workspaces/default/apis/${apiName}/versions/${apiVersion}/definitions`,
ExportApiDefinitions: (domain: string, apiName: string, apiVersion: string, definitionName: string) => `https://${domain}/workspaces/default/apis/${apiName}/versions/${apiVersion}/definitions/${definitionName}:exportSpecification`,
};
33 changes: 33 additions & 0 deletions src/azure/ApiCenter/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export type GeneralApiCenter = ApiCenter | DataPlaneApiCenter;

export type ApiCenter = {
id: string;
Expand All @@ -12,6 +13,11 @@ export type ApiCenter = {
type: string;
};

export type DataPlaneApiCenter = {
name: string;
};

export type GeneralApiCenterApi = ApiCenterApi | DataPlaneApiCenterApi;

export type ApiCenterApi = {
id: string;
Expand All @@ -25,6 +31,16 @@ export type ApiCenterApi = {
type: string;
};

export type DataPlaneApiCenterApi = {
name: string;
title: string;
kind: string;
lifecycleStage: string;
externalDocumentation: [];
contacts: [];
customProperties: {};
};

export type ApiCenterEnvironment = {
id: string;
location: string;
Expand All @@ -35,6 +51,8 @@ export type ApiCenterEnvironment = {
type: string;
};

export type GeneralApiCenterApiVersion = ApiCenterApiVersion | DataPlaneApiCenterApiVersion;

export type ApiCenterApiVersion = {
id: string;
location: string;
Expand All @@ -47,6 +65,12 @@ export type ApiCenterApiVersion = {
type: string;
};

export type DataPlaneApiCenterApiVersion = {
name: string;
title: string;
lifecycleStage: string;
};

export type ApiCenterApiDeployment = {
id: string;
location: string;
Expand All @@ -57,6 +81,8 @@ export type ApiCenterApiDeployment = {
type: string;
};

export type GeneralApiCenterApiVersionDefinition = ApiCenterApiVersionDefinition | DataPlaneApiCenterApiVersionDefinition;

export type ApiCenterApiVersionDefinition = {
id: string;
location: string;
Expand All @@ -76,6 +102,13 @@ export type ApiCenterRulesetConfig = {
properties: {
};
};
export type DataPlaneApiCenterApiVersionDefinition = {
name: string;
title: string;
specification: {
name: string;
}
};

export type ApiCenterApiVersionDefinitionImport = {
format: string;
Expand Down
Loading

0 comments on commit 9ff2c47

Please sign in to comment.