public void Returns_Is_AzureFilesConfigured(string connectionString, string contentShare, bool isAzureFilesConfigured) { var hostAssignmentContext = new HostAssignmentContext() { Environment = new Dictionary <string, string>() }; hostAssignmentContext.Environment[EnvironmentSettingNames.AzureFilesConnectionString] = connectionString; hostAssignmentContext.Environment[EnvironmentSettingNames.AzureFilesContentShare] = contentShare; Assert.Equal(isAzureFilesConfigured, hostAssignmentContext.IsAzureFilesContentShareConfigured(NullLogger.Instance)); }
private async Task ApplyContext(HostAssignmentContext assignmentContext) { _logger.LogInformation($"Applying {assignmentContext.Environment.Count} app setting(s)"); assignmentContext.ApplyAppSettings(_environment, _logger); // We need to get the non-PlaceholderMode script Path so we can unzip to the correct location. // This asks the factory to skip the PlaceholderMode check when configuring options. var options = _optionsFactory.Create(ScriptApplicationHostOptionsSetup.SkipPlaceholder); RunFromPackageContext pkgContext = assignmentContext.GetRunFromPkgContext(); if (_environment.SupportsAzureFileShareMount()) { var azureFilesMounted = false; if (assignmentContext.IsAzureFilesContentShareConfigured(_logger)) { azureFilesMounted = await _runFromPackageHandler.MountAzureFileShare(assignmentContext); } else { _logger.LogError( $"No {nameof(EnvironmentSettingNames.AzureFilesConnectionString)} or {nameof(EnvironmentSettingNames.AzureFilesContentShare)} configured. Azure FileShare will not be mounted. For PowerShell Functions, Managed Dependencies will not persisted across functions host instances."); } if (pkgContext.IsRunFromPackage(options, _logger)) { if (azureFilesMounted) { _logger.LogWarning("App is configured to use both Run-From-Package and AzureFiles. Run-From-Package will take precedence"); } var blobContextApplied = await _runFromPackageHandler.ApplyBlobPackageContext(pkgContext, options.ScriptPath, azureFilesMounted, false); if (!blobContextApplied && azureFilesMounted) { _logger.LogWarning($"Failed to {nameof(_runFromPackageHandler.ApplyBlobPackageContext)}. Attempting to use local disk instead"); await _runFromPackageHandler.ApplyBlobPackageContext(pkgContext, options.ScriptPath, false); } } else { _logger.LogInformation($"No {nameof(EnvironmentSettingNames.AzureWebsiteRunFromPackage)} configured"); } } else { if (pkgContext.IsRunFromPackage(options, _logger)) { await _runFromPackageHandler.ApplyBlobPackageContext(pkgContext, options.ScriptPath, false); } else if (assignmentContext.IsAzureFilesContentShareConfigured(_logger)) { await _runFromPackageHandler.MountAzureFileShare(assignmentContext); } } // BYOS var storageVolumes = assignmentContext.GetBYOSEnvironmentVariables() .Select(AzureStorageInfoValue.FromEnvironmentVariable).ToList(); var mountedVolumes = (await Task.WhenAll(storageVolumes.Where(v => v != null).Select(MountStorageAccount))).Where( result => result).ToList(); if (storageVolumes.Any()) { if (mountedVolumes.Count != storageVolumes.Count) { _logger.LogWarning( $"Successfully mounted {mountedVolumes.Count} / {storageVolumes.Count} BYOS storage accounts"); } else { _logger.LogInformation( $"Successfully mounted {storageVolumes.Count} BYOS storage accounts"); } } }