-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
374 additions
and
31 deletions.
There are no files selected for viewing
Submodule ACMESharp
updated
10 files
47 changes: 47 additions & 0 deletions
47
LetsEncrypt-SiteExtension/Controllers/Api/CertificateController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using LetsEncrypt.Azure.Core; | ||
using LetsEncrypt.Azure.Core.Models; | ||
using LetsEncrypt.SiteExtension.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using System.Web.Http.Description; | ||
|
||
namespace LetsEncrypt.SiteExtension.Controllers.Api | ||
{ | ||
[ValidateApiVersion] | ||
public class CertificateController : ApiController | ||
{ | ||
[HttpPost] | ||
[Route("api/certificates/renew")] | ||
[ResponseType(typeof(List<CertificateInstallModel>))] | ||
public async Task<IHttpActionResult> RenewExisting([FromUri(Name = "api-version")]string apiversion = null) | ||
{ | ||
Trace.TraceInformation("Renew certificate"); | ||
var config = new AppSettingsAuthConfig(); | ||
var res = await new CertificateManager(new AppSettingsAuthConfig()).RenewCertificate(renewXNumberOfDaysBeforeExpiration: config.RenewXNumberOfDaysBeforeExpiration); | ||
Trace.TraceInformation($"Completed renewal of '{res.Count()}' certificates"); | ||
|
||
return Ok(res); | ||
} | ||
|
||
[HttpPost] | ||
[Route("api/certificates/provider/kudu/install")] | ||
[ResponseType(typeof(CertificateInstallModel))] | ||
public async Task<IHttpActionResult> GenerateAndInstall(GenerateAndInstallModel model, [FromUri(Name = "api-version")]string apiversion = null) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
var mgr = new CertificateManager(model.AzureEnvironment, model.AcmeConfig, model.CertificateSettings, model.AuthorizationChallengeProviderConfig); | ||
|
||
return Ok(await mgr.AddCertificate()); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
LetsEncrypt-SiteExtension/Controllers/Api/ValidateApiVersionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http.Controllers; | ||
|
||
namespace LetsEncrypt.SiteExtension.Controllers.Api | ||
{ | ||
public class ValidateApiVersionAttribute : System.Web.Http.Filters.ActionFilterAttribute | ||
{ | ||
public override void OnActionExecuting(HttpActionContext actionContext) | ||
{ | ||
object apiversion = string.Empty; | ||
if (actionContext.ActionArguments.TryGetValue("apiversion", out apiversion)) | ||
{ | ||
var errorMessage = string.Empty; | ||
if (!TryValidateApiVersion(apiversion as string, out errorMessage)) | ||
{ | ||
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage); | ||
} | ||
} | ||
} | ||
|
||
private bool TryValidateApiVersion(string apiversion, out string error) | ||
{ | ||
error = string.Empty; | ||
if (apiversion == "2017-09-01") | ||
{ | ||
return true; | ||
} | ||
error = "Missing query string api-version or unsupported api-version. Only supported api-version is 2017-09-01"; | ||
return false; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
LetsEncrypt-SiteExtension/Models/GenerateAndInstallModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using LetsEncrypt.Azure.Core.Models; | ||
|
||
namespace LetsEncrypt.SiteExtension.Models | ||
{ | ||
public class GenerateAndInstallModel | ||
{ | ||
public AzureEnvironment AzureEnvironment { get; set; } | ||
public AcmeConfig AcmeConfig { get; set; } | ||
|
||
public CertificateServiceSettings CertificateSettings { get; set; } | ||
|
||
public AuthorizationChallengeProviderConfig AuthorizationChallengeProviderConfig { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.