internal static ScheduledRenewal Load(string renewal) { var result = JsonConvert.DeserializeObject <ScheduledRenewal>(renewal); if (result == null || result.Binding == null) { Program.Log.Error("Unable to deserialize renewal {renewal}", renewal); return(null); } if (result.Binding.AlternativeNames == null) { result.Binding.AlternativeNames = new List <string>(); } if (result.Binding.Plugin == null) { Program.Log.Error("Plugin {plugin} not found", result.Binding.PluginName); return(null); } if (result.Binding.HostIsDns == null) { result.Binding.HostIsDns = !result.San; } try { ITargetPlugin target = result.GetTargetPlugin(); if (target != null) { result.Binding = target.Refresh(Program.Options, result.Binding); if (result.Binding == null) { // No match, return nothing, effectively cancelling the renewal Program.Log.Error("Target for {result} no longer found, cancelling renewal", result); return(null); } } } catch (Exception ex) { Program.Log.Warning("Error refreshing renewal for {host} - {@ex}", result.Binding.Host, ex); } return(result); }
private ScheduledRenewal Load(string renewal, string path) { var result = JsonConvert.DeserializeObject <ScheduledRenewal>(renewal); if (result == null || result.Binding == null) { _log.Error("Unable to deserialize renewal {renewal}", renewal); return(null); } if (result.History == null) { result.History = new List <RenewResult>(); var historyFile = ScheduledRenewal.HistoryFile(result.Binding, path); if (historyFile.Exists) { try { result.History = JsonConvert.DeserializeObject <List <RenewResult> >(File.ReadAllText(historyFile.FullName)); } catch { _log.Warning("Unable to read history file {path}", historyFile.Name); } } } if (result.Binding.AlternativeNames == null) { result.Binding.AlternativeNames = new List <string>(); } if (result.Binding.HostIsDns == null) { result.Binding.HostIsDns = !result.San; } if (result.Binding.IIS == null) { result.Binding.IIS = !(result.Binding.PluginName == ScriptClient.PluginName); } try { ITargetPlugin target = result.Binding.GetTargetPlugin(); if (target != null) { result.Binding = target.Refresh(Program.OptionsService, result.Binding); if (result.Binding == null) { // No match, return nothing, effectively cancelling the renewal _log.Error("Cancelling renewal"); return(null); } } else { _log.Error("TargetPlugin not found {PluginName} {TargetPluginName}", result.Binding.PluginName, result.Binding.TargetPluginName); return(null); } } catch (Exception ex) { _log.Warning("Error refreshing renewal for {host} - {@ex}", result.Binding.Host, ex); } return(result); }
private static void ProcessRenewal(List <ScheduledRenewal> renewals, DateTime now, ScheduledRenewal renewal) { if (!_options.ForceRenewal) { _log.Verbose("Checking {renewal}", renewal.Binding.Host); if (renewal.Date >= now) { _log.Information("Renewal for certificate {renewal} not scheduled, due after {date}", renewal.Binding.Host, renewal.Date.ToUserString()); return; } } // Refresh try { ITargetPlugin target = renewal.Binding.GetTargetPlugin(); if (target != null) { renewal.Binding = target.Refresh(OptionsService, renewal.Binding); if (renewal.Binding == null) { _log.Error("Renewal target not found, will retry on next run"); return; } } } catch (Exception ex) { _log.Warning("Error refreshing renewal for {host} - {@ex}", renewal.Binding.Host, ex); } _log.Information(true, "Renewing certificate for {renewal}", renewal.Binding.Host); _options.CentralSslStore = renewal.CentralSsl; _options.KeepExisting = string.Equals(renewal.KeepExisting, "true", StringComparison.InvariantCultureIgnoreCase); _options.Script = renewal.Script; _options.ScriptParameters = renewal.ScriptParameters; _options.Warmup = renewal.Warmup; try { // Let the plugin run var result = renewal.Binding.Plugin.Auto(renewal.Binding); // Process result if (result.Success) { renewal.Date = DateTime.UtcNow.AddDays(_renewalService.RenewalPeriod); _log.Information(true, "Renewal for {host} succeeded, next one scheduled for {date}", renewal.Binding.Host, renewal.Date.ToUserString()); } else { _log.Error("Renewal for {host} failed, will retry on next run", renewal.Binding.Host); } // Store historical information if (renewal.History == null) { renewal.History = new List <RenewResult>(); } renewal.History.Add(result); // Persist to registry _renewalService.Renewals = renewals; } catch (Exception ex) { HandleException(ex); _log.Error("Renewal for {host} failed, will retry on next run", renewal.Binding.Host); } }