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

Remove azureWebJobsStorage validation on deploy #3647

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,24 @@
*--------------------------------------------------------------------------------------------*/

import { AzureWizard } from "@microsoft/vscode-azext-utils";
import { CodeAction, ConnectionKey, localStorageEmulatorConnectionString } from "../../../../constants";
import { CodeAction, ConnectionKey } from "../../../../constants";
import { getLocalSettingsConnectionString } from "../../../../funcConfig/local.settings";
import { IConnectionPromptOptions } from "../IConnectionPromptOptions";
import { ISetConnectionSettingContext } from "../ISetConnectionSettingContext";
import { AzureWebJobsStorageExecuteStep } from "./AzureWebJobsStorageExecuteStep";
import { AzureWebJobsStoragePromptStep } from "./AzureWebJobsStoragePromptStep";
import { IAzureWebJobsStorageWizardContext } from "./IAzureWebJobsStorageWizardContext";

// Supports validation on both 'debug' and 'deploy'
export async function validateStorageConnection(context: Omit<ISetConnectionSettingContext, 'projectPath'>, projectPath: string, options?: IConnectionPromptOptions): Promise<void> {
if (context.action === CodeAction.Deploy) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need even need this? validateStorageConnection never gets called in the deploy scenario anyway, right? I think it's only in pre-debugging.

Copy link
Contributor Author

@MicroFish91 MicroFish91 Apr 14, 2023

Choose a reason for hiding this comment

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

Correct, I wanted to add a guard in there so that it's extremely explicit, especially since the rest of the connection string validations use an update pattern that can happen in both debug or deploy

// Skip validation on deploy - we already connect the storage account for the user when the Function App is initially created
return;
}

const currentStorageConnection: string | undefined = await getLocalSettingsConnectionString(context, ConnectionKey.Storage, projectPath);
if (currentStorageConnection) {
if (context.action === CodeAction.Deploy) {
if (currentStorageConnection !== localStorageEmulatorConnectionString) {
// Found a valid connection in deploy mode. Set it and skip the wizard.
context[ConnectionKey.Storage] = currentStorageConnection;
return;
}
// Found an invalid connection for deploy mode, we need to proceed with acquiring a connection through the wizard...
} else {
// Found a valid connection in debug mode. Skip the wizard.
return;
}
// Found a valid connection in debug mode. Skip the wizard.
return;
}

const wizardContext: IAzureWebJobsStorageWizardContext = Object.assign(context, { projectPath });
Expand Down
12 changes: 4 additions & 8 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/

import type { SiteConfigResource } from '@azure/arm-appservice';
import { deploy as innerDeploy, getDeployFsPath, getDeployNode, IDeployContext, IDeployPaths, showDeployConfirmation } from '@microsoft/vscode-azext-azureappservice';
import { IDeployContext, IDeployPaths, getDeployFsPath, getDeployNode, deploy as innerDeploy, showDeployConfirmation } from '@microsoft/vscode-azext-azureappservice';
import { DialogResponses, IActionContext, nonNullValue } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { CodeAction, ConnectionType, deploySubpathSetting, DurableBackend, DurableBackendValues, functionFilter, ProjectLanguage, remoteBuildSetting, ScmType } from '../../constants';
import { CodeAction, ConnectionType, DurableBackend, DurableBackendValues, ProjectLanguage, ScmType, deploySubpathSetting, functionFilter, remoteBuildSetting } from '../../constants';
import { ext } from '../../extensionVariables';
import { addLocalFuncTelemetry } from '../../funcCoreTools/getLocalFuncCoreToolsVersion';
import { localize } from '../../localize';
Expand All @@ -19,9 +19,8 @@ import { isPathEqual } from '../../utils/fs';
import { treeUtils } from '../../utils/treeUtils';
import { getWorkspaceSetting } from '../../vsCodeConfig/settings';
import { verifyInitForVSCode } from '../../vsCodeConfig/verifyInitForVSCode';
import { validateStorageConnection } from '../appSettings/connectionSettings/azureWebJobsStorage/validateStorageConnection';
import { validateEventHubsConnection } from '../appSettings/connectionSettings/eventHubs/validateEventHubsConnection';
import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/ISetConnectionSettingContext';
import { validateEventHubsConnection } from '../appSettings/connectionSettings/eventHubs/validateEventHubsConnection';
import { validateSqlDbConnection } from '../appSettings/connectionSettings/sqlDatabase/validateSqlDbConnection';
import { tryGetFunctionProjectRoot } from '../createNewProject/verifyIsProject';
import { notifyDeployComplete } from './notifyDeployComplete';
Expand Down Expand Up @@ -97,12 +96,9 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string |
const durableStorageType: DurableBackendValues | undefined = await durableUtils.getStorageTypeFromWorkspace(language, context.projectPath);
context.telemetry.properties.projectDurableStorageType = durableStorageType;

const { shouldValidateStorage, shouldValidateEventHubs, shouldValidateSqlDb } = await shouldValidateConnections(durableStorageType, client, context.projectPath);
const { shouldValidateEventHubs, shouldValidateSqlDb } = await shouldValidateConnections(durableStorageType, client, context.projectPath);

// Preliminary local validation done to ensure all required resources have been created and are available. Final deploy writes are made in 'verifyAppSettings'
if (shouldValidateStorage) {
await validateStorageConnection(context, context.projectPath, { preselectedConnectionType: ConnectionType.Azure });
}
if (shouldValidateEventHubs) {
await validateEventHubsConnection(context, context.projectPath, { preselectedConnectionType: ConnectionType.Azure });
}
Expand Down
5 changes: 1 addition & 4 deletions src/commands/deploy/shouldValidateConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import { ConnectionKey, DurableBackend, DurableBackendValues } from "../../const
import { getEventHubName } from "../appSettings/connectionSettings/eventHubs/validateEventHubsConnection";

export interface IShouldValidateConnection {
shouldValidateStorage: boolean;
shouldValidateEventHubs: boolean;
shouldValidateSqlDb: boolean;
}

export async function shouldValidateConnections(durableStorageType: DurableBackendValues | undefined, client: SiteClient, projectPath: string): Promise<IShouldValidateConnection> {
const app: StringDictionary = await client.listApplicationSettings();
const remoteStorageConnection: string | undefined = app?.properties?.[ConnectionKey.Storage];
const remoteEventHubsConnection: string | undefined = app?.properties?.[ConnectionKey.EventHubs];
const remoteSqlDbConnection: string | undefined = app?.properties?.[ConnectionKey.SQL];
const eventHubName: string | undefined = await getEventHubName(projectPath);

const shouldValidateStorage: boolean = !remoteStorageConnection;
const shouldValidateEventHubs: boolean = durableStorageType === DurableBackend.Netherite && (!eventHubName || !remoteEventHubsConnection);
const shouldValidateSqlDb: boolean = durableStorageType === DurableBackend.SQL && !remoteSqlDbConnection;
return { shouldValidateStorage, shouldValidateEventHubs, shouldValidateSqlDb };
return { shouldValidateEventHubs, shouldValidateSqlDb };
}