Exemple #1
0
        public void ValidExtenstionConfig_ForAppServiceEnvironment_ConfiguresDownloadPath()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, CreateTestAppServiceEnvironment());
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Record.Exception(() => setup.Configure(options));

            string expectedDownloadPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                                    ? @"D:\home\data\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle"
                                    : "/home/data/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle";

            Assert.Equal(expectedDownloadPath, options.DownloadPath);
            Assert.Null(ex);
        }
Exemple #2
0
        public void ValidExtenstionConfig_ForAppServiceEnvironment_ConfiguresProbingPaths()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, CreateTestAppServiceEnvironment());
            ExtensionBundleOptions             options = new ExtensionBundleOptions();

            setup.Configure(options);

            List <string> expectedProbingPaths = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                                    ? new List <string>
            {
                @"C:\Program Files (x86)\FuncExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle"
            }
                                    : new List <string>
            {
                "/FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle",
                "/home/site/wwwroot/.azureFunctions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle"
            };

            Assert.Equal(expectedProbingPaths, options.ProbingPaths);
        }
 public ExtensionBundleManager(ExtensionBundleOptions options, IEnvironment environment, ILoggerFactory loggerFactory)
 {
     _environment = environment ?? throw new ArgumentNullException(nameof(environment));
     _logger      = loggerFactory.CreateLogger <ExtensionBundleManager>() ?? throw new ArgumentNullException(nameof(loggerFactory));
     _cdnUri      = _environment.GetEnvironmentVariable(EnvironmentSettingNames.ExtensionBundleSourceUri) ?? ScriptConstants.ExtensionBundleDefaultSourceUri;
     _options     = options ?? throw new ArgumentNullException(nameof(options));
 }
Exemple #4
0
        internal static ExtensionBundleOptions GetExtensionBundleOptions(IConfiguration configuration)
        {
            var options      = new ExtensionBundleOptions();
            var optionsSetup = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);

            configuration.Bind(options);
            optionsSetup.Configure(options);
            return(options);
        }
Exemple #5
0
        public static ExtensionBundleOptions GetExtensionBundleOptions(ScriptApplicationHostOptions hostOptions = null)
        {
            hostOptions = hostOptions ?? SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory);
            IConfigurationRoot configuration = Utilities.BuildHostJsonConfigutation(hostOptions);
            var configurationHelper          = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);
            var options = new ExtensionBundleOptions();

            configurationHelper.Configure(options);
            return(options);
        }
Exemple #6
0
        public async Task GetExtensionBundleDetails_BundleNotConfigured_ReturnsNull()
        {
            ExtensionBundleOptions options = new ExtensionBundleOptions()
            {
                Id = null, Version = null
            };
            var manager    = GetExtensionBundleManager(options, GetTestAppServiceEnvironment());
            var bundleInfo = await manager.GetExtensionBundleDetails();

            Assert.Null(bundleInfo);
        }
Exemple #7
0
        public void MissingOrValidExtenstionConfig_DoesNotThrowException(string hostJsonContent)
        {
            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var configuration = BuildHostJsonConfiguration();

            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Record.Exception(() => setup.Configure(options));

            Assert.Null(ex);
        }
Exemple #8
0
        public void ExtensionBundleConfigure_InvalidVersion_ThrowsException(string hostJsonContent)
        {
            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var configuration = BuildHostJsonConfiguration();

            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Assert.Throws <ArgumentException>(() => setup.Configure(options));

            Assert.StartsWith($"The value of version property in extensionBundle section of {ScriptConstants.HostMetadataFileName} file is invalid or missing.", ex.Message);
        }
        public void ExtenstionConfig_SetToAnInvalidValue_Throws(string hostJsonContent)
        {
            File.WriteAllText(_hostJsonFile, hostJsonContent);
            Assert.True(File.Exists(_hostJsonFile));
            var configuration = BuildHostJsonConfiguration();

            ExtensionBundleOptionsSetup setup   = new ExtensionBundleOptionsSetup(configuration);
            ExtensionBundleOptions      options = new ExtensionBundleOptions();
            var ex = Assert.Throws <ArgumentException>(() => setup.Configure(options));

            Assert.StartsWith($"The value of id property in extensionBundle section of {ScriptConstants.HostMetadataFileName} file is invalid or missing.", ex.Message);
        }
        public static ExtensionBundleOptions GetExtensionBundleOptions(ScriptApplicationHostOptions hostOptions = null)
        {
            hostOptions = hostOptions ?? SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory);
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.Add(new HostJsonFileConfigurationSource(hostOptions, SystemEnvironment.Instance, loggerFactory: NullLoggerFactory.Instance));
            var configuration = builder.Build();

            var configurationHelper = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);
            var options             = new ExtensionBundleOptions();

            configurationHelper.Configure(options);
            return(options);
        }
Exemple #11
0
        private ExtensionBundleOptions GetTestExtensionBundleOptions(string id, string version)
        {
            var options = new ExtensionBundleOptions
            {
                Id           = id,
                Version      = VersionRange.Parse(version, true),
                DownloadPath = _downloadPath
            };

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                options.ProbingPaths.Add(@"C:\Program Files (x86)\FuncExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle");
            }
            else
            {
                options.ProbingPaths.Add("/FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle");
                options.ProbingPaths.Add("/home/site/wwwroot/.azureFunctions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle");
            }

            return(options);
        }
Exemple #12
0
        public void ValidExtenstionConfig_NonAppServiceEnvironment_DoesNotConfigureDownloadPathAndProbingPath()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();

            setup.Configure(options);

            Assert.Equal(options.Id, "Microsoft.Azure.Functions.ExtensionBundle");
            Assert.Equal(options.Version.OriginalString, "[2.*, 3.0.0)");
            Assert.True(string.IsNullOrEmpty(options.DownloadPath));
            Assert.Equal(options.ProbingPaths.Count, 0);
        }
Exemple #13
0
 private ExtensionBundleManager GetExtensionBundleManager(ExtensionBundleOptions bundleOptions, TestEnvironment environment = null)
 {
     environment = environment ?? new TestEnvironment();
     return(new ExtensionBundleManager(bundleOptions, environment, MockNullLoggerFactory.CreateLoggerFactory()));
 }