Skip to content

Commit

Permalink
#347 adds connection string fields and submission to the Authenticati…
Browse files Browse the repository at this point in the history
…onModel, AppSettingsAuthConfig and corresponding view & controller.
  • Loading branch information
Benjamin Howarth committed Jan 7, 2020
1 parent b254099 commit f7410b8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 8 deletions.
22 changes: 22 additions & 0 deletions LetsEncrypt-SiteExtension/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public async Task<ActionResult> Index(AuthenticationModel model)
return View(model);
}
var webappsettings = client.WebApps.ListSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName);
var connectionStrings = client.WebApps.ListConnectionStrings(model.ResourceGroupName, model.WebAppName);
if (model.UpdateAppSettings)
{
var newAppSettingsValues = new Dictionary<string, string>{
Expand All @@ -74,6 +75,13 @@ public async Task<ActionResult> Index(AuthenticationModel model)
{ AppSettingsAuthConfig.servicePlanResourceGroupNameKey, model.ServicePlanResourceGroupName },
{ AppSettingsAuthConfig.useIPBasedSSL, model.UseIPBasedSSL.ToString().ToLowerInvariant() }
};

var newConnectionStrings = new Dictionary<string, string>
{
{ AppSettingsAuthConfig.webjobDashboard, model.DashboardConnectionString },
{ AppSettingsAuthConfig.webjobStorage, model.StorageConnectionString }
};

foreach (var appsetting in newAppSettingsValues)
{
if (!webappsettings.Properties.ContainsKey(appsetting.Key))
Expand All @@ -86,8 +94,22 @@ public async Task<ActionResult> Index(AuthenticationModel model)
}
}

foreach (var connString in newConnectionStrings)
{
if (!connectionStrings.Properties.ContainsKey(connString.Key))
{
connectionStrings.Properties.Add(connString.Key, new ConnStringValueTypePair(connString.Value, ConnectionStringType.Custom));
}
else
{
connectionStrings.Properties[connString.Key] = new ConnStringValueTypePair(connString.Value, ConnectionStringType.Custom);
}
}

client.WebApps.UpdateSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName, webappsettings);
client.WebApps.UpdateConnectionStrings(model.ResourceGroupName, model.WebAppName, connectionStrings);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection("connectionStrings");

await path.ChallengeDirectory(true);
}
Expand Down
14 changes: 14 additions & 0 deletions LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public bool UseIPBasedSSL
get; set;
}

[Required]
public string DashboardConnectionString
{
get; set;
}

[Required]
public string StorageConnectionString
{
get; set;
}

[Display(Name = "Update Application Settings and Virtual Directory (if needed)")]
public bool UpdateAppSettings
{
Expand Down Expand Up @@ -113,6 +125,8 @@ public static explicit operator AuthenticationModel(AppSettingsAuthConfig config
SiteSlotName = config.SiteSlotName,
WebRootPath = config.WebRootPath,
RunFromPackage = config.RunFromPackage,
DashboardConnectionString = config.DashboardConnectionString,
StorageConnectionString = config.StorageConnectionString,
};
}
}
Expand Down
30 changes: 22 additions & 8 deletions LetsEncrypt-SiteExtension/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@

@if (Model.RunFromPackage && string.IsNullOrEmpty(Environment.GetEnvironmentVariable(LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.webRootPath)))
{
<div class="alert alert-warning" role="alert">
<p>Web Site was deployed using "Run From Package", the site extension will have to configure a virtual directory to ensure the challenge file can be browsable at http://your-site/.well-known/acme-challenge. </p>
<div class="alert alert-warning" role="alert">
<p>Web Site was deployed using "Run From Package", the site extension will have to configure a virtual directory to ensure the challenge file can be browsable at http://your-site/.well-known/acme-challenge. </p>
<p>If you already host content under /.well-known then you should not continue, instead you should follow the manual setup procedure at <a href="https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package">https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package</a></p>
</div>
<p>If you already host content under /.well-known then you should not continue, instead you should follow the manual setup procedure at <a href="https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package">https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package</a></p>
</div>
}
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@{
var authModel = (Model as LetsEncrypt.SiteExtension.Models.AuthenticationModel);
var authModel = (Model as LetsEncrypt.SiteExtension.Models.AuthenticationModel);
}
@if (authModel != null && authModel.Error)
{
<div class="alert alert-danger" role="alert">
@authModel.ErrorMessage
</div>
<div class="alert alert-danger" role="alert">
@authModel.ErrorMessage
</div>
}
<div class="form-group">
@Html.LabelFor(model => model.Tenant, htmlAttributes: new { @class = "control-label col-md-2" })
Expand Down Expand Up @@ -198,6 +198,20 @@
@Html.ValidationMessageFor(model => model.SiteSlotName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DashboardConnectionString, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DashboardConnectionString, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DashboardConnectionString, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.StorageConnectionString, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.StorageConnectionString, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.StorageConnectionString, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UpdateAppSettings, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
Expand Down
20 changes: 20 additions & 0 deletions LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class AppSettingsAuthConfig : IAzureWebAppEnvironment, IAcmeConfig
public const string authorizationChallengeBlobStorageAccount = "letsencrypt:AuthorizationChallengeBlobStorageAccount";
public const string authorizationChallengeBlobStorageContainer = "letsencrypt:AuthorizationChallengeBlobStorageContainer";
public const string disableVirtualApplication = "letsencrypt:DisableVirtualApplication";
public const string webjobDashboard = "AzureWebJobsDashboard";
public const string webjobStorage = "AzureWebJobsStorage";

public AppSettingsAuthConfig()
{
Expand Down Expand Up @@ -109,6 +111,24 @@ public string WebAppName
}
}

[Required(ErrorMessage = webjobDashboard + " connectionString is required")]
public string DashboardConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings[webjobDashboard].ConnectionString;
}
}

[Required(ErrorMessage = webjobStorage + " connectionString is required")]
public string StorageConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings[webjobStorage].ConnectionString;
}
}

public string WebRootPath
{
get
Expand Down

0 comments on commit f7410b8

Please sign in to comment.