Skip to content

Commit

Permalink
Add Service Connector (#3790)
Browse files Browse the repository at this point in the history
* Add Service Connector

* Requested changes and update package

* Add name to activity log

* Hide validate from the command palette

* Update package and change create/delete name

* one more change

* Update dev and serviceconnector package
  • Loading branch information
motm32 authored Aug 29, 2023
1 parent 47f93ac commit 58588c1
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 15 deletions.
78 changes: 65 additions & 13 deletions package-lock.json

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

37 changes: 36 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@
"command": "azureFunctions.viewProperties",
"title": "%azureFunctions.viewProperties%",
"category": "Azure Functions"
},
{
"command": "azureFunctions.createServiceConnector",
"title": "%azureFunctions.createServiceConnector%",
"category": "Azure Functions"
},
{
"command": "azureFunctions.deleteServiceConnector",
"title": "%azureFunctions.deleteServiceConnector%",
"category": "Azure Functions"
},
{
"command": "azureFunctions.validateServiceConnector",
"title": "%azureFunctions.validateServiceConnector%",
"category": "Azure Functions"
}
],
"submenus": [
Expand Down Expand Up @@ -621,6 +636,21 @@
"command": "azureResourceGroups.refresh",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /azFunc.*folder/",
"group": "1@1"
},
{
"command": "azureFunctions.createServiceConnector",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /serviceConnectorGroupItem/",
"group": "1@1"
},
{
"command": "azureFunctions.deleteServiceConnector",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /serviceConnectorItem/",
"group": "1@1"
},
{
"command": "azureFunctions.validateServiceConnector",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /serviceConnectorItem/",
"group": "1@2"
}
],
"explorer/context": [
Expand Down Expand Up @@ -669,6 +699,10 @@
{
"command": "azureFunctions.viewProperties",
"when": "never"
},
{
"command": "azureFunctions.validateServiceConnector",
"when": "never"
}
],
"editor/context": [
Expand Down Expand Up @@ -1108,7 +1142,7 @@
"devDependencies": {
"@azure/arm-resources": "^5.2.0",
"@microsoft/eslint-config-azuretools": "^0.2.1",
"@microsoft/vscode-azext-dev": "^2.0.1",
"@microsoft/vscode-azext-dev": "^2.0.2",
"@types/fs-extra": "^8.1.0",
"@types/gulp": "^4.0.10",
"@types/gulp-filter": "^3.0.33",
Expand Down Expand Up @@ -1157,6 +1191,7 @@
"@microsoft/vscode-azext-azureappservice": "^2.2.5",
"@microsoft/vscode-azext-azureappsettings": "^0.2.0",
"@microsoft/vscode-azext-azureutils": "^2.0.1",
"@microsoft/vscode-azext-serviceconnector": "^0.1.2",
"@microsoft/vscode-azext-utils": "^2.0.0",
"@microsoft/vscode-azureresources-api": "^2.0.4",
"cross-fetch": "^4.0.0",
Expand Down
3 changes: 3 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"azureFunctions.createNewProject": "Create New Project...",
"azureFunctions.createPythonVenv": "Create a virtual environment when creating a new Python project.",
"azureFunctions.createSlot": "Create Slot...",
"azureFunctions.createServiceConnector": "Create connection...",
"azureFunctions.deleteFunction": "Delete Function...",
"azureFunctions.deleteFunctionApp": "Delete Function App...",
"azureFunctions.deleteSlot": "Delete Slot...",
"azureFunctions.deleteServiceConnector": "Delete connection...",
"azureFunctions.deploy": "Deploy to Function App...",
"azureFunctions.deploySlot": "Deploy to Slot...",
"azureFunctions.deploySubpath": "The default subpath of a workspace folder to use when deploying. If set, you will not be prompted for the folder path when deploying.",
Expand Down Expand Up @@ -101,6 +103,7 @@
"azureFunctions.toggleAppSettingVisibility": "Toggle App Setting Visibility.",
"azureFunctions.uninstallFuncCoreTools": "Uninstall Azure Functions Core Tools",
"azureFunctions.validateFuncCoreTools": "Validate the Azure Functions Core Tools is installed before debugging.",
"azureFunctions.validateServiceConnector": "Validate",
"azureFunctions.viewCommitInGitHub": "View Commit in GitHub",
"azureFunctions.viewDeploymentLogs": "View Deployment Logs",
"azureFunctions.viewProperties": "View Properties",
Expand Down
6 changes: 6 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { commands } from "vscode";
import { ext } from '../extensionVariables';
import { installOrUpdateFuncCoreTools } from '../funcCoreTools/installOrUpdateFuncCoreTools';
import { uninstallFuncCoreTools } from '../funcCoreTools/uninstallFuncCoreTools';
import { createServiceConnector } from '../serviceConnector/createServiceConnector';
import { deleteServiceConnector } from '../serviceConnector/deleteServiceConnector';
import { validateServiceConnector } from '../serviceConnector/validateServiceConnector';
import { ResolvedFunctionAppResource } from '../tree/ResolvedFunctionAppResource';
import { addBinding } from './addBinding/addBinding';
import { setAzureWebJobsStorage } from './appSettings/connectionSettings/azureWebJobsStorage/setAzureWebJobsStorage';
Expand Down Expand Up @@ -104,4 +107,7 @@ export function registerCommands(): void {
registerSiteCommand('azureFunctions.viewDeploymentLogs', unwrapTreeNodeCommandCallback(viewDeploymentLogs));
registerCommandWithTreeNodeUnwrapping('azureFunctions.viewProperties', viewProperties);
registerCommandWithTreeNodeUnwrapping('azureFunctions.showOutputChannel', () => { ext.outputChannel.show(); });
registerCommandWithTreeNodeUnwrapping('azureFunctions.createServiceConnector', createServiceConnector);
registerCommandWithTreeNodeUnwrapping('azureFunctions.deleteServiceConnector', deleteServiceConnector);
registerCommandWithTreeNodeUnwrapping('azureFunctions.validateServiceConnector', validateServiceConnector);
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { registerAppServiceExtensionVariables } from '@microsoft/vscode-azext-azureappservice';
import { AzureAccountTreeItemBase, registerAzureUtilsExtensionVariables } from '@microsoft/vscode-azext-azureutils';
import { registerServiceConnectorExtensionVariables } from '@microsoft/vscode-azext-serviceconnector';
import { IActionContext, apiUtils, callWithTelemetryAndErrorHandling, createApiProvider, createAzExtOutputChannel, createExperimentationService, registerErrorHandler, registerEvent, registerReportIssueCommand, registerUIExtensionVariables } from '@microsoft/vscode-azext-utils';
import { AzExtResourceType } from '@microsoft/vscode-azureresources-api';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -44,6 +45,7 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
registerUIExtensionVariables(ext);
registerAzureUtilsExtensionVariables(ext);
registerAppServiceExtensionVariables(ext);
registerServiceConnectorExtensionVariables(ext);

await callWithTelemetryAndErrorHandling('azureFunctions.activate', async (activateContext: IActionContext) => {
activateContext.telemetry.properties.isActivationEvent = 'true';
Expand Down
28 changes: 28 additions & 0 deletions src/serviceConnector/createServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ServiceConnectorGroupTreeItem, createLinker } from "@microsoft/vscode-azext-serviceconnector";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { localize } from "../localize";
import { SlotTreeItem } from "../tree/SlotTreeItem";
import { createActivityContext } from "../utils/activityUtils";
import { pickFunctionApp } from "../utils/pickFunctionApp";

export async function createServiceConnector(context: IActionContext, item?: SlotTreeItem | ServiceConnectorGroupTreeItem): Promise<void> {
item ??= await pickFunctionApp(context);

if (item instanceof ServiceConnectorGroupTreeItem) {
item = <SlotTreeItem>item.parent;
}

const activityContext = {
...context,
...await createActivityContext(),
activityTitle: localize('createServiceConnector', 'Create connection'),
}

await createLinker(activityContext, item.id, item.subscription);
await item.refresh(context);
}
30 changes: 30 additions & 0 deletions src/serviceConnector/deleteServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ServiceConnectorTreeItem, deleteLinker } from "@microsoft/vscode-azext-serviceconnector";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { localize } from "../localize";
import { SlotTreeItem } from "../tree/SlotTreeItem";
import { createActivityContext } from "../utils/activityUtils";
import { pickFunctionApp } from "../utils/pickFunctionApp";

export async function deleteServiceConnector(context: IActionContext, item?: SlotTreeItem | ServiceConnectorTreeItem): Promise<void> {
let serviceConnectorName: string | undefined = undefined;
item ??= await pickFunctionApp(context);

if (item instanceof ServiceConnectorTreeItem) {
serviceConnectorName = item.label;
item = <SlotTreeItem>item.parent?.parent;
}

const activityContext = {
...context,
...await createActivityContext(),
activityTitle: localize('deleteServiceConnector', 'Delete connection'),
}

await deleteLinker(activityContext, item.id, item.subscription, serviceConnectorName);
await item.refresh(context);
}
29 changes: 29 additions & 0 deletions src/serviceConnector/validateServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ServiceConnectorTreeItem, validateLinker } from "@microsoft/vscode-azext-serviceconnector";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { localize } from "../localize";
import { SlotTreeItem } from "../tree/SlotTreeItem";
import { createActivityContext } from "../utils/activityUtils";
import { pickFunctionApp } from "../utils/pickFunctionApp";

export async function validateServiceConnector(context: IActionContext, item?: SlotTreeItem | ServiceConnectorTreeItem): Promise<void> {
let serviceConnectorName: string | undefined = undefined
item ??= await pickFunctionApp(context);

if (item instanceof ServiceConnectorTreeItem) {
serviceConnectorName = item.label;
item = <SlotTreeItem>item.parent?.parent;
}

const activityContext = {
...context,
...await createActivityContext(),
activityTitle: localize('validate', `Validate connection "{0}"`, serviceConnectorName),
}

await validateLinker(activityContext, item.id, item.subscription, serviceConnectorName);
}
Loading

0 comments on commit 58588c1

Please sign in to comment.