Skip to content

Commit

Permalink
Refactored Boefje.schema to Boefje.boefje_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ammar92 committed Sep 18, 2024
1 parent b995d32 commit b874930
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion boefjes/boefjes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ def create_boefje_meta(task, plugin: PluginType) -> BoefjeMeta:
input_ooi=input_ooi,
arguments=arguments,
organization=organization,
environment=get_environment_settings(task.data, plugin.schema),
environment=get_environment_settings(task.data, plugin.boefje_schema),
)
return boefje_meta
2 changes: 1 addition & 1 deletion boefjes/boefjes/dependencies/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def schema(self, plugin_id: str) -> dict | None:
try:
boefje = self.plugin_storage.boefje_by_id(plugin_id)

return boefje.schema
return boefje.boefje_schema
except PluginNotFound:
return self.local_repo.schema(plugin_id)

Expand Down
2 changes: 1 addition & 1 deletion boefjes/boefjes/job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def handle(self, boefje_meta: BoefjeMeta) -> None:
boefje_meta.arguments["input"] = ooi.serialize()

boefje_meta.runnable_hash = plugin.runnable_hash
boefje_meta.environment = get_environment_settings(boefje_meta, plugin.schema)
boefje_meta.environment = get_environment_settings(boefje_meta, plugin.boefje_schema)

mime_types = _default_mime_types(boefje_meta.boefje).union(plugin.produces)

Expand Down
4 changes: 2 additions & 2 deletions boefjes/boefjes/katalogus/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ class BoefjeIn(BaseModel):
scan_level: int = 1
consumes: set[str] = Field(default_factory=set)
produces: set[str] = Field(default_factory=set)
schema: dict | None = None
boefje_schema: dict | None = None
oci_image: str | None = None
oci_arguments: list[str] = Field(default_factory=list)

@field_validator("schema")
@field_validator("boefje_schema")
@classmethod
def json_schema_valid(cls, schema: dict | None) -> dict | None:
if schema is not None:
Expand Down
4 changes: 2 additions & 2 deletions boefjes/boefjes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Boefje(Plugin):
scan_level: int = 1
consumes: set[str] = Field(default_factory=set)
produces: set[str] = Field(default_factory=set)
schema: dict | None = None
boefje_schema: dict | None = None
runnable_hash: str | None = None
oci_image: str | None = None
oci_arguments: list[str] = Field(default_factory=list)

@field_validator("schema")
@field_validator("boefje_schema")
@classmethod
def json_schema_valid(cls, schema: dict) -> dict:
if schema is not None:
Expand Down
2 changes: 1 addition & 1 deletion boefjes/boefjes/plugins/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, path: Path, package: str):

if (path / SCHEMA_FILE).exists():
try:
self.boefje.schema = json.load((path / SCHEMA_FILE).open())
self.boefje.boefje_schema = json.load((path / SCHEMA_FILE).open())
except JSONDecodeError as e:
raise ModuleException("Invalid schema file") from e
except SchemaError as e:
Expand Down
4 changes: 2 additions & 2 deletions boefjes/boefjes/sql/plugin_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def to_boefje_in_db(boefje: Boefje) -> BoefjeInDB:
scan_level=str(boefje.scan_level),
consumes=boefje.consumes,
produces=boefje.produces,
schema=boefje.schema,
schema=boefje.boefje_schema,
oci_image=boefje.oci_image,
oci_arguments=boefje.oci_arguments,
version=boefje.version,
Expand Down Expand Up @@ -141,7 +141,7 @@ def to_boefje(boefje_in_db: BoefjeInDB) -> Boefje:
scan_level=int(boefje_in_db.scan_level),
consumes=boefje_in_db.consumes,
produces=boefje_in_db.produces,
schema=boefje_in_db.schema,
boefje_schema=boefje_in_db.schema,
oci_image=boefje_in_db.oci_image,
oci_arguments=boefje_in_db.oci_arguments,
version=boefje_in_db.version,
Expand Down
10 changes: 5 additions & 5 deletions boefjes/tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_update_plugins(test_client, organisation):

def test_cannot_create_boefje_with_invalid_schema(test_client, organisation):
boefje = Boefje(id="test_plugin", name="My test boefje", description="123").model_dump(mode="json")
boefje["schema"] = {"$schema": 3}
boefje["boefje_schema"] = {"$schema": 3}

r = test_client.post(f"/v1/organisations/{organisation.id}/plugins", json=boefje)
assert r.status_code == 400
Expand All @@ -137,7 +137,7 @@ def test_update_boefje_schema(test_client, organisation):
boefje = Boefje(id="test_plugin", name="My test boefje", description="123")
test_client.post(f"/v1/organisations/{organisation.id}/plugins", content=boefje.model_dump_json())

r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"schema": {"$schema": 3}})
r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": {"$schema": 3}})
assert r.status_code == 400

valid_schema = {
Expand All @@ -151,16 +151,16 @@ def test_update_boefje_schema(test_client, organisation):
},
"required": [],
}
r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"schema": valid_schema})
r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": valid_schema})
assert r.status_code == 204

schema = test_client.get(f"/v1/organisations/{organisation.id}/plugins/{boefje.id}/schema.json").json()
assert schema == valid_schema

api_boefje = test_client.get(f"/v1/organisations/{organisation.id}/plugins/{boefje.id}").json()
assert api_boefje["schema"] == valid_schema
assert api_boefje["boefje_schema"] == valid_schema

r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/dns-records", json={"schema": valid_schema})
r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/dns-records", json={"boefje_schema": valid_schema})
assert r.status_code == 404


Expand Down
4 changes: 2 additions & 2 deletions rocky/katalogus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Boefje(Plugin):
produces: set[str] = Field(default_factory=set)
options: list[str] | None = None
runnable_hash: str | None = None
schema: dict | None = None
boefje_schema: dict | None = None
oci_image: str | None = None
oci_arguments: list[str] = Field(default_factory=list)

Expand Down Expand Up @@ -243,7 +243,7 @@ def parse_boefje(boefje: dict) -> Boefje:
scan_level=scan_level,
consumes=consumes,
produces=boefje["produces"],
schema=boefje.get("schema"),
boefje_schema=boefje.get("schema"),
oci_image=boefje.get("oci_image"),
oci_arguments=boefje.get("oci_arguments", []),
)
Expand Down
2 changes: 1 addition & 1 deletion rocky/katalogus/views/boefje_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def form_valid(self, form):
scan_level=form_data["scan_level"],
consumes=input_objects,
produces=produces,
schema=form_data["schema"],
boefje_schema=form_data["schema"],
oci_image=form_data.get("oci_image"),
oci_arguments=arguments,
)
Expand Down
4 changes: 2 additions & 2 deletions rocky/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ def boefje_dns_records():
options=None,
runnable_hash=None,
produces={"boefje/dns-records"},
schema={},
boefje_schema={},
oci_image="ghcr.io/test/image:123",
oci_arguments=["-test", "-arg"],
)
Expand All @@ -1835,7 +1835,7 @@ def boefje_nmap_tcp():
options=None,
runnable_hash=None,
produces={"boefje/nmap"},
schema={},
boefje_schema={},
oci_image="ghcr.io/test/image:123",
oci_arguments=["-test", "-arg"],
)
Expand Down

0 comments on commit b874930

Please sign in to comment.