com.metaeffekt.mirror.index.advisor.CertSeiAdvisorIndex Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.metaeffekt.mirror.index.advisor;
import com.metaeffekt.artifact.analysis.utils.FileUtils;
import com.metaeffekt.mirror.download.documentation.MirrorMetadata;
import com.metaeffekt.mirror.contents.advisory.CertSeiAdvisorEntry;
import com.metaeffekt.mirror.download.advisor.CertSeiDownload;
import com.metaeffekt.mirror.download.documentation.DocRelevantMethods;
import com.metaeffekt.mirror.index.Index;
import org.apache.lucene.document.Document;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The CERT-SEI provides multiple JSON files with one note/advisor per file. To parse the JSON files in the download
* directory:
*
* - iterate over all JSON files in the directory,
* - read and parse the JSON contents of each file,
* - use
CertSeiAdvisorEntry.fromDownloadJson
to map the fields to a CertSeiAdvisorEntry
object.
*
*
* Mapping of JSON content to CertSeiAdvisorEntry
fields
*
*
* JSON
* CertSeiAdvisorEntry
*
*
*
*
* vuid
, idnumber
, id
* id
*
*
* datecreated
, datefirstpublished
, publicdate
, dateupdated
* createDate
*
*
* dateupdated
, datecreated
, datefirstpublished
, publicdate
* updateDate
*
*
* author
& thanks
& Acknowledgements
* acknowledgements
*
*
* public
* references
*
*
* keywords
* keywords
*
*
* cveids
* referenceIds
*
*
* cvss_basevector
& cvss_environmentalvector
* cvss2
*
*
* name
, Overview
, clean_description
* summary
*
*
* longest(Description
, ""
, clean_description
)
* description
*
*
* Impact
, impact
* threat
*
*
* Solution
, resolution
* recommendation
*
*
* Workarounds
, workarounds
* workarounds
*
*
*
*/
@MirrorMetadata(directoryName = "certsei-advisors", mavenPropertyName = "certSeiAdvisorIndex")
public class CertSeiAdvisorIndex extends Index {
private final static Logger LOG = LoggerFactory.getLogger(CertSeiAdvisorIndex.class);
public CertSeiAdvisorIndex(File baseMirrorDirectory) {
super(baseMirrorDirectory, CertSeiAdvisorIndex.class, Collections.singletonList(CertSeiDownload.class), Collections.emptyList());
}
@Override
@DocRelevantMethods({"CertSeiAdvisorEntry#fromDownloadJson"})
protected Map createIndexDocuments() {
final Map documents = new HashMap<>();
final List files = super.getAllFilesInSubDirectories(super.requiredDownloads[0]);
for (File file : files) {
try {
final List contents = FileUtils.readLines(file, StandardCharsets.UTF_8);
final JSONObject jsonContent = new JSONObject(String.join("", contents));
final CertSeiAdvisorEntry parsedEntry = CertSeiAdvisorEntry.fromDownloadJson(jsonContent);
documents.put(parsedEntry.getId(), parsedEntry.toDocument());
} catch (IOException e) {
throw new RuntimeException("Unable to read file contents during indexing ", e);
}
}
return documents;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy