-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension bundle probing and download
- Loading branch information
Showing
25 changed files
with
1,199 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
src/WebJobs.Script/BindingExtensionBundle/ExtensionBundleOptionsSetup.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/WebJobs.Script/Config/ExtensionBundleConfigurationSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration.Json; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using static System.Environment; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Configuration | ||
{ | ||
public class ExtensionBundleConfigurationSource : FileConfigurationSource | ||
{ | ||
private const string IdProperty = "id"; | ||
private const string VersionProperty = "version"; | ||
|
||
public bool IsAppServiceEnvironment { get; set; } | ||
|
||
public override IConfigurationProvider Build(IConfigurationBuilder builder) | ||
{ | ||
if (IsAppServiceEnvironment) | ||
{ | ||
string home = GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHomePath); | ||
Path = System.IO.Path.Combine(home, "site", "wwwroot", ScriptConstants.HostMetadataFileName); | ||
} | ||
else | ||
{ | ||
string root = GetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsScriptRoot); | ||
Path = System.IO.Path.Combine(root, ScriptConstants.HostMetadataFileName); | ||
} | ||
|
||
ReloadOnChange = true; | ||
ResolveFileProvider(); | ||
return new ExtensionBundleConfigurationProvider(this); | ||
} | ||
|
||
public class ExtensionBundleConfigurationProvider : FileConfigurationProvider | ||
{ | ||
public ExtensionBundleConfigurationProvider(ExtensionBundleConfigurationSource configurationSource) : base(configurationSource) { } | ||
|
||
public override void Load(Stream stream) | ||
{ | ||
using (var reader = new StreamReader(stream)) | ||
{ | ||
string json = reader.ReadToEnd(); | ||
JObject configObject = JObject.Parse(json); | ||
|
||
var bundleConfig = configObject?[ConfigurationSectionNames.ExtensionBundle]; | ||
if (bundleConfig == null) | ||
{ | ||
return; | ||
} | ||
|
||
var bundleSection = ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, ConfigurationSectionNames.ExtensionBundle); | ||
var idProperty = ConfigurationPath.Combine(bundleSection, IdProperty); | ||
var versionProperty = ConfigurationPath.Combine(bundleSection, VersionProperty); | ||
|
||
if (bundleConfig.Type != JTokenType.Object) | ||
{ | ||
Data[bundleSection] = string.Empty; | ||
} | ||
else | ||
{ | ||
Data[idProperty] = bundleConfig?[IdProperty]?.Value<string>(); | ||
Data[versionProperty] = bundleConfig?[VersionProperty]?.Value<string>(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Azure.WebJobs.Script.Properties; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using NuGet.Packaging; | ||
using NuGet.Versioning; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Configuration | ||
{ | ||
public class ExtensionBundleOptionsSetup : IConfigureOptions<ExtensionBundleOptions> | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly IEnvironment _environment; | ||
private readonly IHostingEnvironment _hostingEnvironment; | ||
|
||
public ExtensionBundleOptionsSetup(IConfiguration configuration, IEnvironment environment, IHostingEnvironment hostingEnvironment) | ||
{ | ||
_configuration = configuration; | ||
_environment = environment; | ||
_hostingEnvironment = hostingEnvironment; | ||
} | ||
|
||
public void Configure(ExtensionBundleOptions options) | ||
{ | ||
IConfigurationSection jobHostSection = _configuration.GetSection(ConfigurationSectionNames.JobHost); | ||
var extensionBundleSection = jobHostSection.GetSection(ConfigurationSectionNames.ExtensionBundle); | ||
extensionBundleSection.Bind(options); | ||
|
||
if (extensionBundleSection.Exists()) | ||
{ | ||
ValidateBundleId(options.Id); | ||
ConfigureBundleVersion(extensionBundleSection, options); | ||
|
||
if (_environment.IsAppServiceEnvironment() || _hostingEnvironment.IsDevelopment()) | ||
{ | ||
options.DownloadPath = Path.Combine(_environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHomePath), | ||
"data", "Functions", ScriptConstants.ExtensionBundleDirectory, options.Id); | ||
ConfigureProbingPaths(options); | ||
} | ||
} | ||
} | ||
|
||
private void ConfigureBundleVersion(IConfigurationSection configurationSection, ExtensionBundleOptions options) | ||
{ | ||
string bundleVersion = configurationSection.GetValue<string>("version"); | ||
if (string.IsNullOrWhiteSpace(bundleVersion) || !VersionRange.TryParse(bundleVersion.ToString(), allowFloating: true, out VersionRange version)) | ||
{ | ||
string message = string.Format(Resources.ExtensionBundleConfigMissingVersion, ScriptConstants.HostMetadataFileName); | ||
throw new ArgumentException(message); | ||
} | ||
options.Version = version; | ||
} | ||
|
||
private void ValidateBundleId(string id) | ||
{ | ||
if (string.IsNullOrWhiteSpace(id) || !PackageIdValidator.IsValidPackageId(id)) | ||
{ | ||
string message = string.Format(Resources.ExtensionBundleConfigMissingId, ScriptConstants.HostMetadataFileName); | ||
throw new ArgumentException(message); | ||
} | ||
} | ||
|
||
private void ConfigureProbingPaths(ExtensionBundleOptions options) | ||
{ | ||
if (_environment.IsAppServiceWindowsEnvironment() || _hostingEnvironment.IsDevelopment()) | ||
{ | ||
string windowsDefaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), | ||
ScriptConstants.DefaultExtensionBundleDirectory, | ||
options.Id); | ||
|
||
options.ProbingPaths.Add(windowsDefaultPath); | ||
} | ||
|
||
if (_environment.IsLinuxAppServiceEnvironment()) | ||
{ | ||
string linuxDefaultPath = Path.Combine(Path.PathSeparator.ToString(), ScriptConstants.DefaultExtensionBundleDirectory, options.Id); | ||
|
||
string deploymentPackageBundlePath = Path.Combine( | ||
_environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHomePath), | ||
"site", "wwwroot", ".azureFunctions", ScriptConstants.ExtensionBundleDirectory, options.Id); | ||
|
||
options.ProbingPaths.Add(linuxDefaultPath); | ||
options.ProbingPaths.Add(deploymentPackageBundlePath); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/WebJobs.Script/DependencyInjection/IScriptStartupTypeLocatorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.WebJobs.Hosting; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.DependencyInjection | ||
{ | ||
public interface IScriptStartupTypeLocatorFactory | ||
{ | ||
IWebJobsStartupTypeLocator Create(); | ||
} | ||
} |
Oops, something went wrong.