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

Add Service Connector #3790

Merged
merged 7 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
64 changes: 58 additions & 6 deletions package-lock.json

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

31 changes: 31 additions & 0 deletions 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 @@ -1157,6 +1187,7 @@
"@microsoft/vscode-azext-azureappservice": "^2.2.2",
"@microsoft/vscode-azext-azureappsettings": "^0.2.0",
"@microsoft/vscode-azext-azureutils": "^2.0.1",
"@microsoft/vscode-azext-serviceconnector": "0.1.0",
"@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 Service Connector...",
"azureFunctions.deleteFunction": "Delete Function...",
"azureFunctions.deleteFunctionApp": "Delete Function App...",
"azureFunctions.deleteSlot": "Delete Slot...",
"azureFunctions.deleteServiceConnector": "Delete Service Connector...",
"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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to make the same changes you did on the App Service PR here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm you got it

"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 Service Connector'),
}

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 Service Connector'),
}

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'),
}

await validateLinker(activityContext, item.id, item.subscription, serviceConnectorName);
}
5 changes: 4 additions & 1 deletion src/tree/ResolvedFunctionAppResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Site, SiteConfig, SiteSourceControl, StringDictionary } from "@azure/arm-appservice";
import { DeleteLastServicePlanStep, DeleteSiteStep, DeploymentTreeItem, DeploymentsTreeItem, IDeleteSiteWizardContext, LogFilesTreeItem, ParsedSite, SiteFilesTreeItem, getFile } from "@microsoft/vscode-azext-azureappservice";
import { AppSettingTreeItem, AppSettingsTreeItem } from "@microsoft/vscode-azext-azureappsettings";
import { ServiceConnectorGroupTreeItem } from "@microsoft/vscode-azext-serviceconnector";
import { AzExtTreeItem, AzureWizard, DeleteConfirmationStep, IActionContext, ISubscriptionContext, TreeItemIconPath, nonNullValue } from "@microsoft/vscode-azext-utils";
import { ResolvedAppResourceBase } from "@microsoft/vscode-azext-utils/hostapi";
import { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
Expand Down Expand Up @@ -47,6 +48,7 @@ export class ResolvedFunctionAppResource implements ResolvedAppResourceBase {
private _functionsTreeItem: RemoteFunctionsTreeItem | undefined;
private _logFilesTreeItem: LogFilesTreeItem;
private _siteFilesTreeItem: SiteFilesTreeItem;
private _serviceConnectorNode!: ServiceConnectorGroupTreeItem;

private _cachedVersion: FuncVersion | undefined;
private _cachedHostJson: IParsedHostJson | undefined;
Expand Down Expand Up @@ -235,12 +237,13 @@ export class ResolvedFunctionAppResource implements ResolvedAppResourceBase {
site: this.site,
contextValuesToAdd: ['azFunc']
});
this._serviceConnectorNode = new ServiceConnectorGroupTreeItem(proxyTree, this.site.id);

if (!this._functionsTreeItem) {
this._functionsTreeItem = await RemoteFunctionsTreeItem.createFunctionsTreeItem(context, proxyTree);
}

const children: AzExtTreeItem[] = [this._functionsTreeItem, this.appSettingsTreeItem, this._siteFilesTreeItem, this._logFilesTreeItem, this.deploymentsNode];
const children: AzExtTreeItem[] = [this._functionsTreeItem, this.appSettingsTreeItem, this._siteFilesTreeItem, this._logFilesTreeItem, this.deploymentsNode, this._serviceConnectorNode];
if (!this.site.isSlot) {
this._slotsTreeItem = new SlotsTreeItem(proxyTree);
children.push(this._slotsTreeItem);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/pickFunctionApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ITreeItemPickerContext } from "@microsoft/vscode-azext-utils";
import { functionFilter } from "../constants";
import { ext } from "../extensionVariables";
import { SlotTreeItem } from "../tree/SlotTreeItem";

export async function pickFunctionApp(context: ITreeItemPickerContext): Promise<SlotTreeItem> {
return await ext.rgApi.pickAppResource<SlotTreeItem>(context, {
filter: functionFilter
});
}