Skip to content

Commit

Permalink
Addressed PR feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Jul 11, 2024
1 parent f8ead7a commit 1c1e109
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 31 deletions.
Binary file modified security-analytics-commons-1.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.startObject()
.field(STIX2IOC.ID_FIELD, ioc.getId())
.field(STIX2IOC.NAME_FIELD, ioc.getName())
.field(STIX2IOC.TYPE_FIELD, ioc.getType().getType())
.field(STIX2IOC.TYPE_FIELD, ioc.getType().toString())
.field(STIX2IOC.VALUE_FIELD, ioc.getValue())
.field(STIX2IOC.SEVERITY_FIELD, ioc.getSeverity())
.timeField(STIX2IOC.CREATED_FIELD, ioc.getCreated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static STIX2IOC readFrom(StreamInput sin) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(super.getId());
out.writeString(super.getName());
out.writeString(super.getType().getType());
out.writeString(super.getType().toString());
out.writeString(super.getValue());
out.writeString(super.getSeverity());
out.writeInstant(super.getCreated());
Expand All @@ -160,7 +160,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject()
.field(ID_FIELD, super.getId())
.field(NAME_FIELD, super.getName())
.field(TYPE_FIELD, super.getType().getType())
.field(TYPE_FIELD, super.getType().toString())
.field(VALUE_FIELD, super.getValue())
.field(SEVERITY_FIELD, super.getSeverity());
XContentUtils.buildInstantAsField(builder, super.getCreated(), CREATED_FIELD);
Expand Down Expand Up @@ -292,8 +292,8 @@ public static STIX2IOC parse(XContentParser xcp, String id, Long version) throws
public void validate() throws IllegalArgumentException {
if (super.getType() == null) {
throw new IllegalArgumentException(String.format("[%s] is required.", TYPE_FIELD));
} else if (!IOCType.supportedType(super.getType().getType())) {
logger.debug("Unsupported IOCType: {}", super.getType().getType());
} else if (!IOCType.supportedType(super.getType().toString())) {
logger.debug("Unsupported IOCType: {}", super.getType().toString());
throw new IllegalArgumentException(String.format("[%s] is not supported.", TYPE_FIELD));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static STIX2IOCDto readFrom(StreamInput sin) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeString(name);
out.writeString(type.getType());
out.writeString(type.toString());
out.writeString(value);
out.writeString(severity);
out.writeInstant(created);
Expand All @@ -120,7 +120,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.startObject()
.field(STIX2IOC.ID_FIELD, id)
.field(STIX2IOC.NAME_FIELD, name)
.field(STIX2IOC.TYPE_FIELD, type.getType())
.field(STIX2IOC.TYPE_FIELD, type.toString())
.field(STIX2IOC.VALUE_FIELD, value)
.field(STIX2IOC.SEVERITY_FIELD, severity)
.timeField(STIX2IOC.CREATED_FIELD, created)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void accept(final STIX2 ioc) {
);

// If the IOC received is not a type listed for the config, do not add it to the queue
if (!feedStore.getSaTifSourceConfig().getIocTypes().contains(stix2IOC.getType().getType())) {
if (!feedStore.getSaTifSourceConfig().getIocTypes().contains(stix2IOC.getType().toString())) {
log.error("{} is not a supported Ioc type for tif source config {}. Skipping IOC {}: of type {} value {}",
stix2IOC.getType().getType(), feedStore.getSaTifSourceConfig().getId(),
stix2IOC.getType().toString(), feedStore.getSaTifSourceConfig().getId(),
stix2IOC.getId(), stix2IOC.getType(), stix2IOC.getValue()
);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void createIocFindings(List<STIX2IOC> iocs,
for (STIX2IOC ioc : iocs) {
String iocValue = ioc.getValue();
if (false == iocValueToType.containsKey(iocValue))
iocValueToType.put(iocValue, ioc.getType().getType());
iocValueToType.put(iocValue, ioc.getType().toString());
iocValueToFeedIds
.computeIfAbsent(iocValue, k -> new HashSet<>())
.add(new IocWithFeeds(ioc.getId(), ioc.getFeedId(), ioc.getFeedName(), "")); //todo figure how to store index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public IocToIndexDetails(StreamInput sin) throws IOException {
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(iocType.getType());
out.writeString(iocType.toString());
out.writeString(indexPattern);
out.writeString(activeIndex);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field(IOC_TYPE_FIELD, iocType.getType())
.field(IOC_TYPE_FIELD, iocType.toString())
.field(INDEX_PATTERN_FIELD, indexPattern)
.field(ACTIVE_INDEX_FIELD, activeIndex)
.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ public void downloadAndSaveIOCs(SATIFSourceConfig saTifSourceConfig,
List<STIX2IOC> validStix2IocList = new ArrayList<>();
// If the IOC received is not a type listed for the config, do not add it to the queue
for (STIX2IOC stix2IOC : stix2IOCList) {
if (saTifSourceConfig.getIocTypes().contains(stix2IOC.getType().getType())) {
if (saTifSourceConfig.getIocTypes().contains(stix2IOC.getType().toString())) {
validStix2IocList.add(stix2IOC);
} else {
log.error("{} is not a supported Ioc type for tif source config {}. Skipping IOC {}: of type {} value {}",
stix2IOC.getType().getType(), saTifSourceConfig.getId(),
stix2IOC.getId(), stix2IOC.getType().getType(), stix2IOC.getValue()
stix2IOC.getType().toString(), saTifSourceConfig.getId(),
stix2IOC.getId(), stix2IOC.getType().toString(), stix2IOC.getValue()
);
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ private void storeAndDeleteIocIndices(List<STIX2IOC> stix2IOCList, ActionListene
Set<String> concreteIndices = SATIFSourceConfigService.getConcreteIndices(clusterStateResponse);

// remove ioc types not specified in list
defaultIocStoreConfig.getIocToIndexDetails().removeIf(iocToIndexDetails -> !IOCType.supportedType(iocToIndexDetails.getIocType().getType()));
defaultIocStoreConfig.getIocToIndexDetails().removeIf(iocToIndexDetails -> !IOCType.supportedType(iocToIndexDetails.getIocType().toString()));

// get the active indices
defaultIocStoreConfig.getIocToIndexDetails().forEach(e -> activeIndices.add(e.getActiveIndex()));
Expand Down Expand Up @@ -468,7 +468,7 @@ private void downloadAndSaveIocsToRefresh(ActionListener<SATIFSourceConfigDto> l
if (newIocStoreConfig instanceof DefaultIocStoreConfig) {
DefaultIocStoreConfig defaultIocStoreConfig = (DefaultIocStoreConfig) newIocStoreConfig;
// remove ioc types not specified in list
defaultIocStoreConfig.getIocToIndexDetails().removeIf(iocToIndexDetails -> !IOCType.supportedType(iocToIndexDetails.getIocType().getType()));
defaultIocStoreConfig.getIocToIndexDetails().removeIf(iocToIndexDetails -> !IOCType.supportedType(iocToIndexDetails.getIocType().toString()));
updatedSourceConfig.setIocStoreConfig(defaultIocStoreConfig);
}
// Update source config as succeeded, change state back to available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public void getIocTypeToIndices(ActionListener<Map<String, List<String>>> listen
for (DefaultIocStoreConfig.IocToIndexDetails iocToindexDetails : iocStoreConfig.getIocToIndexDetails()) {
String activeIndex = iocToindexDetails.getActiveIndex();
IOCType iocType = iocToindexDetails.getIocType();
List<String> strings = cumulativeIocTypeToIndices.computeIfAbsent(iocType.getType(), k -> new ArrayList<>());
List<String> strings = cumulativeIocTypeToIndices.computeIfAbsent(iocType.toString(), k -> new ArrayList<>());
strings.add(activeIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void assertEqualsSaTifSourceConfigs(SATIFSourceConfig saTifSourceConfig,
assertEquals(saTifSourceConfig.isEnabled(), newSaTifSourceConfig.isEnabled());
DefaultIocStoreConfig iocStoreConfig = (DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig();
DefaultIocStoreConfig newIocStoreConfig = (DefaultIocStoreConfig) newSaTifSourceConfig.getIocStoreConfig();
assertEquals(iocStoreConfig.getIocToIndexDetails().get(0).getIocType().getType(), newIocStoreConfig.getIocToIndexDetails().get(0).getIocType().getType());
assertEquals(iocStoreConfig.getIocToIndexDetails().get(0).getIocType().toString(), newIocStoreConfig.getIocToIndexDetails().get(0).getIocType().toString());
assertEquals(iocStoreConfig.getIocToIndexDetails().get(0).getIndexPattern(), newIocStoreConfig.getIocToIndexDetails().get(0).getIndexPattern());
assertEquals(iocStoreConfig.getIocToIndexDetails().get(0).getActiveIndex(), newIocStoreConfig.getIocToIndexDetails().get(0).getActiveIndex());
assertEquals(saTifSourceConfig.getIocTypes(), newSaTifSourceConfig.getIocTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void testRetrieveIOCsSuccessfully() throws IOException, InterruptedExcept
if (!canRunTests) return;

// Execute test for each IOCType
for (String type : IOCType.types()) {
for (String type : IOCType.types) {
// Generate test IOCs, and upload them to S3
int numOfIOCs = 5;
stix2IOCGenerator = new STIX2IOCGenerator(List.of(new IOCType(type)));
Expand Down Expand Up @@ -457,7 +457,7 @@ public void testRetrieveIOCsSuccessfully() throws IOException, InterruptedExcept
// Confirm expected IOCs have been ingested
for (int i = 0; i < numOfIOCs; i++) {
assertEquals(stix2IOCGenerator.getIocs().get(i).getName(), iocs.get(i).get(STIX2IOC.NAME_FIELD));
assertEquals(stix2IOCGenerator.getIocs().get(i).getType().getType(), IOCType.fromString((String) iocs.get(i).get(STIX2IOC.TYPE_FIELD)));
assertEquals(stix2IOCGenerator.getIocs().get(i).getType().toString(), IOCType.fromString((String) iocs.get(i).get(STIX2IOC.TYPE_FIELD)));
assertEquals(stix2IOCGenerator.getIocs().get(i).getValue(), iocs.get(i).get(STIX2IOC.VALUE_FIELD));
assertEquals(stix2IOCGenerator.getIocs().get(i).getSeverity(), iocs.get(i).get(STIX2IOC.SEVERITY_FIELD));

Expand All @@ -482,7 +482,7 @@ public void testRetrieveMultipleIOCTypesSuccessfully() throws IOException, Inter
stix2IOCGenerator = new STIX2IOCGenerator();
s3ObjectGenerator.write(numOfIOCs, objectKey, stix2IOCGenerator);
List<STIX2IOC> allIocs = stix2IOCGenerator.getIocs();
assertEquals("Incorrect total number of test IOCs generated.", IOCType.types().size() * numOfIOCs, allIocs.size());
assertEquals("Incorrect total number of test IOCs generated.", IOCType.types.size() * numOfIOCs, allIocs.size());

// Create test feed
String feedName = "download_test_feed_name";
Expand All @@ -508,7 +508,7 @@ public void testRetrieveMultipleIOCTypesSuccessfully() throws IOException, Inter
Instant.now(),
null,
true,
IOCType.types(),
IOCType.types,
true
);

Expand Down Expand Up @@ -556,7 +556,7 @@ public void testRetrieveMultipleIOCTypesSuccessfully() throws IOException, Inter
// Confirm expected IOCs have been ingested
for (int i = 0; i < allIocs.size(); i++) {
assertEquals(stix2IOCGenerator.getIocs().get(i).getName(), iocHits.get(i).get(STIX2IOC.NAME_FIELD));
assertEquals(stix2IOCGenerator.getIocs().get(i).getType(), IOCType.fromString((String) iocHits.get(i).get(STIX2IOC.TYPE_FIELD)));
assertEquals(stix2IOCGenerator.getIocs().get(i).getType().toString(), IOCType.fromString((String) iocHits.get(i).get(STIX2IOC.TYPE_FIELD)));
assertEquals(stix2IOCGenerator.getIocs().get(i).getValue(), iocHits.get(i).get(STIX2IOC.VALUE_FIELD));
assertEquals(stix2IOCGenerator.getIocs().get(i).getSeverity(), iocHits.get(i).get(STIX2IOC.SEVERITY_FIELD));

Expand All @@ -582,7 +582,7 @@ public void testWithValidAndInvalidIOCTypes() throws IOException {
assertEquals("Incorrect number of test IOCs generated.", numOfIOCs, stix2IOCGenerator.getIocs().size());

List<String> types = new ArrayList<>(invalidTypes);
types.addAll(IOCType.types());
types.addAll(IOCType.types);

// Execute the test for each invalid type
for (String type : invalidTypes) {
Expand Down Expand Up @@ -689,7 +689,7 @@ public void testWithNoIOCsToDownload() {
assertTrue("Failed to create empty bucket object for type.", putObjectResponse.sdkHttpResponse().isSuccessful());

// Execute the test case for each IOC type
for (String type : IOCType.types()) {
for (String type : IOCType.types) {
// Create test feed
String feedName = "download_test_feed_name";
String feedFormat = "STIX2";
Expand Down Expand Up @@ -743,7 +743,7 @@ public void testWhenBucketObjectDoesNotExist() {
);

// Execute the test case for each IOC type
for (String type : IOCType.types()) {
for (String type : IOCType.types) {
// Create test feed
String feedName = "download_test_feed_name";
String feedFormat = "STIX2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class STIX2IOCGenerator implements PojoGenerator {
private List<STIX2IOC> iocs;
private List<IOCType> types = IOCType.types().stream().map(IOCType::new).collect(Collectors.toList());
private List<IOCType> types = IOCType.types.stream().map(IOCType::new).collect(Collectors.toList());

private final ObjectMapper objectMapper;

Expand Down Expand Up @@ -137,7 +137,7 @@ public static STIX2IOC randomIOC(
name = randomLowerCaseString();
}
if (type == null) {
type = new IOCType(IOCType.types().get(randomInt(IOCType.types().size() - 1)));
type = new IOCType(IOCType.types.get(randomInt(IOCType.types.size() - 1)));
}
if (value == null) {
value = randomLowerCaseString();
Expand Down Expand Up @@ -251,7 +251,7 @@ public static void assertIOCEqualsDTO(STIX2IOC ioc, STIX2IOCDto iocDto) {
public static void assertEqualIOCs(STIX2IOC ioc, STIX2IOC newIoc) {
assertNotNull(newIoc.getId());
assertEquals(ioc.getName(), newIoc.getName());
assertEquals(ioc.getType().getType(), newIoc.getType().getType());
assertEquals(ioc.getType().toString(), newIoc.getType().toString());
assertEquals(ioc.getValue(), newIoc.getValue());
assertEquals(ioc.getSeverity(), newIoc.getSeverity());
// assertEquals(ioc.getCreated(), newIoc.getCreated());
Expand All @@ -266,7 +266,7 @@ public static void assertEqualIOCs(STIX2IOC ioc, STIX2IOC newIoc) {
public static void assertEqualIocDtos(STIX2IOCDto ioc, STIX2IOCDto newIoc) {
assertNotNull(newIoc.getId());
assertEquals(ioc.getName(), newIoc.getName());
assertEquals(ioc.getType().getType(), newIoc.getType().getType());
assertEquals(ioc.getType().toString(), newIoc.getType().toString());
assertEquals(ioc.getValue(), newIoc.getValue());
assertEquals(ioc.getSeverity(), newIoc.getSeverity());
// assertEquals(ioc.getCreated(), newIoc.getCreated());
Expand Down

0 comments on commit 1c1e109

Please sign in to comment.