internal ApplicationManager(ISiteManager siteManager, Site site, string appName, ISettingsResolver settingsResolver) { _siteManager = siteManager; _site = site; _appName = appName; _settingsResolver = settingsResolver; // Always null in public Kudu, but makes the code more similar to private Kudu NetworkCredential credentials = null; SiteUrl = site.SiteUrl; ServiceUrl = site.ServiceUrl; DeploymentManager = new RemoteDeploymentManager(site.ServiceUrl + "deployments", credentials); SettingsManager = new RemoteDeploymentSettingsManager(site.ServiceUrl + "settings", credentials); LogStreamManager = new RemoteLogStreamManager(site.ServiceUrl + "logstream", credentials); SSHKeyManager = new RemoteSSHKeyManager(site.ServiceUrl + "sshkey", credentials); VfsManager = new RemoteVfsManager(site.ServiceUrl + "vfs", credentials); VfsWebRootManager = new RemoteVfsManager(site.ServiceUrl + "vfs/site/wwwroot", credentials); LiveScmVfsManager = new RemoteVfsManager(site.ServiceUrl + "scmvfs", credentials); ZipManager = new RemoteZipManager(site.ServiceUrl + "zip", credentials); RuntimeManager = new RemoteRuntimeManager(site.ServiceUrl + "diagnostics/runtime", credentials); CommandExecutor = new RemoteCommandExecutor(site.ServiceUrl + "command", credentials); ProcessManager = new RemoteProcessManager(site.ServiceUrl + "diagnostics/processes", credentials); WebHooksManager = new RemoteWebHooksManager(site.ServiceUrl + "hooks", credentials); RepositoryManager = new RemoteRepositoryManager(site.ServiceUrl + "scm", credentials); JobsManager = new RemoteJobsManager(site.ServiceUrl + "jobs", credentials); LogFilesManager = new RemoteLogFilesManager(site.ServiceUrl + "/api/logs", credentials); SiteExtensionManager = new RemoteSiteExtensionManager(site.ServiceUrl + "api", credentials); var repositoryInfo = RepositoryManager.GetRepositoryInfo().Result; GitUrl = repositoryInfo.GitUrl.OriginalString; }
internal ApplicationManager(ISiteManager siteManager, Site site, string appName, ISettingsResolver settingsResolver) { _siteManager = siteManager; _site = site; _appName = appName; _settingsResolver = settingsResolver; SiteUrl = site.SiteUrl; ServiceUrl = site.ServiceUrl; DeploymentManager = new RemoteDeploymentManager(site.ServiceUrl + "deployments"); SettingsManager = new RemoteDeploymentSettingsManager(site.ServiceUrl + "settings"); LogStreamManager = new RemoteLogStreamManager(site.ServiceUrl + "logstream"); SSHKeyManager = new RemoteSSHKeyManager(site.ServiceUrl + "sshkey"); VfsManager = new RemoteVfsManager(site.ServiceUrl + "vfs"); VfsWebRootManager = new RemoteVfsManager(site.ServiceUrl + "vfs/site/wwwroot"); LiveScmVfsManager = new RemoteVfsManager(site.ServiceUrl + "scmvfs"); ZipManager = new RemoteZipManager(site.ServiceUrl + "zip"); CommandExecutor = new RemoteCommandExecutor(site.ServiceUrl + "command"); ProcessManager = new RemoteProcessManager(site.ServiceUrl + "diagnostics/processes"); WebHooksManager = new RemoteWebHooksManager(site.ServiceUrl + "hooks"); RepositoryManager = new RemoteRepositoryManager(site.ServiceUrl + "scm"); JobsManager = new RemoteJobsManager(site.ServiceUrl + "jobs"); var repositoryInfo = RepositoryManager.GetRepositoryInfo().Result; GitUrl = repositoryInfo.GitUrl.OriginalString; }
public ActionResult CreateConnectionString(string slug, string name, string connectionString) { try { if (String.IsNullOrEmpty(name)) { ModelState.AddModelError("Name", "name is required"); } if (String.IsNullOrEmpty(connectionString)) { ModelState.AddModelError("ConnectionString", "connection string is required"); } if (ModelState.IsValid) { Application application = db.Applications.SingleOrDefault(a => a.Slug == slug); var settingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl); settingsManager.SetConnectionString(name, connectionString); return RedirectToAction("Index", new { slug }); } } catch { } SettingsViewModel model = GetSettingsViewModel(slug); ViewBag.Name = name; ViewBag.ConnectionString = connectionString; return View("index", model); }
public ActionResult CreateAppSetting(string slug, string key, string value) { try { if (String.IsNullOrEmpty(key)) { ModelState.AddModelError("Key", "key is required"); } if (String.IsNullOrEmpty(value)) { ModelState.AddModelError("Value", "value is required"); } if (ModelState.IsValid) { Application application = db.Applications.SingleOrDefault(a => a.Slug == slug); var settingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl); settingsManager.SetAppSetting(key, value); return RedirectToAction("Index", new { slug }); } } catch { } SettingsViewModel model = GetSettingsViewModel(slug); ViewBag.Key = key; ViewBag.Value = value; return View("index", model); }
public async Task<Site> CreateSiteAsync(string applicationName) { using (ServerManager iis = GetServerManager()) { try { var siteBindingCongfigs = new List<IBindingConfiguration>(); var svcSiteBindingCongfigs = new List<IBindingConfiguration>(); if (_context.Configuration != null && _context.Configuration.Bindings != null) { siteBindingCongfigs = _context.Configuration.Bindings.Where(b => b.SiteType == SiteType.Live).ToList(); svcSiteBindingCongfigs = _context.Configuration.Bindings.Where(b => b.SiteType == SiteType.Service).ToList(); } // Determine the host header values List<BindingInformation> siteBindings = BuildDefaultBindings(applicationName, siteBindingCongfigs).ToList(); List<BindingInformation> serviceSiteBindings = BuildDefaultBindings(applicationName, svcSiteBindingCongfigs).ToList(); // Create the service site for this site var serviceSite = CreateSiteAsync(iis, applicationName, GetServiceSite(applicationName), _context.Configuration.ServiceSitePath, serviceSiteBindings); // Create the main site string siteName = GetLiveSite(applicationName); string root = _context.Paths.GetApplicationPath(applicationName); string siteRoot = _context.Paths.GetLiveSitePath(applicationName); string webRoot = Path.Combine(siteRoot, Constants.WebRoot); FileSystemHelpers.EnsureDirectory(webRoot); File.WriteAllText(Path.Combine(webRoot, HostingStartHtml), HostingStartHtmlContents); var site = CreateSiteAsync(iis, applicationName, siteName, webRoot, siteBindings); // Map a path called _app to the site root under the service site MapServiceSitePath(iis, applicationName, Constants.MappedSite, root); // Commit the changes to iis iis.CommitChanges(); var serviceUrls = serviceSite.Bindings .Select(url => String.Format("{0}://{1}:{2}/", url.Protocol, String.IsNullOrEmpty(url.Host) ? "localhost" : url.Host, url.EndPoint.Port)) .ToList(); // Wait for the site to start await OperationManager.AttemptAsync(() => WaitForSiteAsync(serviceUrls.First())); // Set initial ScmType state to LocalGit var settings = new RemoteDeploymentSettingsManager(serviceUrls.First() + "api/settings"); await settings.SetValue(SettingsKeys.ScmType, ScmType.LocalGit); var siteUrls = site.Bindings .Select(url => String.Format("{0}://{1}:{2}/", url.Protocol, String.IsNullOrEmpty(url.Host) ? "localhost" : url.Host, url.EndPoint.Port)) .ToList(); return new Site { ServiceUrls = serviceUrls, SiteUrls = siteUrls }; } catch { try { DeleteSiteAsync(applicationName).Wait(); } catch { // Don't let it throw if we're unable to delete a failed creation. } throw; } } }
public static RemoteDeploymentSettingsManager GetSettingsManager(this IApplication application, ICredentials credentials) { var deploymentSettingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl + "settings", credentials); return deploymentSettingsManager; }
public async Task<Site> CreateSiteAsync(string applicationName) { using (var iis = GetServerManager()) { try { // Determine the host header values List<string> siteBindings = GetDefaultBindings(applicationName, _settingsResolver.SitesBaseUrl); List<string> serviceSiteBindings = GetDefaultBindings(applicationName, _settingsResolver.ServiceSitesBaseUrl); // Create the service site for this site string serviceSiteName = GetServiceSite(applicationName); var serviceSite = CreateSiteAsync(iis, applicationName, serviceSiteName, _pathResolver.ServiceSitePath, serviceSiteBindings); // Create the main site string siteName = GetLiveSite(applicationName); string root = _pathResolver.GetApplicationPath(applicationName); string siteRoot = _pathResolver.GetLiveSitePath(applicationName); string webRoot = Path.Combine(siteRoot, Constants.WebRoot); FileSystemHelpers.EnsureDirectory(webRoot); File.WriteAllText(Path.Combine(webRoot, HostingStartHtml), @"<html> <head> <title>This web site has been successfully created</title> <style type=""text/css""> BODY { color: #444444; background-color: #E5F2FF; font-family: verdana; margin: 0px; text-align: center; margin-top: 100px; } H1 { font-size: 16pt; margin-bottom: 4px; } </style> </head> <body> <h1>This web site has been successfully created</h1><br/> </body> </html>"); var site = CreateSiteAsync(iis, applicationName, siteName, webRoot, siteBindings); // Map a path called _app to the site root under the service site MapServiceSitePath(iis, applicationName, Constants.MappedSite, root); // Commit the changes to iis iis.CommitChanges(); var serviceUrls = new List<string>(); foreach (var url in serviceSite.Bindings) { serviceUrls.Add(String.Format("http://{0}:{1}/", String.IsNullOrEmpty(url.Host) ? "localhost" : url.Host, url.EndPoint.Port)); } // Wait for the site to start await OperationManager.AttemptAsync(() => WaitForSiteAsync(serviceUrls[0])); // Set initial ScmType state to LocalGit var settings = new RemoteDeploymentSettingsManager(serviceUrls.First() + "api/settings"); await settings.SetValue(SettingsKeys.ScmType, ScmType.LocalGit); var siteUrls = new List<string>(); foreach (var url in site.Bindings) { siteUrls.Add(String.Format("http://{0}:{1}/", String.IsNullOrEmpty(url.Host) ? "localhost" : url.Host, url.EndPoint.Port)); } return new Site { ServiceUrls = serviceUrls, SiteUrls = siteUrls }; } catch { try { DeleteSiteAsync(applicationName).Wait(); } catch { // Don't let it throw if we're unable to delete a failed creation. } throw; } } }
public ActionResult DeleteApplicationSetting(string slug, string key) { Application application = db.Applications.SingleOrDefault(a => a.Slug == slug); var settingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl); settingsManager.RemoveAppSetting(key); return RedirectToAction("Index", new { slug }); }
private SettingsViewModel GetSettingsViewModel(Application application) { var settingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl); ViewBag.slug = application.Slug; try { return new SettingsViewModel { AppSettings = settingsManager.GetAppSettings().ToList(), ConnectionStrings = settingsManager.GetConnectionStrings().ToList() }; } catch (InvalidOperationException) { throw new InvalidOperationException("Settings API not available"); } }