/// <summary> /// Get a certificate from the cache /// </summary> /// <param name="context"></param> /// <param name="runLevel"></param> /// <returns></returns> private CertificateInfo?GetFromCache(OrderContext context, RunLevel runLevel) { var cachedCertificate = _certificateService.CachedInfo(context.Order); if (cachedCertificate == null || cachedCertificate.CacheFile == null) { return(null); } if (cachedCertificate.CacheFile.LastWriteTime < DateTime.Now.AddDays(_settings.Cache.ReuseDays * -1)) { return(null); } if (runLevel.HasFlag(RunLevel.IgnoreCache)) { _log.Warning( "Cached certificate available but not used due to --{switch} switch.", nameof(MainArguments.Force).ToLower()); return(null); } _log.Warning( "Using cache for {friendlyName}. To get a new certificate " + "within {days} days, run with --{switch}.", context.Order.FriendlyNameIntermediate, _settings.Cache.ReuseDays, nameof(MainArguments.Force).ToLower()); return(cachedCertificate); }
public virtual bool ShouldRun(Order order) { var renewalDue = IsDue(order.Renewal); if (renewalDue) { return(true); } if (_certificateService.CachedInfo(order) == null) { _logService.Information(LogType.All, "Renewal {renewal} running prematurely due to source change in order {order}", order.Renewal.LastFriendlyName, order.FriendlyNamePart ?? OrderContext.DefaultOrderName); return(true); } return(false); }
private string NotificationHosts(Renewal renewal) { try { var cache = _certificateService.CachedInfo(renewal); if (cache == null) { return("Unknown"); } else { return(string.Join(", ", cache.HostNames)); } } catch { return("Error"); } }