public OrderDomains(Options options) { this.options = options; var serviceCollection = new ServiceCollection(); serviceCollection.AddHttpClient(); ServiceProvider services = serviceCollection.BuildServiceProvider(); IHttpClientFactory httpClientFactory = services.GetRequiredService <System.Net.Http.IHttpClientFactory>(); cloudflareClient = new CloudflareClientFactory(options.Username, options.ApiKey, new CloudflareRestClientFactory(httpClientFactory), CloudflareAPIEndpoint.V4Endpoint) .Create(); // RSA service provider var rsaCryptoServiceProvider = new RSACryptoServiceProvider(2048); if (string.IsNullOrEmpty(options.Key)) { Program.LogLine("Generating new key for ACME."); var exportKey = rsaCryptoServiceProvider.ExportCspBlob(true); var strKey = Convert.ToBase64String(exportKey); File.WriteAllText("acmekey.key", strKey); } else { var key = Convert.FromBase64String(File.ReadAllText(options.Key)); rsaCryptoServiceProvider.ImportCspBlob(key); } var rsaKey = RSA.Create(rsaCryptoServiceProvider.ExportParameters(true)); acmeClient = new ACMEClient( new Uri(options.Environment == AcmeEnvironment.ProductionV2 ? ACMEEnvironment.ProductionV2 : ACMEEnvironment.StagingV2), rsaKey, new HttpClient()); }
public CloudflareService(ICloudflareClient client, ILogger <CloudflareService> logger, IOptions <AppConfiguration> config) { _client = client; _logger = logger; _config = config.Value; }