示例#1
0
  public VulnerabilityUpdateStatus updateForRelease(Release release) {
    Optional<List<CveSearchData>> cveSearchDatas = cveSearchWrapper.searchForRelease(release);
    if (!cveSearchDatas.isPresent()) {
      return new VulnerabilityUpdateStatus().setRequestStatus(RequestStatus.FAILURE);
    }

    CveSearchDataTranslator cveSearchDataTranslator = new CveSearchDataTranslator();
    List<CveSearchDataTranslator.VulnerabilityWithRelation> translated =
        cveSearchDatas
            .get()
            .stream()
            .map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData))
            .map(
                vulnerabilityWithRelation -> {
                  vulnerabilityWithRelation.relation.setReleaseId(release.getId());
                  return vulnerabilityWithRelation;
                })
            .collect(Collectors.toList());

    VulnerabilityUpdateStatus updateStatus = getEmptyVulnerabilityUpdateStatus();
    for (CveSearchDataTranslator.VulnerabilityWithRelation vulnerabilityWithRelation : translated) {
      updateStatus =
          vulnerabilityConnector.addOrUpdate(
              vulnerabilityWithRelation.vulnerability,
              vulnerabilityWithRelation.relation,
              updateStatus);
    }

    return updateStatus;
  }
示例#2
0
  @Override
  public VulnerabilityUpdateStatus fullUpdate() throws TException {
    List<Release> allReleases = vulnerabilityConnector.getAllReleases();

    return allReleases
        .stream()
        .map(this::updateForRelease)
        .reduce(
            getEmptyVulnerabilityUpdateStatus(),
            (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2));
  }
示例#3
0
  @Override
  public VulnerabilityUpdateStatus updateForComponent(String componentId) throws TException {
    Optional<Component> component = vulnerabilityConnector.getComponent(componentId);

    return component
        .map(
            c ->
                c.isSetReleaseIds()
                    ? c.getReleaseIds()
                        .stream()
                        .map(this::updateForRelease)
                        .reduce(
                            getEmptyVulnerabilityUpdateStatus(),
                            (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2))
                    : getEmptyVulnerabilityUpdateStatus())
        .orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE));
  }
示例#4
0
  @Override
  public VulnerabilityUpdateStatus updateForProject(String projectId) throws TException {
    Optional<Project> project = vulnerabilityConnector.getProject(projectId);

    return project
        .map(
            r ->
                r.isSetReleaseIdToUsage()
                    ? r.getReleaseIdToUsage()
                        .keySet()
                        .stream()
                        .map(this::updateForRelease)
                        .reduce(
                            getEmptyVulnerabilityUpdateStatus(),
                            (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2))
                    : getEmptyVulnerabilityUpdateStatus())
        .orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE));
  }
示例#5
0
 @Override
 public VulnerabilityUpdateStatus updateForRelease(String releaseId) {
   Optional<Release> release = vulnerabilityConnector.getRelease(releaseId);
   Optional<VulnerabilityUpdateStatus> updateStatus = release.map(this::updateForRelease);
   return updateStatus.orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE));
 }