public static IServiceCollection AddDnsMonitor(this IServiceCollection services, Action <ProviderSettings> configure) { var settings = new ProviderSettings(); configure?.Invoke(settings); services.AddSingleton(settings); services.AddHttpClient(); if (settings.PublicIpProviderApiCredentials.ProviderKey == IpifyPublicIpProvider.Key) { services.AddTransient <IPublicIpProvider, IpifyPublicIpProvider>(); } else if (settings.PublicIpProviderApiCredentials.ProviderKey == HyprsoftPublicIpProvider.Key) { services.AddTransient <IPublicIpProvider, HyprsoftPublicIpProvider>(); } else { throw new ProviderNotFoundException($"Public IP address provider key '{settings.PublicIpProviderApiCredentials.ProviderKey}' does not exist. Valid values are '{IpifyPublicIpProvider.Key}' and '{HyprsoftPublicIpProvider.Key}'."); } if (settings.DnsProviderApiCredentials.ProviderKey == GoDaddyDnsProvider.Key) { services.AddTransient <IDnsProvider, GoDaddyDnsProvider>(); } else if (settings.DnsProviderApiCredentials.ProviderKey == HyprsoftDnsProvider.Key) { services.AddTransient <IDnsProvider, HyprsoftDnsProvider>(); } else { throw new ProviderNotFoundException($"DNS provider key '{settings.DnsProviderApiCredentials.ProviderKey}' does not exist. Valid values are '{GoDaddyDnsProvider.Key}' and '{HyprsoftDnsProvider.Key}'."); } return(services); }
public HyprsoftPublicIpProvider(ILogger <HyprsoftPublicIpProvider> logger, ProviderSettings settings, HttpClient httpClient) : base(logger, httpClient) => _client = new HyprsoftClient(settings.PublicIpProviderApiCredentials.ApiKey, settings.PublicIpProviderApiCredentials.ApiSecret);
public GoDaddyDnsProvider(ILogger <GoDaddyDnsProvider> logger, IPublicIpProvider provider, ProviderSettings settings, HttpClient httpClient) : base(logger, provider) { _httpClient = httpClient; _httpClient.BaseAddress = new Uri("https://api.godaddy.com/"); _httpClient.DefaultRequestHeaders.Add("Authorization", $"sso-key {settings.DnsProviderApiCredentials.ApiKey}:{settings.DnsProviderApiCredentials.ApiSecret}"); }