Skip to content

Commit

Permalink
Adding Acmebot options validation (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan committed Jun 18, 2020
1 parent c79ece1 commit e485131
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion AppService.Acmebot/AcmebotOptions.cs
@@ -1,13 +1,19 @@
namespace AppService.Acmebot
using System.ComponentModel.DataAnnotations;

namespace AppService.Acmebot
{
public class AcmebotOptions
{
[Required]
public string Endpoint { get; set; } = "https://acme-v02.api.letsencrypt.org/";

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

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

[Url]
public string Webhook { get; set; }
}
}
7 changes: 6 additions & 1 deletion AppService.Acmebot/Startup.cs
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.Rest;

Expand All @@ -32,6 +33,8 @@ public Startup()

public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory<>), typeof(OptionsFactory<>)));

builder.Services.AddHttpClient();
builder.Services.AddHttpClient("InSecure")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
Expand Down Expand Up @@ -69,7 +72,9 @@ public override void Configure(IFunctionsHostBuilder builder)

var section = Configuration.GetSection("Acmebot");

builder.Services.Configure<AcmebotOptions>(section.Exists() ? section : Configuration.GetSection("LetsEncrypt"));
builder.Services.AddOptions<AcmebotOptions>()
.Bind(section.Exists() ? section : Configuration.GetSection("LetsEncrypt"))
.ValidateDataAnnotations();
}
}
}

0 comments on commit e485131

Please sign in to comment.