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
4 changes: 3 additions & 1 deletion src/commands/addDataPlaneApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@
import { ext } from "../extensionVariables";
import { UiStrings } from "../uiStrings";
export async function getDataPlaneApis(context: IActionContext): Promise<any | void> {
const endpointUrl = await vscode.window.showInputBox({ title: UiStrings.AddDataPlaneRuntimeUrl, ignoreFocusOut: true });
if (!endpointUrl) {
return;
}
const clientid = await vscode.window.showInputBox({ title: UiStrings.AddDataPlaneClientId, ignoreFocusOut: true });
if (!clientid) {
return;
}
const tenantid = await vscode.window.showInputBox({ title: UiStrings.AddDataPlaneTenantId, ignoreFocusOut: true });
if (!tenantid) {
return;
}
// return await getSessionToken(clientid, tenantid);

setAccountToExt(endpointUrl, clientid, tenantid);
ext.workspaceItem.refresh(context);
}
export function setAccountToExt(domain: string, clientId: string, tenantId: string) {
function pushIfNotExist(array: DataPlaneAccount[], element: DataPlaneAccount) {
if (!array.some(item => item.domain === element.domain)) {
array.push(element);
} else {
vscode.window.showInformationMessage(UiStrings.DatplaneAlreadyAdded);
}
}
pushIfNotExist(ext.dataPlaneAccounts, { domain: domain, tenantId: tenantId, clientId: clientId });
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 34 in src/commands/addDataPlaneApis.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/addDataPlaneApis.ts#L9-L34

Added lines #L9 - L34 were not covered by tests
4 changes: 2 additions & 2 deletions src/commands/registerApiSubCommands/registerStepByStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from 'vscode';
import { ApiCenterService } from "../../azure/ApiCenter/ApiCenterService";
import { ApiCenterApi, ApiCenterApiVersion, ApiCenterApiVersionDefinition, ApiCenterApiVersionDefinitionImport, ApiKind, ApiVersionLifecycleStage, SpecificationName } from "../../azure/ApiCenter/contracts";
import { ApiCenterVersionDefinitionManagement } from "../../azure/ApiCenterDefines/ApiCenterDefinition";
import { ApiCenterVersionDefinitionDataPlane } from "../../azure/ApiCenterDefines/ApiCenterDefinition";
import { ext } from "../../extensionVariables";
import { ApiCenterTreeItem } from "../../tree/ApiCenterTreeItem";
import { ApisTreeItem } from "../../tree/ApisTreeItem";
Expand All @@ -17,9 +17,9 @@
const apiCenterNode = await ext.treeDataProvider.showTreeItemPicker<ApiCenterTreeItem>(ApiCenterTreeItem.contextValue, context);
wenytang-ms marked this conversation as resolved.
Show resolved Hide resolved
node = apiCenterNode.apisTreeItem;
}
if (node.apiCenter instanceof ApiCenterVersionDefinitionManagement) {
if (node.apiCenter instanceof ApiCenterVersionDefinitionDataPlane) {
return;
}

Check warning on line 22 in src/commands/registerApiSubCommands/registerStepByStep.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/registerApiSubCommands/registerStepByStep.ts#L20-L22

Added lines #L20 - L22 were not covered by tests

const apiTitle = await vscode.window.showInputBox({ title: UiStrings.ApiTitle, ignoreFocusOut: true, validateInput: validateInputForTitle });
if (!apiTitle) {
Expand Down Expand Up @@ -64,8 +64,8 @@
return;
}

const resourceGroupName = getResourceGroupFromId(node.apiCenter.getId());
const apiCenterService = new ApiCenterService(node.parent?.subscription!, resourceGroupName, node.apiCenter.getName());

Check warning on line 68 in src/commands/registerApiSubCommands/registerStepByStep.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/registerApiSubCommands/registerStepByStep.ts#L67-L68

Added lines #L67 - L68 were not covered by tests

await createApiResources(apiCenterService, apiTitle, apiKind, apiVersionTitle, apiVersionLifecycleStage,
apiDefinitionTitle, specificationName, filePath);
Expand Down
68 changes: 33 additions & 35 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import { AzExtTreeDataProvider, AzExtTreeItem, CommandCallback, IActionContext, IParsedError, createAzExtOutputChannel, isUserCancelledError, parseError, registerCommand, registerEvent } from '@microsoft/vscode-azext-utils';
import { AzureAccount } from "./azure/azureLogin/azureAccount";
import { AzureSessionProviderHelper } from "./azure/azureLogin/azureSessionProvider";
import { AzureDataSessionProviderHelper } from "./azure/azureLogin/dataSessionProvider";
import { getDataPlaneApis } from "./commands/addDataPlaneApis";

Check warning on line 15 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
import { cleanupSearchResult } from './commands/cleanUpSearch';
import { detectBreakingChange } from './commands/detectBreakingChange';
import { showOpenApi } from './commands/editOpenApi';
Expand All @@ -21,13 +21,13 @@
import { generateApiLibrary } from './commands/generateApiLibrary';
import { GenerateHttpFile } from './commands/generateHttpFile';
import { generateMarkdownDocument } from './commands/generateMarkdownDocument';
import { handleUri } from './commands/handleUri';

Check warning on line 24 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L24

Added line #L24 was not covered by tests
import { importOpenApi } from './commands/importOpenApi';
import { openAPiInSwagger } from './commands/openApiInSwagger';
import { openUrlFromTreeNode } from './commands/openUrl';
import { refreshTree } from './commands/refreshTree';
import { registerApi } from './commands/registerApi';
import { removeDataplaneAPI } from './commands/removeDataplaneApi';

Check warning on line 30 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L30

Added line #L30 was not covered by tests
import { addCustomFunction } from './commands/rules/addCustomFunction';
import { deleteCustomFunction } from './commands/rules/deleteCustomFunction';
import { deployRules } from './commands/rules/deployRules';
Expand All @@ -37,16 +37,15 @@
import { renameCustomFunction } from './commands/rules/renameCustomFunction';
import { searchApi } from './commands/searchApi';
import { setApiRuleset } from './commands/setApiRuleset';
import { SignInToDataPlane } from "./commands/signInToDataPlane";

Check warning on line 40 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L40

Added line #L40 was not covered by tests
import { testInPostman } from './commands/testInPostman';
import { ErrorProperties, TelemetryProperties } from './common/telemetryEvent';
import { doubleClickDebounceDelay, selectedNodeKey } from './constants';
import { ext } from './extensionVariables';
import { ApiVersionDefinitionTreeItem } from './tree/ApiVersionDefinitionTreeItem';
import { createAzureAccountTreeItem } from "./tree/AzureAccountTreeItem";
import { createAzureDataAccountTreeItem } from './tree/DataPlaneAccount';

Check warning on line 47 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L47

Added line #L47 was not covered by tests
import { OpenApiEditor } from './tree/Editors/openApi/OpenApiEditor';
// Copilot Chat
import { ErrorProperties, TelemetryProperties } from './common/telemetryEvent';
export async function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "azure-api-center" is now active!');

Expand All @@ -60,39 +59,8 @@
context.subscriptions.push(ext.outputChannel);
registerAzureUtilsExtensionVariables(ext);

AzureSessionProviderHelper.activateAzureSessionProvider(context);
const sessionProvider = AzureSessionProviderHelper.getSessionProvider();

const azureAccountTreeItem = createAzureAccountTreeItem(sessionProvider);
context.subscriptions.push(azureAccountTreeItem);
ext.treeItem = azureAccountTreeItem;
// var a = ext.treeItem.subscription;
ext.dataPlaneAccounts = [];
const treeDataProvider = new AzExtTreeDataProvider(azureAccountTreeItem, "appService.loadMore");

ext.treeItem = azureAccountTreeItem;

ext.treeDataProvider = treeDataProvider;

const treeView = vscode.window.createTreeView("apiCenterTreeView", { treeDataProvider });
context.subscriptions.push(treeView);

AzureDataSessionProviderHelper.activateAzureSessionProvider(context);
const dataPlaneSessionProvider = AzureDataSessionProviderHelper.getSessionProvider();
const dataPlanAccountManagerTreeItem = createAzureDataAccountTreeItem(dataPlaneSessionProvider);
context.subscriptions.push(dataPlanAccountManagerTreeItem);
ext.workspaceItem = dataPlanAccountManagerTreeItem;

const workspaceTreeDataProvider = new AzExtTreeDataProvider(dataPlanAccountManagerTreeItem, "appService.loadMore");
ext.workspaceProvider = workspaceTreeDataProvider;

vscode.window.registerTreeDataProvider('apiCenterWorkspace', workspaceTreeDataProvider);

treeView.onDidChangeSelection((e: vscode.TreeViewSelectionChangeEvent<AzExtTreeItem>) => {
const selectedNode = e.selection[0];
ext.outputChannel.appendLine(selectedNode.id!);
ext.context.globalState.update(selectedNodeKey, selectedNode.id);
});
setupControlView(context);
setupDataTreeView(context);

Check warning on line 63 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L62-L63

Added lines #L62 - L63 were not covered by tests

// Register API Center extension commands

Expand Down Expand Up @@ -156,21 +124,21 @@
registerCommandWithTelemetry('azure-api-center.signInToAzure', AzureAccount.signInToAzure);
registerCommandWithTelemetry('azure-api-center.selectTenant', AzureAccount.selectTenant);
registerCommandWithTelemetry('azure-api-center.selectSubscriptions', AzureAccount.selectSubscriptions);
registerCommandWithTelemetry('azure-api-center.openUrl', openUrlFromTreeNode);
registerCommandWithTelemetry('azure-api-center.apiCenterWorkspace.signInToDataPlane', SignInToDataPlane);
registerCommandWithTelemetry('azure-api-center.apiCenterWorkspace.refresh', async (context: IActionContext) => ext.workspaceItem.refresh(context));
registerCommandWithTelemetry('azure-api-center.apiCenterWorkspace.addApis', getDataPlaneApis);
registerCommandWithTelemetry('azure-api-center.apiCenterWorkspace.collapse', () => {
vscode.commands.executeCommand('workbench.actions.treeView.apiCenterWorkspace.collapseAll');

Check warning on line 132 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L127-L132

Added lines #L127 - L132 were not covered by tests
});

registerCommandWithTelemetry('azure-api-center.apiCenterWorkspace.removeApi', removeDataplaneAPI);

context.subscriptions.push(
vscode.window.registerUriHandler({
handleUri
})
);

Check warning on line 141 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L134-L141

Added lines #L134 - L141 were not covered by tests
}

async function registerCommandWithTelemetry(commandId: string, callback: CommandCallback, debounce?: number): Promise<void> {
Expand Down Expand Up @@ -203,4 +171,34 @@
}, debounce);
}

function setupControlView(context: vscode.ExtensionContext) {
AzureSessionProviderHelper.activateAzureSessionProvider(context);
const sessionProvider = AzureSessionProviderHelper.getSessionProvider();
const azureAccountTreeItem = createAzureAccountTreeItem(sessionProvider);
context.subscriptions.push(azureAccountTreeItem);
ext.treeItem = azureAccountTreeItem;
const treeDataProvider = new AzExtTreeDataProvider(azureAccountTreeItem, "appService.loadMore");
ext.treeItem = azureAccountTreeItem;
ext.treeDataProvider = treeDataProvider;
const treeView = vscode.window.createTreeView("apiCenterTreeView", { treeDataProvider });
context.subscriptions.push(treeView);
treeView.onDidChangeSelection((e: vscode.TreeViewSelectionChangeEvent<AzExtTreeItem>) => {
const selectedNode = e.selection[0];
ext.outputChannel.appendLine(selectedNode.id!);
ext.context.globalState.update(selectedNodeKey, selectedNode.id);
});
}

function setupDataTreeView(context: vscode.ExtensionContext) {
ext.dataPlaneAccounts = [];
AzureDataSessionProviderHelper.activateAzureSessionProvider(context);
const dataPlaneSessionProvider = AzureDataSessionProviderHelper.getSessionProvider();
const dataPlanAccountManagerTreeItem = createAzureDataAccountTreeItem(dataPlaneSessionProvider);
context.subscriptions.push(dataPlanAccountManagerTreeItem);
ext.workspaceItem = dataPlanAccountManagerTreeItem;
const workspaceTreeDataProvider = new AzExtTreeDataProvider(dataPlanAccountManagerTreeItem, "appService.loadMore");
ext.workspaceProvider = workspaceTreeDataProvider;
vscode.window.registerTreeDataProvider('apiCenterWorkspace', workspaceTreeDataProvider);
}

Check warning on line 203 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L174-L203

Added lines #L174 - L203 were not covered by tests
export function deactivate() { }
1 change: 1 addition & 0 deletions src/uiStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ export class UiStrings {
static readonly AddDataPlaneTenantId = vscode.l10n.t("Input Entra App Tenant ID");
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.");
}
Loading