/// <summary>
        /// Load provider settings or create new
        /// </summary>
        private void LoadSettings()
        {
            if (!System.IO.Directory.Exists(_settingsFolder))
            {
                System.IO.Directory.CreateDirectory(_settingsFolder);
            }

            if (System.IO.File.Exists(_settingsFolder + "\\c-settings.json"))
            {
                var json = System.IO.File.ReadAllText(_settingsFolder + "\\c-settings.json");
                _settings = Newtonsoft.Json.JsonConvert.DeserializeObject <CertesSettings>(json);
            }
            else
            {
                _settings = new CertesSettings();
            }
        }
예제 #2
0
        /// <summary>
        /// Initialise provider settings, loading current account key if present
        /// </summary>
        public async Task <bool> InitProvider(ILog log = null, AccountDetails account = null)
        {
            if (log != null)
            {
                _log = log;
            }

            PreInitAcmeContext();

            if (_settings == null)
            {
                if (account == null)
                {
                    // if initalising without a known account, attempt to load details form storage
                    if (System.IO.File.Exists(_settingsFolder + "\\c-settings.json"))
                    {
                        var json = System.IO.File.ReadAllText(_settingsFolder + "\\c-settings.json");
                        _settings = Newtonsoft.Json.JsonConvert.DeserializeObject <CertesSettings>(json);
                    }
                    else
                    {
                        _settings = new CertesSettings();
                    }

                    if (!string.IsNullOrEmpty(_settings.AccountKey))
                    {
                        if (System.IO.File.Exists(_settingsFolder + "\\c-acc.key"))
                        {
                            //remove legacy key info
                            System.IO.File.Delete(_settingsFolder + "\\c-acc.key");
                        }
                        SetAcmeContextAccountKey(_settings.AccountKey);
                    }
                    else
                    {
                        // no account key in settings, check .key (legacy key file)
                        if (System.IO.File.Exists(_settingsFolder + "\\c-acc.key"))
                        {
                            var pem = System.IO.File.ReadAllText(_settingsFolder + "\\c-acc.key");
                            SetAcmeContextAccountKey(pem);
                        }
                    }
                }
                else
                {
                    _settings = new CertesSettings
                    {
                        AccountEmail = account.Email,
                        AccountKey   = account.AccountKey,
                        AccountUri   = account.AccountURI
                    };
                    SetAcmeContextAccountKey(_settings.AccountKey);
                }
            }
            else
            {
                SetAcmeContextAccountKey(_settings.AccountKey);
            }

            _currentOrders = new Dictionary <string, IOrderContext>();

            return(await Task.FromResult(true));
        }