/// <summary> /// Returns a specified environment configuration as the current webapp's /// default configuration during the runtime. /// </summary> internal static IEnvironment GetEnvironment(IHostingEnvironment hostingEnvironment, IFileSystemPathProvider fileSystemPathsProvider, IDeploymentSettingsManager settings = null, IHttpContextAccessor httpContextAccessor = null) { var root = PathResolver.ResolveRootPath(); var siteRoot = Path.Combine(root, Constants.SiteFolder); var repositoryPath = Path.Combine(siteRoot, settings == null ? Constants.RepositoryPath : settings.GetRepositoryPath()); var binPath = AppContext.BaseDirectory; var requestId = httpContextAccessor?.HttpContext.Request.GetRequestId(); var kuduConsoleFullPath = Path.Combine(AppContext.BaseDirectory, KuduConsoleRelativePath, KuduConsoleFilename); return(new Environment(root, EnvironmentHelper.NormalizeBinPath(binPath), repositoryPath, requestId, kuduConsoleFullPath, httpContextAccessor, fileSystemPathsProvider)); }
public Environment( string rootPath, string binPath, string repositoryPath, string requestId, string kuduConsoleFullPath, IHttpContextAccessor httpContextAccessor, IFileSystemPathProvider fileSystemPathsProvider) { RootPath = rootPath; SiteRootPath = Path.Combine(rootPath, Constants.SiteFolder); _tempPath = Path.GetTempPath(); _repositoryPath = repositoryPath; _zipTempDirectoryPath = Path.Combine(_tempPath, Constants.ZipTempDirectoryName); _webRootPath = Path.Combine(SiteRootPath, Constants.WebRoot); _deploymentsPath = Path.Combine(SiteRootPath, Constants.DeploymentCachePath); _artifactsPath = Path.Combine(SiteRootPath, Constants.ArtifactsPath); _deploymentToolsPath = Path.Combine(_deploymentsPath, Constants.DeploymentToolsPath); _siteExtensionSettingsPath = Path.Combine(SiteRootPath, Constants.SiteExtensionsCachePath); _diagnosticsPath = Path.Combine(SiteRootPath, Constants.DiagnosticsPath); _locksPath = Path.Combine(SiteRootPath, Constants.LocksPath); if (OSDetector.IsOnWindows()) { _sshKeyPath = Path.Combine(rootPath, Constants.SSHKeyPath); } else { // in linux, rootPath is "/home", while .ssh folder need to under "/home/{user}" string path2 = System.Environment.GetEnvironmentVariable("KUDU_RUN_USER"); if (path2 == null || path2.Equals("")) { path2 = "root"; } _sshKeyPath = Path.Combine(rootPath, path2, Constants.SSHKeyPath); } _scriptPath = Path.Combine(binPath, Constants.ScriptsPath); _nodeModulesPath = Path.Combine(binPath, Constants.NodeModulesPath); _logFilesPath = Path.Combine(rootPath, Constants.LogFilesPath); _applicationLogFilesPath = Path.Combine(_logFilesPath, Constants.ApplicationLogFilesDirectory); _tracePath = Path.Combine(rootPath, Constants.TracePath); _analyticsPath = Path.Combine(_tempPath ?? _logFilesPath, Constants.SiteExtensionLogsDirectory); _deploymentTracePath = Path.Combine(rootPath, Constants.DeploymentTracePath); _dataPath = Path.Combine(rootPath, Constants.DataPath); _jobsDataPath = Path.Combine(_dataPath, Constants.JobsPath); _jobsBinariesPath = Path.Combine(_webRootPath, Constants.AppDataPath, Constants.JobsPath); _secondaryJobsBinariesPath = Path.Combine(SiteRootPath, Constants.JobsPath); string userDefinedWebJobRoot = System.Environment.GetEnvironmentVariable(SettingsKeys.WebJobsRootPath); if (!String.IsNullOrEmpty(userDefinedWebJobRoot)) { userDefinedWebJobRoot = System.Environment.ExpandEnvironmentVariables(userDefinedWebJobRoot).Trim('\\', '/'); // Path.Combine(p1,p2) returns p2 if p2 is an absolute path // default _jobsBinariesPath = "D:/home/site/wwwroot/App_Data/jobs" // if userDefinedWebJobRoot = "myfunctions", _jobsBinariesPath = "D:/home/site/wwwroot/myfunctions" // if userDefinedWebJobRoot = "D:/home/functionfolder", _jobsBinariesPath = "D:/home/functionfolder" _jobsBinariesPath = Path.Combine(_webRootPath, userDefinedWebJobRoot); } _sitePackagesPath = Path.Combine(_dataPath, Constants.SitePackages); RequestId = !string.IsNullOrEmpty(requestId) ? requestId : Guid.Empty.ToString(); _httpContextAccessor = httpContextAccessor; _fileSystemPathsProvider = fileSystemPathsProvider ?? throw new ArgumentNullException(nameof(fileSystemPathsProvider)); KuduConsoleFullPath = kuduConsoleFullPath; }
public static IEnvironment GetMockedEnvironment(string rootPath = "rootPath", string binPath = "binPath", string repositoryPath = "repositoryPath", string requestId = "requestId", string kuduConsoleFullPath = "kuduConsoleFullPath", IFileSystemPathProvider fileSystemPathProvider = null) { return(new Environment(rootPath, binPath, repositoryPath, requestId, kuduConsoleFullPath, new HttpContextAccessor(), fileSystemPathProvider ?? TestFileSystemPathProvider.Instance)); }