Skip to content

Commit

Permalink
Merge branch 'v3.x' into v4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brettsam committed Sep 20, 2021
2 parents 3235f24 + a66eaf2 commit 2b9e0e6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
26 changes: 9 additions & 17 deletions src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private bool IsPreCompiledFunctionApp()
return isPrecompiled;
}

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

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

foreach ((var filePath, var functionJson) in functionsJsons)
Expand All @@ -467,14 +464,9 @@ internal static async Task CheckNonOptionalSettings(IEnumerable<KeyValuePair<str
}
else if (!secrets.Any(v => v.Key.Equals(appSettingName, StringComparison.OrdinalIgnoreCase)))
{
string warningMessage = userSecretsEnabled ? Constants.Errors.AppSettingNotFoundWithUserSecrets : Constants.Errors.AppSettingNotFound;
ColoredConsole.WriteLine(WarningColor(string.Format(warningMessage,
appSettingName,
SecretsManager.AppSettingsFileName,
token.Key,
binding["type"]?.ToString(),
filePath,
SecretsManager.AppSettingsFileName)));
ColoredConsole
.WriteLine(WarningColor($"Warning: Cannot find value named '{appSettingName}' in {SecretsManager.AppSettingsFileName} that matches '{token.Key}' property set on '{binding["type"]?.ToString()}' in '{filePath}'. " +
$"You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in {SecretsManager.AppSettingsFileName}."));
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/Azure.Functions.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Autofac;
using Colors.Net;
using Azure.Functions.Cli.Arm;
Expand All @@ -15,7 +16,7 @@ internal static void Main(string[] args)
{
FirstTimeCliExperience();
SetupGlobalExceptionHandler();
SetCoreToolsEnvironmentVaraibles();
SetCoreToolsEnvironmentVariables(args);
ConsoleApp.Run<Program>(args, InitializeAutofacContainer());
}

Expand Down Expand Up @@ -43,10 +44,14 @@ private static void FirstTimeCliExperience()
}
}

private static void SetCoreToolsEnvironmentVaraibles()
private static void SetCoreToolsEnvironmentVariables(string[] args)
{
EnvironmentHelper.SetEnvironmentVariableAsBoolIfNotExists(Constants.FunctionsCoreToolsEnvironment);
EnvironmentHelper.SetEnvironmentVariableAsBoolIfNotExists(Constants.SequentialJobHostRestart);
if (args.Contains("--debug", StringComparer.OrdinalIgnoreCase))
{
Environment.SetEnvironmentVariable(Constants.CliDebug, "1");
}
}

internal static IContainer InitializeAutofacContainer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS installer-env

# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task CheckNonOptionalSettingsDoesntThrowMissingStorageUsingManagedI
Exception exception = null;
try
{
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\", false);
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\");
}
catch (Exception e)
{
Expand All @@ -81,24 +81,31 @@ public async Task CheckNonOptionalSettingsDoesntThrowMissingStorageUsingManagedI
[Fact]
public async Task CheckNonOptionalSettingsDoesntThrowOnMissingAzureWebJobsStorage()
{
Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
reason: "Environment.CurrentDirectory throws in linux in test cases for some reason. Revisit this once we figure out why it's failing");
var fileSystem = GetFakeFileSystem(new[]
{
("x:\\folder1", "{'bindings': [{'type': 'httpTrigger'}]}"),
{
("x:\\folder1", "{'bindings': [{'type': 'blobTrigger'}]}"),
("x:\\folder2", "{'bindings': [{'type': 'httpTrigger'}]}")
});

var secrets = new Dictionary<string, string>()
{
{ "AzureWebJobsStorage:blobServiceUri", "myuri" },
{ "AzureWebJobsStorage__queueServiceUri", "queueuri" }
};

FileSystemHelpers.Instance = fileSystem;

Exception exception = null;
try
{
await StartHostAction.CheckNonOptionalSettings(new Dictionary<string, string>(), "x:\\", false);
await StartHostAction.CheckNonOptionalSettings(secrets, "x:\\", false);
}
catch (Exception e)
{
exception = e;
}

exception.Should().BeNull();
}

Expand Down

0 comments on commit 2b9e0e6

Please sign in to comment.