Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate include validation #32

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ocsf_validator/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ def get_type(self):
return OcsfExtension


class IncludeMatcher(RegexMatcher, TypeMatcher):
def __init__(self):
self._pattern = re.compile(r".*includes/.*.json")

def get_type(self):
return OcsfInclude


class ProfileMatcher(RegexMatcher, TypeMatcher):
def __init__(self):
self._pattern = re.compile(r".*profiles/.*.json")
Expand Down
2 changes: 1 addition & 1 deletion ocsf_validator/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def resolve_include(
for file in filenames:
if relative_to is not None:
# Search extension for relative include path,
# e.g. /includes/thing.json -> /extensions/stuff/includes/thing.json
# e.g. /profiles/thing.json -> /extensions/stuff/profiles/thing.json
extn = self._types.extension(relative_to)
if extn is not None:
k = self._reader.key("extensions", extn, file)
Expand Down
2 changes: 0 additions & 2 deletions ocsf_validator/type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
VersionMatcher(),
DictionaryMatcher(),
CategoriesMatcher(),
IncludeMatcher(),
CategoriesMatcher(),
query-jeremy marked this conversation as resolved.
Show resolved Hide resolved
ProfileMatcher(),
ObjectMatcher(),
EventMatcher(),
Expand Down
10 changes: 2 additions & 8 deletions ocsf_validator/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
DictionaryMatcher,
EventMatcher,
ExtensionMatcher,
IncludeMatcher,
ObjectMatcher,
ProfileMatcher,
)
Expand All @@ -49,7 +48,6 @@

METASCHEMA_MATCHERS = {
"event.schema.json": EventMatcher(),
"include.schema.json": IncludeMatcher(),
"object.schema.json": ObjectMatcher(),
"profile.schema.json": ProfileMatcher(),
"categories.schema.json": CategoriesMatcher(),
Expand Down Expand Up @@ -231,9 +229,7 @@ def validate(reader: Reader, file: str):

reader.apply(
validate,
AnyMatcher(
[ObjectMatcher(), EventMatcher(), ProfileMatcher(), IncludeMatcher()]
),
AnyMatcher([ObjectMatcher(), EventMatcher(), ProfileMatcher()]),
)


Expand Down Expand Up @@ -374,9 +370,7 @@ def validate(reader: Reader, file: str):

reader.apply(
validate,
AnyMatcher(
[ObjectMatcher(), EventMatcher(), ProfileMatcher(), IncludeMatcher()]
),
AnyMatcher([ObjectMatcher(), EventMatcher(), ProfileMatcher()]),
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ocsf-validator"
version = "0.2.0"
version = "0.2.1"
description = "OCSF Schema Validation"
authors = [
"Jeremy Fisher <[email protected]>",
Expand Down
14 changes: 7 additions & 7 deletions tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def test_include_one():
net["name"] = "network"
net["name2"] = "network"
httpa = event("http_activity")
httpa["$include"] = "includes/network.json"
httpa["$include"] = "profiles/network.json"

s = {
"/events/network/http_activity.json": httpa,
"/includes/network.json": net,
"/profiles/network.json": net,
"/dictionary.json": attributes(["stuff"]),
}

Expand All @@ -49,11 +49,11 @@ def test_include_many():
net = attributes(["proxy", "src_ip"])
thing = attributes(["dest_ip", "score"])
httpa = event("http_activity")
httpa["$include"] = ["includes/network.json", "events/thing.json"]
httpa["$include"] = ["profiles/network.json", "events/thing.json"]

s = {
"/events/network/http_activity.json": httpa,
"/includes/network.json": net,
"/profiles/network.json": net,
"/events/thing.json": thing,
"/dictionary.json": attributes(["stuff"]),
}
Expand All @@ -72,11 +72,11 @@ def test_include_attrs():
net = attributes(["proxy", "src_ip"])
thing = attributes(["dest_ip", "score"])
httpa = event("http_activity")
httpa["attributes"]["$include"] = ["includes/network.json", "events/thing.json"]
httpa["attributes"]["$include"] = ["profiles/network.json", "events/thing.json"]

s = {
"/events/network/http_activity.json": httpa,
"/includes/network.json": net,
"/profiles/network.json": net,
"/events/thing.json": thing,
"/dictionary.json": attributes(["stuff"]),
}
Expand All @@ -93,7 +93,7 @@ def test_include_attrs():

def test_missing_include():
httpa = event("http_activity")
httpa["attributes"]["$include"] = "includes/network.json"
httpa["attributes"]["$include"] = "profiles/network.json"

s = {
"/events/network/http_activity.json": httpa,
Expand Down
Loading