public override void Configure(IFunctionsHostBuilder builder) { var context = builder.GetContext(); var section = context.Configuration.GetSection("Acmebot"); // Add Options builder.Services.AddOptions <AcmebotOptions>() .Bind(section.Exists() ? section : context.Configuration.GetSection("LetsEncrypt")) .ValidateDataAnnotations() .PostConfigure(options => { // Backward compatibility if (options.Endpoint == "https://acme-v02.api.letsencrypt.org/") { options.PreferredChain ??= "DST Root CA X3"; } }); // Add Services builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory <>), typeof(OptionsFactory <>))); builder.Services.AddHttpClient(); builder.Services.AddSingleton <ITelemetryInitializer, ApplicationVersionInitializer <Startup> >(); builder.Services.AddSingleton(new LookupClient(new LookupClientOptions(NameServer.GooglePublicDns, NameServer.GooglePublicDns2) { UseCache = false, UseRandomNameServer = true })); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); return(AzureEnvironment.Get(options.Value.Environment)); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <AzureEnvironment>(); var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = environment.ActiveDirectory }); return(new CertificateClient(new Uri(options.Value.VaultBaseUrl), credential)); }); builder.Services.AddSingleton <AcmeProtocolClientFactory>(); builder.Services.AddSingleton <WebhookInvoker>(); builder.Services.AddSingleton <ILifeCycleNotificationHelper, WebhookLifeCycleNotification>(); builder.Services.AddSingleton <IDnsProvider>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >().Value; var environment = provider.GetRequiredService <AzureEnvironment>(); if (options.Cloudflare != null) { return(new CloudflareProvider(options.Cloudflare)); } if (options.DnsMadeEasy != null) { return(new DnsMadeEasyProvider(options.DnsMadeEasy)); } if (options.GoogleDns != null || options.Google != null) { return(new GoogleDnsProvider(options.GoogleDns ?? options.Google)); } if (options.GratisDns != null) { return(new GratisDnsProvider(options.GratisDns)); } if (options.Route53 != null) { return(new Route53Provider(options.Route53)); } if (options.TransIp != null) { return(new TransIpProvider(options, options.TransIp, environment)); } if (options.AzureDns != null) { return(new AzureDnsProvider(options.AzureDns, environment)); } // Backward compatibility if (options.SubscriptionId != null) { return(new AzureDnsProvider(new AzureDnsOptions { SubscriptionId = options.SubscriptionId }, environment)); } throw new NotSupportedException("DNS Provider is not configured. Please check the documentation and configure it."); }); }
public override void Configure(IFunctionsHostBuilder builder) { // Add Options var context = builder.GetContext(); var section = context.Configuration.GetSection("Acmebot"); builder.Services.AddOptions <AcmebotOptions>() .Bind(section.Exists() ? section : context.Configuration.GetSection("LetsEncrypt")) .ValidateDataAnnotations() .PostConfigure(options => { // Backward compatibility if (options.Endpoint == "https://acme-v02.api.letsencrypt.org/") { options.PreferredChain ??= "DST Root CA X3"; } }); // Add Services builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory <>), typeof(OptionsFactory <>))); builder.Services.AddHttpClient(); builder.Services.AddHttpClient("InSecure") .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); builder.Services.AddSingleton(new LookupClient(new LookupClientOptions(NameServer.GooglePublicDns, NameServer.GooglePublicDns2) { UseCache = false, UseRandomNameServer = true })); builder.Services.AddSingleton <ITokenProvider, AppAuthenticationTokenProvider>(); builder.Services.AddSingleton <IAzureEnvironment>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); return(AzureEnvironment.Get(options.Value.Environment)); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new WebSiteManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new DnsManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new ResourceManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton <IAcmeProtocolClientFactory, AcmeProtocolClientFactory>(); builder.Services.AddSingleton <IKuduClientFactory, KuduClientFactory>(); builder.Services.AddSingleton <WebhookClient>(); builder.Services.AddSingleton <ILifeCycleNotificationHelper, WebhookLifeCycleNotification>(); }
public override void Configure(IFunctionsHostBuilder builder) { builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory <>), typeof(OptionsFactory <>))); builder.Services.AddHttpClient(); builder.Services.AddSingleton(new LookupClient(new LookupClientOptions { UseCache = false })); builder.Services.AddSingleton <IAzureEnvironment>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); return(AzureEnvironment.Get(options.Value.Environment)); }); builder.Services.AddSingleton(provider => { var environment = provider.GetRequiredService <IAzureEnvironment>(); var tokenProvider = new AzureServiceTokenProvider(azureAdInstance: environment.ActiveDirectory); return(new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback))); }); builder.Services.AddSingleton <IAcmeProtocolClientFactory, AcmeProtocolClientFactory>(); builder.Services.AddSingleton <WebhookClient>(); builder.Services.AddSingleton <ILifeCycleNotificationHelper, WebhookLifeCycleNotification>(); builder.Services.AddSingleton <IDnsProvider>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >().Value; var environment = provider.GetRequiredService <IAzureEnvironment>(); if (options.Cloudflare != null) { return(new CloudflareProvider(options.Cloudflare)); } if (options.GratisDns != null) { return(new GratisDnsProvider(options.GratisDns)); } if (options.AzureDns != null) { return(new AzureDnsProvider(options.AzureDns, environment)); } if (options.SubscriptionId != null) { return(new AzureDnsProvider(new AzureDnsOptions { SubscriptionId = options.SubscriptionId }, environment)); } throw new NotSupportedException(); }); var section = Configuration.GetSection("Acmebot"); builder.Services.AddOptions <AcmebotOptions>() .Bind(section.Exists() ? section : Configuration.GetSection("LetsEncrypt")) .ValidateDataAnnotations(); }
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 { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); builder.Services.AddSingleton(new LookupClient(new LookupClientOptions { UseCache = false })); builder.Services.AddSingleton <ITokenProvider, AppAuthenticationTokenProvider>(); builder.Services.AddSingleton <IAzureEnvironment>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); return(AzureEnvironment.Get(options.Value.Environment)); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new WebSiteManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new DnsManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); return(new ResourceManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(provider.GetRequiredService <ITokenProvider>())) { SubscriptionId = options.Value.SubscriptionId }); }); builder.Services.AddSingleton <IAcmeProtocolClientFactory, AcmeProtocolClientFactory>(); builder.Services.AddSingleton <IKuduClientFactory, KuduClientFactory>(); builder.Services.AddSingleton <WebhookClient>(); builder.Services.AddSingleton <ILifeCycleNotificationHelper, WebhookLifeCycleNotification>(); var context = builder.GetContext(); var section = context.Configuration.GetSection("Acmebot"); builder.Services.AddOptions <AcmebotOptions>() .Bind(section.Exists() ? section : context.Configuration.GetSection("LetsEncrypt")) .ValidateDataAnnotations(); }
public override void Configure(IFunctionsHostBuilder builder) { builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory <>), typeof(OptionsFactory <>))); builder.Services.AddHttpClient(); builder.Services.AddSingleton(new LookupClient(new LookupClientOptions { UseCache = false })); builder.Services.AddSingleton <IAzureEnvironment>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); return(AzureEnvironment.Get(options.Value.Environment)); }); builder.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >(); var environment = provider.GetRequiredService <IAzureEnvironment>(); var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri(environment.ActiveDirectory) }); return(new CertificateClient(new Uri(options.Value.VaultBaseUrl), credential)); }); builder.Services.AddSingleton <IAcmeProtocolClientFactory, AcmeProtocolClientFactory>(); builder.Services.AddSingleton <WebhookClient>(); builder.Services.AddSingleton <ILifeCycleNotificationHelper, WebhookLifeCycleNotification>(); builder.Services.AddSingleton <IDnsProvider>(provider => { var options = provider.GetRequiredService <IOptions <AcmebotOptions> >().Value; var environment = provider.GetRequiredService <IAzureEnvironment>(); if (options.Cloudflare != null) { return(new CloudflareProvider(options.Cloudflare)); } if (options.GratisDns != null) { return(new GratisDnsProvider(options.GratisDns)); } if (options.AzureDns != null) { return(new AzureDnsProvider(options.AzureDns, environment)); } if (options.SubscriptionId != null) { return(new AzureDnsProvider(new AzureDnsOptions { SubscriptionId = options.SubscriptionId }, environment)); } throw new NotSupportedException(); }); var context = builder.GetContext(); var section = context.Configuration.GetSection("Acmebot"); builder.Services.AddOptions <AcmebotOptions>() .Bind(section.Exists() ? section : context.Configuration.GetSection("LetsEncrypt")) .ValidateDataAnnotations(); }