Skip to content

Commit

Permalink
feat: create NVD meta data file as part of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Nov 28, 2023
1 parent 26650fe commit 40bc5d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions vulnz/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation project(':open-vulnerability-store')
implementation 'info.picocli:picocli-spring-boot-starter:4.7.4'
implementation 'com.diogonunes:JColor:5.5.1'
implementation 'commons-io:commons-io:2.15.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2'
implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.github.jeremylong.vulnz.cli.cache.CacheException;
import io.github.jeremylong.vulnz.cli.cache.CacheProperties;
import io.github.jeremylong.vulnz.cli.model.BasicOutput;
import org.apache.commons.io.output.CountingOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -307,10 +308,13 @@ private Integer processRequest(NvdCveClientBuilder builder, CacheProperties prop
} catch (NoSuchAlgorithmException e) {
throw new CacheException("Unable to calculate sha256 checksum", e);
}
long byteCount = 0;
try (FileOutputStream fileOutputStream = new FileOutputStream(file);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream);
DigestOutputStream digestOutputStream = new DigestOutputStream(gzipOutputStream, md);) {
objectMapper.writeValue(digestOutputStream, data);
DigestOutputStream digestOutputStream = new DigestOutputStream(gzipOutputStream, md);
CountingOutputStream countingOutputStream = new CountingOutputStream(digestOutputStream)) {
objectMapper.writeValue(countingOutputStream, data);
byteCount = countingOutputStream.getByteCount();
} catch (IOException ex) {
throw new CacheException("Unable to write cached data: " + file, ex);
}
Expand All @@ -320,6 +324,7 @@ private Integer processRequest(NvdCveClientBuilder builder, CacheProperties prop
PrintWriter writer = new PrintWriter(osw)) {
final String lmd = DateTimeFormatter.ISO_DATE_TIME.format(timestamp);
writer.println("lastModifiedDate:" + lmd);
writer.println("size: " + byteCount);
writer.println("gzSize:" + file.length());
writer.println("sha256:" + checksum);
} catch (IOException ex) {
Expand Down

0 comments on commit 40bc5d9

Please sign in to comment.