Skip to content

Commit 4e6f48e

Browse files
nturinskiNathan Turinski
andauthored
Fallback to storage suffix endpoint if not available (#4929)
Co-authored-by: Nathan Turinski <naturins@microsoft.comm>
1 parent e29231c commit 4e6f48e

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/commands/createFunctionApp/FunctionAppCreateStep.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,24 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStepWithActivityOut
147147
private async getNewSiteConfig(context: IFunctionAppWizardContext, stack?: FullFunctionAppStack): Promise<SiteConfig> {
148148
let newSiteConfig: SiteConfig = {};
149149

150-
const storageConnectionString: string = (await getStorageConnectionString(context)).connectionString;
150+
const isElasticPremium: boolean = context.plan?.sku?.family?.toLowerCase() === 'ep';
151+
const isConsumption: boolean = context.plan?.sku?.family?.toLowerCase() === 'y';
152+
// no stack means it's a flex app
153+
const isFlex: boolean = !stack;
154+
155+
// Only fetch the storage connection string when it's actually needed.
156+
// It's not needed for flex + managed identity since all storage settings use service URIs.
157+
const needsConnectionString: boolean = !(isFlex && context.managedIdentity);
158+
const storageConnectionString: string | undefined = needsConnectionString ?
159+
(await getStorageConnectionString(context)).connectionString : undefined;
151160

152161
let appSettings: NameValuePair[] = [];
153162
if (context.managedIdentity) {
154163
appSettings.push(...createAzureWebJobsStorageManagedIdentitySettings(context));
155164
} else {
156165
appSettings.push({
157166
name: ConnectionKey.Storage,
158-
value: storageConnectionString
167+
value: nonNullProp({ storageConnectionString }, 'storageConnectionString')
159168
});
160169
}
161170

@@ -176,20 +185,16 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStepWithActivityOut
176185
if (context.version === FuncVersion.v1) {
177186
appSettings.push({
178187
name: 'AzureWebJobsDashboard',
179-
value: storageConnectionString
188+
value: nonNullProp({ storageConnectionString }, 'storageConnectionString')
180189
});
181190
}
182191

183-
const isElasticPremium: boolean = context.plan?.sku?.family?.toLowerCase() === 'ep';
184-
const isConsumption: boolean = context.plan?.sku?.family?.toLowerCase() === 'y';
185-
// no stack means it's a flex app
186-
const isFlex: boolean = !stack;
187192
if (isConsumption || isElasticPremium) {
188193
// WEBSITE_CONTENT* settings are added for consumption/premium plans, but not dedicated
189194
// https://github.com/microsoft/vscode-azurefunctions/issues/1702
190195
appSettings.push({
191196
name: contentConnectionStringKey,
192-
value: storageConnectionString
197+
value: nonNullProp({ storageConnectionString }, 'storageConnectionString')
193198
});
194199
appSettings.push({
195200
name: contentShareKey,
@@ -199,7 +204,7 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStepWithActivityOut
199204
} else if (isFlex && !context.managedIdentity) {
200205
appSettings.push({
201206
name: 'DEPLOYMENT_STORAGE_CONNECTION_STRING',
202-
value: storageConnectionString
207+
value: nonNullProp({ storageConnectionString }, 'storageConnectionString')
203208
});
204209
}
205210

src/utils/managedIdentityUtils.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,37 @@ import { nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
88
import { type IFunctionAppWizardContext } from "../commands/createFunctionApp/IFunctionAppWizardContext";
99
import { ConnectionKey } from "../constants";
1010

11+
const defaultStorageEndpointSuffix = 'core.windows.net';
12+
13+
/**
14+
* Gets the storage endpoint suffix from the Azure environment, stripping any leading dot.
15+
* Falls back to 'core.windows.net' if the environment doesn't provide one.
16+
*/
17+
function getStorageEndpointSuffix(context: IFunctionAppWizardContext): string {
18+
let suffix: string = context.environment?.storageEndpointSuffix ?? defaultStorageEndpointSuffix;
19+
// https://github.com/Azure/azure-sdk-for-node/issues/4706
20+
if (suffix.startsWith('.')) {
21+
suffix = suffix.substring(1);
22+
}
23+
return suffix;
24+
}
25+
1126
export function createAzureWebJobsStorageManagedIdentitySettings(context: IFunctionAppWizardContext): NameValuePair[] {
1227
const appSettings: NameValuePair[] = [];
1328
const storageAccountName = context.newStorageAccountName ?? context.storageAccount?.name;
1429
if (context.managedIdentity) {
30+
const endpointSuffix = getStorageEndpointSuffix(context);
1531
appSettings.push({
1632
name: `${ConnectionKey.Storage}__blobServiceUri`,
17-
value: `https://${storageAccountName}.blob.core.windows.net`
33+
value: `https://${storageAccountName}.blob.${endpointSuffix}`
1834
});
1935
appSettings.push({
2036
name: `${ConnectionKey.Storage}__queueServiceUri`,
21-
value: `https://${storageAccountName}.queue.core.windows.net`
37+
value: `https://${storageAccountName}.queue.${endpointSuffix}`
2238
});
2339
appSettings.push({
2440
name: `${ConnectionKey.Storage}__tableServiceUri`,
25-
value: `https://${storageAccountName}.table.core.windows.net`
41+
value: `https://${storageAccountName}.table.${endpointSuffix}`
2642
});
2743
appSettings.push({
2844
name: `${ConnectionKey.Storage}__clientId`,

0 commit comments

Comments
 (0)