Skip to content

Commit a66eaf2

Browse files
Support secretless extensions in V3 (#2713)
* merge conflict resolved * more merge conflicts * fix tests
1 parent c1582f5 commit a66eaf2

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private bool IsPreCompiledFunctionApp()
415415
return isPrecompiled;
416416
}
417417

418-
internal static async Task CheckNonOptionalSettings(IEnumerable<KeyValuePair<string, string>> secrets, string scriptPath, bool userSecretsEnabled)
418+
internal static async Task CheckNonOptionalSettings(IEnumerable<KeyValuePair<string, string>> secrets, string scriptPath, bool skipAzureWebJobsStorageCheck = false)
419419
{
420420
string storageConnectionKey = "AzureWebJobsStorage";
421421
try
@@ -441,15 +441,12 @@ internal static async Task CheckNonOptionalSettings(IEnumerable<KeyValuePair<str
441441
.Where(b => b.IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) != -1)
442442
.All(t => Constants.TriggersWithoutStorage.Any(tws => tws.Equals(t, StringComparison.OrdinalIgnoreCase)));
443443

444-
if (string.IsNullOrWhiteSpace(azureWebJobsStorage) &&
445-
!StorageConnectionExists(secrets, storageConnectionKey) &&
446-
!allNonStorageTriggers)
444+
if (!skipAzureWebJobsStorageCheck && string.IsNullOrWhiteSpace(azureWebJobsStorage) &&
445+
!StorageConnectionExists(secrets, storageConnectionKey) && !allNonStorageTriggers)
447446
{
448-
string errorMessage = userSecretsEnabled ? Constants.Errors.WebJobsStorageNotFoundWithUserSecrets : Constants.Errors.WebJobsStorageNotFound;
449-
throw new CliException(string.Format(errorMessage,
450-
SecretsManager.AppSettingsFileName,
451-
string.Join(", ", Constants.TriggersWithoutStorage),
452-
SecretsManager.AppSettingsFileName));
447+
throw new CliException($"Missing value for AzureWebJobsStorage in {SecretsManager.AppSettingsFileName}. " +
448+
$"This is required for all triggers other than {string.Join(", ", Constants.TriggersWithoutStorage)}. "
449+
+ $"You can run 'func azure functionapp fetch-app-settings <functionAppName>', specify a connection string in {SecretsManager.AppSettingsFileName}, or use managed identity to authenticate.");
453450
}
454451

455452
foreach ((var filePath, var functionJson) in functionsJsons)
@@ -467,14 +464,9 @@ internal static async Task CheckNonOptionalSettings(IEnumerable<KeyValuePair<str
467464
}
468465
else if (!secrets.Any(v => v.Key.Equals(appSettingName, StringComparison.OrdinalIgnoreCase)))
469466
{
470-
string warningMessage = userSecretsEnabled ? Constants.Errors.AppSettingNotFoundWithUserSecrets : Constants.Errors.AppSettingNotFound;
471-
ColoredConsole.WriteLine(WarningColor(string.Format(warningMessage,
472-
appSettingName,
473-
SecretsManager.AppSettingsFileName,
474-
token.Key,
475-
binding["type"]?.ToString(),
476-
filePath,
477-
SecretsManager.AppSettingsFileName)));
467+
ColoredConsole
468+
.WriteLine(WarningColor($"Warning: Cannot find value named '{appSettingName}' in {SecretsManager.AppSettingsFileName} that matches '{token.Key}' property set on '{binding["type"]?.ToString()}' in '{filePath}'. " +
469+
$"You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in {SecretsManager.AppSettingsFileName}."));
478470
}
479471
}
480472
}

test/Azure.Functions.Cli.Tests/ActionsTests/StartHostActionTests.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task CheckNonOptionalSettingsDoesntThrowMissingStorageUsingManagedI
6969
Exception exception = null;
7070
try
7171
{
72-
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\", false);
72+
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\");
7373
}
7474
catch (Exception e)
7575
{
@@ -81,24 +81,31 @@ public async Task CheckNonOptionalSettingsDoesntThrowMissingStorageUsingManagedI
8181
[Fact]
8282
public async Task CheckNonOptionalSettingsDoesntThrowOnMissingAzureWebJobsStorage()
8383
{
84+
Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
85+
reason: "Environment.CurrentDirectory throws in linux in test cases for some reason. Revisit this once we figure out why it's failing");
8486
var fileSystem = GetFakeFileSystem(new[]
85-
{
86-
("x:\\folder1", "{'bindings': [{'type': 'httpTrigger'}]}"),
87+
{
88+
("x:\\folder1", "{'bindings': [{'type': 'blobTrigger'}]}"),
8789
("x:\\folder2", "{'bindings': [{'type': 'httpTrigger'}]}")
8890
});
8991

92+
var secrets = new Dictionary<string, string>()
93+
{
94+
{ "AzureWebJobsStorage:blobServiceUri", "myuri" },
95+
{ "AzureWebJobsStorage__queueServiceUri", "queueuri" }
96+
};
97+
9098
FileSystemHelpers.Instance = fileSystem;
9199

92100
Exception exception = null;
93101
try
94102
{
95-
await StartHostAction.CheckNonOptionalSettings(new Dictionary<string, string>(), "x:\\", false);
103+
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\", false);
96104
}
97105
catch (Exception e)
98106
{
99107
exception = e;
100108
}
101-
102109
exception.Should().BeNull();
103110
}
104111

0 commit comments

Comments
 (0)