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

feat: data plane view support #209

Merged
merged 30 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
96cdd45
feat: rbac demo
wenytang-ms Jun 5, 2024
3429972
feat: support api server
wenytang-ms Jul 16, 2024
b187b5a
feat: update
wenytang-ms Jul 16, 2024
dfafbed
feat: ready
wenytang-ms Jul 22, 2024
c9320b6
feat: update
wenytang-ms Jul 22, 2024
6a6c8c1
feat: update
wenytang-ms Aug 1, 2024
25a442b
test: update test case
wenytang-ms Aug 1, 2024
224ece0
feat: add feautres
wenytang-ms Aug 1, 2024
48d8519
docs: strings
wenytang-ms Aug 1, 2024
b24677f
test: update
wenytang-ms Aug 1, 2024
c8ab52a
feat: update command
wenytang-ms Aug 1, 2024
7fc4201
feat: change to b type
wenytang-ms Aug 1, 2024
c86d654
feat: adjust treeitem view structure
wenytang-ms Aug 1, 2024
1476178
feat: update
wenytang-ms Aug 2, 2024
0e90e97
feat: update
wenytang-ms Aug 2, 2024
42e823c
feat: separate defines
wenytang-ms Aug 2, 2024
d538370
feat: update
wenytang-ms Aug 2, 2024
06271c8
feat: update
wenytang-ms Aug 2, 2024
d3bf5db
test: add test cases
wenytang-ms Aug 2, 2024
9816f7c
test: add test cases
wenytang-ms Aug 2, 2024
405785a
fix: update the code according to comments
wenytang-ms Aug 13, 2024
a04a3c4
fix: update code according to comments
wenytang-ms Aug 14, 2024
9c5a58f
feat: update code
wenytang-ms Aug 15, 2024
5c8f466
feat: update
wenytang-ms Aug 15, 2024
8246f70
feat: update
wenytang-ms Aug 16, 2024
8ff5a41
fix: update
wenytang-ms Aug 16, 2024
fe2e39b
Merge branch 'dev' into wenyt/auth1
wenytang-ms Aug 22, 2024
70dee3e
test: fix comments and test cases
wenytang-ms Aug 22, 2024
be0ea57
test: update
wenytang-ms Aug 22, 2024
b715df5
fix: update the uistring
wenytang-ms Aug 23, 2024
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
2 changes: 1 addition & 1 deletion package.nls.json
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
"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": "Remove API Center",
"azure-api-center.commands.apiCenterWorkspace.removeApis.title": "Remove API Center"
}
41 changes: 39 additions & 2 deletions src/commands/exportApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import * as path from "path";
import * as vscode from "vscode";
import { ApiSpecExportResultFormat } from "../azure/ApiCenter/contracts";
import { ApiCenterVersionDefinitionManagement } from "../azure/ApiCenterDefines/ApiCenterDefinition";
import { ApiCenterVersionDefinitionDataPlane, ApiCenterVersionDefinitionManagement } from "../azure/ApiCenterDefines/ApiCenterDefinition";
import { TreeViewType } from "../constants";
import { ext } from "../extensionVariables";
import { ApiVersionDefinitionTreeItem } from "../tree/ApiVersionDefinitionTreeItem";
import { ApiServerItem } from "../tree/DataPlaneAccount";
import { SubscriptionTreeItem } from "../tree/SubscriptionTreeItem";
import { UiStrings } from "../uiStrings";
import { createTemporaryFolder } from "../utils/fsUtil";
import { GeneralUtils } from "../utils/generalUtils";
export namespace ExportAPI {
export async function exportApi(
context: IActionContext,
node?: ApiVersionDefinitionTreeItem): Promise<void> {
if (!node) {
node = await ext.treeDataProvider.showTreeItemPicker<ApiVersionDefinitionTreeItem>(new RegExp(`${ApiCenterVersionDefinitionManagement.contextValue}*`), context);
let res = await getDefinitionTreeNode(context);
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
if (!res) {
return;
}
node = res;

Check warning on line 27 in src/commands/exportApi.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/exportApi.ts#L23-L27

Added lines #L23 - L27 were not covered by tests
}

const exportedSpec = await node?.apiCenterApiVersionDefinition.getDefinitions(node?.subscription!, node?.apiCenterName!, node?.apiCenterApiName!, node?.apiCenterApiVersionName!);
Expand All @@ -28,7 +36,7 @@
}

function getFilename(treeItem: ApiVersionDefinitionTreeItem): string {
return `${treeItem.apiCenterApiVersionDefinition.getName()}`;

Check warning on line 39 in src/commands/exportApi.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/exportApi.ts#L39

Added line #L39 was not covered by tests
}

async function writeToTempFile(node: ApiVersionDefinitionTreeItem, specFormat: string, specValue: string) {
Expand All @@ -49,4 +57,33 @@
await vscode.workspace.fs.writeFile(vscode.Uri.file(localFilePath), Buffer.from(fileContent));
await vscode.window.showTextDocument(document);
}

async function getDefinitionTreeNode(context: IActionContext): Promise<ApiVersionDefinitionTreeItem | null> {
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
const controlViewItem = await ext.dataPlaneTreeDataProvier.getChildren(ext.treeItem)

Check warning on line 62 in src/commands/exportApi.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check warning on line 62 in src/commands/exportApi.ts

View workflow job for this annotation

GitHub Actions / unit-test

Missing semicolon
const isControlPlaneExist = controlViewItem.some(item => item.contextValue === SubscriptionTreeItem.contextValue);
const dataViewItem = await ext.treeDataProvider.getChildren(ext.dataPlaneTreeItem);
const isDataPlaneExist = dataViewItem.some(item => item.contextValue === ApiServerItem.contextValue);
if (!isControlPlaneExist && !isDataPlaneExist) {
vscode.window.showInformationMessage(UiStrings.GetTreeView);
return null;
}
if (!isDataPlaneExist) {
return await ext.treeDataProvider.showTreeItemPicker<ApiVersionDefinitionTreeItem>(new RegExp(`${ApiCenterVersionDefinitionManagement.contextValue}*`), context);
}
if (!isControlPlaneExist) {
return await ext.dataPlaneTreeDataProvier.showTreeItemPicker<ApiVersionDefinitionTreeItem>(new RegExp(`${ApiCenterVersionDefinitionDataPlane.contextValue}*`), context);
}
const viewType = await vscode.window.showQuickPick(Object.values(TreeViewType), { title: UiStrings.SelectItemFromTreeView, ignoreFocusOut: true });
if (!viewType) {
return null;
}
switch (viewType) {
case TreeViewType.controlPlaneView:
return await ext.treeDataProvider.showTreeItemPicker<ApiVersionDefinitionTreeItem>(new RegExp(`${ApiCenterVersionDefinitionManagement.contextValue}*`), context);
case TreeViewType.dataPlaneView:
return await ext.dataPlaneTreeDataProvier.showTreeItemPicker<ApiVersionDefinitionTreeItem>(new RegExp(`${ApiCenterVersionDefinitionDataPlane.contextValue}*`), context);
default:
return null;
}
}

Check warning on line 88 in src/commands/exportApi.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/exportApi.ts#L62-L88

Added lines #L62 - L88 were not covered by tests
}
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
cicd: UiStrings.RegisterApiOptionCicd,
};

export const TreeViewType = {
controlPlaneView: "API Center Management View",
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
dataPlaneView: "API Center Data Plane View",
}

Check warning on line 40 in src/constants.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check warning on line 40 in src/constants.ts

View workflow job for this annotation

GitHub Actions / unit-test

Missing semicolon

export const ApiRulesetOptions = {
default: UiStrings.ApiRulesetOptionDefault,
azureApiGuideline: UiStrings.ApiRulesetOptionAzureApiGuideline,
Expand Down
2 changes: 1 addition & 1 deletion src/tree/SubscriptionTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createSubscriptionTreeItem(
return new SubscriptionTreeItem(parent, subscription);
}

class SubscriptionTreeItem extends AzExtParentTreeItem {
export class SubscriptionTreeItem extends AzExtParentTreeItem {
public readonly subscriptionContext: ISubscriptionContext;
public readonly subscriptionId: string;
public static contextValue: string = "azureApiCenterAzureSubscription";
Expand Down
2 changes: 2 additions & 0 deletions src/uiStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@ export class UiStrings {
static readonly RequestFailedWithStatusCode = vscode.l10n.t("Request failed with status code: {0}");
static readonly DownloadDefinitionFileWithErrorMsg = vscode.l10n.t("Download API Center Definition File error: {0}");
static readonly DatplaneAlreadyAdded = vscode.l10n.t("This Data Plane Runtime URL already added to Data View.");
static readonly SelectItemFromTreeView = vscode.l10n.t("Select from which tree view");
static readonly GetTreeView = vscode.l10n.t("Please Sign In to Azure to get management view or connect to data plane APIs");
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 2 additions & 7 deletions src/utils/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@
}

export async function fetchDataFromLink(link: string): Promise<string> {
try {
const res = await axios.get(link);
return JSON.stringify(res.data);
}
catch (err) {
throw err;
}
const res = await axios.get(link);
return JSON.stringify(res.data);
}

Check warning on line 61 in src/utils/generalUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/generalUtils.ts#L59-L61

Added lines #L59 - L61 were not covered by tests
}
Loading