Skip to content

Commit 12d3f4b

Browse files
committed
setting up extension bundle config and validation
1 parent a682307 commit 12d3f4b

File tree

12 files changed

+460
-3
lines changed

12 files changed

+460
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using NuGet.Versioning;
6+
7+
namespace Microsoft.Azure.WebJobs.Script.BindingExtensionBundle
8+
{
9+
public class ExtensionBundleOptions
10+
{
11+
public string Id { get; set; }
12+
13+
public VersionRange Version { get; set; }
14+
}
15+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.Azure.WebJobs.Script.Configuration;
6+
using Microsoft.Azure.WebJobs.Script.Properties;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Logging;
9+
using Microsoft.Extensions.Options;
10+
using NuGet.Packaging;
11+
using NuGet.Versioning;
12+
13+
namespace Microsoft.Azure.WebJobs.Script.BindingExtensionBundle
14+
{
15+
internal class ExtensionBundleOptionsSetup : IConfigureOptions<ExtensionBundleOptions>
16+
{
17+
private readonly IConfiguration _configuration;
18+
19+
public ExtensionBundleOptionsSetup(IConfiguration configuration)
20+
{
21+
_configuration = configuration;
22+
}
23+
24+
public void Configure(ExtensionBundleOptions options)
25+
{
26+
IConfigurationSection jobHostSection = _configuration.GetSection(ConfigurationSectionNames.JobHost);
27+
var extensionBundleSection = jobHostSection.GetSection(ConfigurationSectionNames.ExtensionBundle);
28+
extensionBundleSection.Bind(options);
29+
30+
if (extensionBundleSection.Exists())
31+
{
32+
ValidateBundleId(options.Id);
33+
ConfigureBundleVersion(extensionBundleSection, options);
34+
}
35+
}
36+
37+
private static void ConfigureBundleVersion(IConfigurationSection configurationSection, ExtensionBundleOptions options)
38+
{
39+
string bundleVersion = configurationSection.GetValue<string>("version");
40+
if (string.IsNullOrWhiteSpace(bundleVersion) || !VersionRange.TryParse(bundleVersion.ToString(), out VersionRange version))
41+
{
42+
string message = string.Format(Resources.ExtensionBundleConfigMissingVersion, ScriptConstants.HostMetadataFileName);
43+
throw new ArgumentException(message);
44+
}
45+
options.Version = version;
46+
}
47+
48+
private static void ValidateBundleId(string id)
49+
{
50+
if (string.IsNullOrWhiteSpace(id) || !PackageIdValidator.IsValidPackageId(id))
51+
{
52+
string message = string.Format(Resources.ExtensionBundleConfigMissingId, ScriptConstants.HostMetadataFileName);
53+
throw new ArgumentException(message);
54+
}
55+
}
56+
}
57+
}

src/WebJobs.Script/BindingExtensions/ExtensionsManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ internal virtual Task ProcessExtensionsProject(string projectFolder)
153153
}
154154
else
155155
{
156-
ProcessReults(projectFolder)
156+
ProcessResults(projectFolder)
157157
.ContinueWith(t =>
158158
{
159159
if (t.IsFaulted)
@@ -234,7 +234,7 @@ private void LogOutput(string data, StringBuilder logBuilder)
234234
logBuilder.Append(data);
235235
}
236236

237-
private async Task ProcessReults(string tempFolder)
237+
private async Task ProcessResults(string tempFolder)
238238
{
239239
string sourceBin = Path.Combine(tempFolder, "bin");
240240
string target = Path.Combine(_scriptRootPath, "bin");

src/WebJobs.Script/Config/ConfigurationSectionNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public static class ConfigurationSectionNames
1111
public const string Aggregator = "aggregator";
1212
public const string HealthMonitor = "healthMonitor";
1313
public const string HostIdPath = WebHost + ":hostid";
14+
public const string ExtensionBundle = "extensionBundle";
1415
}
1516
}

src/WebJobs.Script/Config/HostJsonFileConfigurationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private class HostJsonFileConfigurationProvider : ConfigurationProvider
4545
private static readonly string[] WellKnownHostJsonProperties = new[]
4646
{
4747
"version", "functionTimeout", "functions", "http", "watchDirectories", "queues", "serviceBus",
48-
"eventHub", "singleton", "logging", "aggregator", "healthMonitor"
48+
"eventHub", "singleton", "logging", "aggregator", "healthMonitor", "extensionBundle"
4949
};
5050

5151
private readonly HostJsonFileConfigurationSource _configurationSource;

src/WebJobs.Script/Environment/EnvironmentExtensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Runtime.InteropServices;
67
using static Microsoft.Azure.WebJobs.Script.EnvironmentSettingNames;
78

89
namespace Microsoft.Azure.WebJobs.Script
@@ -61,6 +62,39 @@ public static bool IsZipDeployment(this IEnvironment environment)
6162
!string.IsNullOrEmpty(environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteRunFromPackage));
6263
}
6364

65+
public static bool IsAppServiceWindowsEnvironment(this IEnvironment environment)
66+
{
67+
return environment.IsAppServiceEnvironment() && RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
68+
}
69+
70+
public static bool IsCoreToolsEnvironment(this IEnvironment environment)
71+
{
72+
return !string.IsNullOrEmpty(environment.GetEnvironmentVariable(CoreToolsEnvironment));
73+
}
74+
75+
public static bool IsPersistentFileSystemAvailable(this IEnvironment environment)
76+
{
77+
return environment.IsAppServiceWindowsEnvironment()
78+
|| environment.IsLinuxAppServiceEnvWithPersistentFileSystem()
79+
|| environment.IsCoreToolsEnvironment();
80+
}
81+
82+
public static bool IsLinuxAppServiceEnvWithPersistentFileSystem(this IEnvironment environment)
83+
{
84+
if (environment.IsLinuxAppServiceEnvironment())
85+
{
86+
string storageConfig = environment.GetEnvironmentVariable(LinuxAzureAppServiceStorage);
87+
88+
// AzureAppServiceStorage is enabled by default, So return if true it is not set
89+
if (string.IsNullOrEmpty(storageConfig))
90+
{
91+
return true;
92+
}
93+
return bool.TryParse(storageConfig, out bool storageConfigValue) && storageConfigValue;
94+
}
95+
return false;
96+
}
97+
6498
public static bool FileSystemIsReadOnly(this IEnvironment environment)
6599
{
66100
return environment.IsZipDeployment();

src/WebJobs.Script/Environment/EnvironmentSettingNames.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ public static class EnvironmentSettingNames
4747
public const string AzureWebsiteAltZipDeployment = "WEBSITE_RUN_FROM_ZIP";
4848
public const string AzureWebsiteRunFromPackage = "WEBSITE_RUN_FROM_PACKAGE";
4949
public const string RegionName = "REGION_NAME";
50+
51+
public const string LinuxAzureAppServiceStorage = "WEBSITES_ENABLE_APP_SERVICE_STORAGE";
52+
public const string CoreToolsEnvironment = "FUNCTIONS_CORETOOLS_ENVIRONMENT";
5053
}
5154
}

src/WebJobs.Script/Properties/Resources.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Script/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@
123123
<data name="LanguageWorkerChannelSpecializationTrace" xml:space="preserve">
124124
<value>Starting language worker channel specialization</value>
125125
</data>
126+
<data name="ExtensionBundleConfigMissingId" xml:space="preserve">
127+
<value>The value of id property in extensionBundle section of {0} file is invalid or missing. See https://aka.ms/functions-hostjson for more information</value>
128+
</data>
129+
<data name="ExtensionBundleConfigMissingMessage" xml:space="preserve">
130+
<value>The id and version property are missing in extensionBundle section of {0} file. See https://aka.ms/functions-hostjson for more information"</value>
131+
</data>
132+
<data name="ExtensionBundleConfigMissingVersion" xml:space="preserve">
133+
<value>The value of version property in extensionBundle section of {0} file is invalid or missing. See https://aka.ms/functions-hostjson for more information</value>
134+
</data>
126135
</root>

src/WebJobs.Script/ScriptHostBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Azure.WebJobs.Logging.ApplicationInsights;
1212
using Microsoft.Azure.WebJobs.Script.Abstractions;
1313
using Microsoft.Azure.WebJobs.Script.Binding;
14+
using Microsoft.Azure.WebJobs.Script.BindingExtensionBundle;
1415
using Microsoft.Azure.WebJobs.Script.BindingExtensions;
1516
using Microsoft.Azure.WebJobs.Script.Config;
1617
using Microsoft.Azure.WebJobs.Script.Configuration;
@@ -142,6 +143,7 @@ public static IHostBuilder AddScriptHostCore(this IHostBuilder builder, ScriptAp
142143
services.ConfigureOptions<JobHostFunctionTimeoutOptionsSetup>();
143144
// TODO: pgopa only add this to WebHostServiceCollection
144145
services.ConfigureOptions<LanguageWorkerOptionsSetup>();
146+
services.ConfigureOptions<ExtensionBundleOptionsSetup>();
145147
services.AddOptions<FunctionResultAggregatorOptions>()
146148
.Configure<IConfiguration>((o, c) =>
147149
{

0 commit comments

Comments
 (0)