예제 #1
0
        public async Task ExecAsync()
        {
            var configBuilder = new ConfigurationBuilder();

            if (_options.AzureKeyVaultUrl != null)
            {
                configBuilder.AddAzureKeyVault(_options.AzureKeyVaultUrl);
            }

            var config = configBuilder.Build();

            _services.AddLogging((builder => { builder.AddConsole(); }));
            _services.AddSingleton <IConfiguration>(config);

            switch (_options.StorageType)
            {
            case StorageType.AzureBlob:
                SetupAzureBlobStore();
                break;

            case StorageType.LocalFs:
                SetupLocalFsStore();
                break;

            default:
                throw new ArgumentException($"Invalid storage type {_options.StorageType}");
            }

            _services.AddSingleton <IAccountStore, FileSystemAccountStore>();
            _services.AddSingleton <IChallengeStore, FileSystemChallengeStore>();
            _services.AddSingleton <ICertStore, FileSystemCertStore>();
            _services.AddSingleton <ICertReader, FileSystemCertStore>();
            _services.AddSingleton <IClientStateStore, DelegatedClientStateStore>();
            _services.AddSingleton((provider) =>
            {
                var client = new AcmeClient(_options.CaUrl, CreateLogger <AcmeClient>(provider));
                client.InitAsync().Wait();
                return(client);
            });
            _services.AddSingleton((provider) => new AcmeOptions
            {
                AcceptTermsOfService = true,
                AccountContactEmails = _options.AccountContactEmails,
                DnsNames             = _options.DnsNames,
                CertificateKeyAlgor  = "rsa"
            });
            _services.AddSingleton <ACMEWorker>();

            var serviceProvider = _services.BuildServiceProvider();
            var worker          = serviceProvider.GetService(typeof(ACMEWorker)) as ACMEWorker;

            await worker.WorkAsync();

            await serviceProvider.DisposeAsync();
        }