-
Notifications
You must be signed in to change notification settings - Fork 144
feat: add dynamic Azurite connection string generation using workspace settings #4667
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,10 @@ import * as path from 'path'; | |
| import * as vscode from 'vscode'; | ||
| import { decryptLocalSettings } from '../commands/appSettings/localSettings/decryptLocalSettings'; | ||
| import { encryptLocalSettings } from '../commands/appSettings/localSettings/encryptLocalSettings'; | ||
| import { localSettingsFileName, type ConnectionKey } from '../constants'; | ||
| import { azuriteAccountKey, localSettingsFileName, localStorageEmulatorConnectionString, type ConnectionKey } from '../constants'; | ||
| import { localize } from '../localize'; | ||
| import { parseJson } from '../utils/parseJson'; | ||
| import { getWorkspaceSetting } from '../vsCodeConfig/settings'; | ||
|
|
||
| export interface ILocalSettingsJson { | ||
| IsEncrypted?: boolean; | ||
|
|
@@ -19,14 +20,48 @@ export interface ILocalSettingsJson { | |
| ConnectionStrings?: { [key: string]: string }; | ||
| } | ||
|
|
||
| export async function getLocalSettingsConnectionString(context: IActionContext, connectionKey: ConnectionKey, projectPath: string): Promise<string | undefined> { | ||
| export async function getLocalSettingsConnectionString(context: IActionContext, connectionKey: ConnectionKey, projectPath: string): Promise<[string | undefined, boolean]> { | ||
| // func cli uses environment variable if it's defined on the machine, so no need to prompt | ||
| if (process.env[connectionKey]) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The return value should be
|
||
| return process.env[connectionKey]; | ||
| return [process.env[connectionKey], isConnectionStringEmulator(process.env[connectionKey])]; | ||
| } | ||
|
|
||
| const settings: ILocalSettingsJson = await getLocalSettingsJson(context, path.join(projectPath, localSettingsFileName)); | ||
| return settings.Values && settings.Values[connectionKey]; | ||
| let connectionString = settings.Values && settings.Values[connectionKey]; | ||
| if (connectionString === localStorageEmulatorConnectionString) { | ||
| // check for azurite settings and build the connection string if it's an emulator | ||
| connectionString = getLocalSettingsEmulatorConnectionString(); | ||
| } | ||
| const isEmulator = isConnectionStringEmulator(connectionString); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing null check for The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| return [connectionString, isEmulator]; | ||
| } | ||
|
|
||
| function getLocalSettingsEmulatorConnectionString(): string { | ||
| const blobHost = getWorkspaceSetting('blobHost', undefined, 'azurite') || '127.0.0.1'; | ||
| const blobPort = getWorkspaceSetting('blobPort', undefined, 'azurite') || '10000'; | ||
| const queueHost = getWorkspaceSetting('queueHost', undefined, 'azurite') || '127.0.0.1'; | ||
| const queuePort = getWorkspaceSetting('queuePort', undefined, 'azurite') || '10001'; | ||
| const tableHost = getWorkspaceSetting('tableHost', undefined, 'azurite') || '127.0.0.1'; | ||
| const tablePort = getWorkspaceSetting('tablePort', undefined, 'azurite') || '10002'; | ||
|
|
||
| const protocol = getTransferProtocol(); | ||
| return `DefaultEndpointsProtocol=${protocol};AccountName=devstoreaccount1;AccountKey=${azuriteAccountKey}/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=${protocol}://${blobHost}:${blobPort}/devstoreaccount1;QueueEndpoint=${protocol}://${queueHost}:${queuePort}/devstoreaccount1;TableEndpoint=${protocol}://${tableHost}:${tablePort}/devstoreaccount1;`; | ||
| } | ||
|
|
||
| function isConnectionStringEmulator(connectionString: string | undefined): boolean { | ||
| const blobHost: string = getWorkspaceSetting('blobHost', undefined, 'azurite') || '127.0.0.1'; | ||
| const queueHost: string = getWorkspaceSetting('queueHost', undefined, 'azurite') || '127.0.0.1'; | ||
| const tableHost: string = getWorkspaceSetting('tableHost', undefined, 'azurite') || '127.0.0.1'; | ||
|
|
||
| return !!connectionString && | ||
| (connectionString.includes(blobHost) || | ||
| connectionString.includes(queueHost) || | ||
| connectionString.includes(tableHost) | ||
| ); | ||
| } | ||
|
|
||
| function getTransferProtocol(): string { | ||
| return getWorkspaceSetting('cert', undefined, 'azurite') && getWorkspaceSetting('key', undefined, 'azurite') ? 'https' : 'http'; | ||
| } | ||
|
|
||
| export enum MismatchBehavior { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The destructuring assignment here correctly handles the new tuple return type from
getLocalSettingsConnectionString(). TheisEmulatorboolean provides better semantic clarity than string comparison.Review generated with Copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to tell me that I am doing things correctly. Please don't do that.