Skip to content

Commit c82b497

Browse files
authored
Try/catch the functions that get warnings for deployment (#4479)
1 parent 34df673 commit c82b497

File tree

2 files changed

+75
-61
lines changed

2 files changed

+75
-61
lines changed

src/commands/createFunctionApp/stacks/getStackPicks.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -300,64 +300,68 @@ export async function getEolWarningMessages(context: ISubscriptionActionContext,
300300
displayVersion: string | undefined;
301301
} = { endOfLife: undefined, displayVersion: undefined };
302302

303-
if (options.isFlex) {
304-
const runtime = options.site.functionAppConfig?.runtime?.name;
305-
version = options.site.functionAppConfig?.runtime?.version;
306-
displayInfo = (await getEOLDate(context, {
307-
site: options.site,
308-
version: nonNullValue(version),
309-
runtime: nonNullValue(runtime) === 'dotnet-isolated' ? 'dotnet' : nonNullValue(runtime),
310-
isFlex: true,
311-
location: options.site.location
312-
})
313-
);
314-
} else if (options.isLinux) {
315-
const linuxFxVersion = options.site.siteConfig?.linuxFxVersion;
316-
displayInfo = await getEOLLinuxFxVersion(context, nonNullValue(linuxFxVersion));
317-
} else if (options.site.siteConfig) {
318-
if (options.site.siteConfig.javaVersion) {
319-
displayInfo = (await getEOLDate(context, {
320-
site: options.site,
321-
version: options.site.siteConfig.javaVersion,
322-
runtime: 'java'
323-
}));
324-
} else if (options.site.siteConfig.powerShellVersion) {
303+
try {
304+
if (options.isFlex) {
305+
const runtime = options.site.functionAppConfig?.runtime?.name;
306+
version = options.site.functionAppConfig?.runtime?.version;
325307
displayInfo = (await getEOLDate(context, {
326308
site: options.site,
327-
version: options.site.siteConfig.powerShellVersion,
328-
runtime: 'powershell'
329-
}));
330-
} else if (options.site.siteConfig.netFrameworkVersion) {
331-
// In order to get the node version, we need to check the app settings
332-
let appSettings: StringDictionary | undefined;
333-
if (options.client) {
334-
appSettings = await options.client.listApplicationSettings();
335-
}
336-
if (appSettings && appSettings.properties && appSettings.properties['WEBSITE_NODE_DEFAULT_VERSION']) {
309+
version: nonNullValue(version),
310+
runtime: nonNullValue(runtime) === 'dotnet-isolated' ? 'dotnet' : nonNullValue(runtime),
311+
isFlex: true,
312+
location: options.site.location
313+
})
314+
);
315+
} else if (options.isLinux) {
316+
const linuxFxVersion = options.site.siteConfig?.linuxFxVersion;
317+
displayInfo = await getEOLLinuxFxVersion(context, nonNullValue(linuxFxVersion));
318+
} else if (options.site.siteConfig) {
319+
if (options.site.siteConfig.javaVersion) {
337320
displayInfo = (await getEOLDate(context, {
338321
site: options.site,
339-
version: appSettings.properties['WEBSITE_NODE_DEFAULT_VERSION'],
340-
runtime: 'node'
322+
version: options.site.siteConfig.javaVersion,
323+
runtime: 'java'
341324
}));
342-
} else {
325+
} else if (options.site.siteConfig.powerShellVersion) {
343326
displayInfo = (await getEOLDate(context, {
344327
site: options.site,
345-
version: options.site.siteConfig.netFrameworkVersion,
346-
runtime: 'dotnet'
328+
version: options.site.siteConfig.powerShellVersion,
329+
runtime: 'powershell'
347330
}));
331+
} else if (options.site.siteConfig.netFrameworkVersion) {
332+
// In order to get the node version, we need to check the app settings
333+
let appSettings: StringDictionary | undefined;
334+
if (options.client) {
335+
appSettings = await options.client.listApplicationSettings();
336+
}
337+
if (appSettings && appSettings.properties && appSettings.properties['WEBSITE_NODE_DEFAULT_VERSION']) {
338+
displayInfo = (await getEOLDate(context, {
339+
site: options.site,
340+
version: appSettings.properties['WEBSITE_NODE_DEFAULT_VERSION'],
341+
runtime: 'node'
342+
}));
343+
} else {
344+
displayInfo = (await getEOLDate(context, {
345+
site: options.site,
346+
version: options.site.siteConfig.netFrameworkVersion,
347+
runtime: 'dotnet'
348+
}));
349+
}
348350
}
349351
}
350-
}
351352

352-
if (displayInfo.endOfLife) {
353-
const sixMonthsFromNow = new Date(new Date().setMonth(new Date().getMonth() + 6));
354-
isEOL = displayInfo.endOfLife <= new Date();
355-
willBeEOL = displayInfo.endOfLife <= sixMonthsFromNow;
356-
if (isEOL) {
357-
return localize('eolWarning', 'Upgrade to the latest available version as version {0} has reached end-of-life on {1} and is no longer supported.', displayInfo.displayVersion, displayInfo.endOfLife.toLocaleDateString());
358-
} else if (willBeEOL) {
359-
return localize('willBeEolWarning', 'Upgrade to the latest available version as version {0} will reach end-of-life on {1} and will no longer be supported.', displayInfo.displayVersion, displayInfo.endOfLife.toLocaleDateString());
353+
if (displayInfo.endOfLife) {
354+
const sixMonthsFromNow = new Date(new Date().setMonth(new Date().getMonth() + 6));
355+
isEOL = displayInfo.endOfLife <= new Date();
356+
willBeEOL = displayInfo.endOfLife <= sixMonthsFromNow;
357+
if (isEOL) {
358+
return localize('eolWarning', 'Upgrade to the latest available version as version {0} has reached end-of-life on {1} and is no longer supported.', displayInfo.displayVersion, displayInfo.endOfLife.toLocaleDateString());
359+
} else if (willBeEOL) {
360+
return localize('willBeEolWarning', 'Upgrade to the latest available version as version {0} will reach end-of-life on {1} and will no longer be supported.', displayInfo.displayVersion, displayInfo.endOfLife.toLocaleDateString());
361+
}
360362
}
363+
} catch (error) {
364+
// do nothing, we don't want to show an error message if we can't get the EOL date
361365
}
362366

363367
return '';

src/commands/deploy/getWarningsForConnectionSettings.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,35 @@ export async function getWarningsForConnectionSettings(context: IActionContext,
2020
node: SlotTreeItem,
2121
projectPath: string | undefined
2222
}): Promise<string | undefined> {
23+
try {
24+
const localSettingsPath = await tryGetLocalSettingsFileNoPrompt(context, options.projectPath);
25+
let localSettings: ILocalSettingsJson;
26+
try {
27+
localSettings = localSettingsPath ? await AzExtFsExtra.readJSON(localSettingsPath) : { Values: {} };
28+
} catch (err) {
29+
// if we can't read the local settings, just assume it's empty
30+
localSettings = { Values: {} };
31+
}
2332

24-
const localSettingsPath = await tryGetLocalSettingsFileNoPrompt(context, options.projectPath);
25-
const localSettings: ILocalSettingsJson = localSettingsPath ? await AzExtFsExtra.readJSON(localSettingsPath) : { Values: {} };
26-
const localConnectionSettings = await getConnectionSettings(localSettings.Values ?? {});
27-
const remoteConnectionSettings = await getConnectionSettings(options.appSettings?.properties ?? {});
33+
const localConnectionSettings = await getConnectionSettings(localSettings.Values ?? {});
34+
const remoteConnectionSettings = await getConnectionSettings(options.appSettings?.properties ?? {});
2835

29-
if (localConnectionSettings.some(setting => setting.type === 'ManagedIdentity')) {
30-
if (!options.node.site.rawSite.identity ||
31-
options.node.site.rawSite.identity.type === 'None') {
32-
// if they have nothing in remote, warn them to connect a managed identity
33-
return localize('configureManagedIdentityWarning',
34-
'Your app is not connected to a managed identity. To ensure access, please configure a managed identity. Without it, your application may encounter authorization issues.');
36+
if (localConnectionSettings.some(setting => setting.type === 'ManagedIdentity')) {
37+
if (!options.node.site.rawSite.identity ||
38+
options.node.site.rawSite.identity.type === 'None') {
39+
// if they have nothing in remote, warn them to connect a managed identity
40+
return localize('configureManagedIdentityWarning',
41+
'Your app is not connected to a managed identity. To ensure access, please configure a managed identity. Without it, your application may encounter authorization issues.');
42+
}
3543
}
36-
}
3744

38-
if (localConnectionSettings.some(setting => setting.type === 'ConnectionString') || remoteConnectionSettings.some(setting => setting.type === 'ConnectionString')) {
39-
// if they have connection strings, warn them about insecure connections but don't try to convert them
40-
return localize('connectionStringWarning',
41-
'Your app may be using connection strings for authentication. This may expose sensitive credentials and lead to security vulnerabilities. Consider using managed identities to enhance security.')
45+
if (localConnectionSettings.some(setting => setting.type === 'ConnectionString') || remoteConnectionSettings.some(setting => setting.type === 'ConnectionString')) {
46+
// if they have connection strings, warn them about insecure connections but don't try to convert them
47+
return localize('connectionStringWarning',
48+
'Your app may be using connection strings for authentication. This may expose sensitive credentials and lead to security vulnerabilities. Consider using managed identities to enhance security.')
49+
}
50+
} catch (err) {
51+
// if we can't read local or remote settings, don't warn them about anything
4252
}
4353

4454
return;

0 commit comments

Comments
 (0)