All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.danielsomerfield.cvecheck.DefaultScanningEngineSourceUpdate.groovy Maven / Gradle / Ivy

There is a newer version: 0.6.2-100
Show newest version
package com.danielsomerfield.cvecheck

import com.danielsomerfield.cvecheck.owaspdependencycheck.ScanningEngine
import com.danielsomerfield.util.Maybe
import com.danielsomerfield.util.TimeSource
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class DefaultScanningEngineSourceUpdate implements ScanningEngineSourceUpdate {
  private Configuration configuration;
  private RuntimeStore runtimeStore;
  private TimeSource timeSource;
  private final Logger logger = LoggerFactory.getLogger(this.class)

  public DefaultScanningEngineSourceUpdate(
      final Configuration configuration, final RuntimeStore runtimeStore, TimeSource timeSource) {
    this.configuration = configuration
    this.runtimeStore = runtimeStore
    this.timeSource = timeSource
  }

  @Override
  public void run(ScanningEngine engine) {
    if (this.configuration.refreshAfter() <= 0 || refreshTimePast()) {
      logger.info("Updating CVE contents.")
      engine.updateSource()
      runtimeStore.refreshed()
    } else {
      logger.info("Skipping CVE update.")
    }
  }

  public boolean refreshTimePast(){
    Maybe lastRefreshed = runtimeStore.lastRefreshed()
    long currentTime = timeSource.currentTimeInMillis()
    long refreshAfterInMillis = configuration.refreshAfter() * 1000;
    return !lastRefreshed.exists() || (currentTime - lastRefreshed.value > refreshAfterInMillis)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy