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

Add min_scan_level to nibbles with phantom result toggle #4054

Draft
wants to merge 4 commits into
base: feature/nibbles
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion octopoes/nibbles/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import BaseModel
from xxhash import xxh3_128_hexdigest as xxh3

from octopoes.models import OOI, Reference
from octopoes.models import OOI, Reference, ScanLevel

NIBBLES_DIR = Path(__file__).parent
NIBBLE_ATTR_NAME = "NIBBLE"
Expand Down Expand Up @@ -50,6 +50,7 @@ class NibbleDefinition(BaseModel):
query: str | Callable[[list[Reference | None]], str] | None = None
enabled: bool = True
additional: set[type[OOI]] = set()
minimal_scan_level: ScanLevel | None = None
_payload: MethodType | None = None
_checksum: str | None = None

Expand Down
1 change: 1 addition & 0 deletions octopoes/nibbles/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def _write(self, valid_time: datetime):
origin_type=OriginType.NIBBLET,
source=source_ooi.reference,
result=[ooi.reference for ooi in result],
phantom_result=[],
parameters_hash=nibble_hasher(arg, self.nibbles[nibble_id]._checksum),
parameters_references=[a.reference if isinstance(a, OOI) else None for a in arg],
)
Expand Down
11 changes: 11 additions & 0 deletions octopoes/octopoes/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ def recalculate_scan_profiles(self, valid_time: datetime) -> None:
)
logger.info("Recalculated scan profiles")

def nibblet_toggle_phantom_result(self, origin_id: str, valid_time: datetime) -> None:
origin = self.origin_repository.get(origin_id, valid_time)
if origin.origin_type == OriginType.NIBBLET and origin.phantom_result is not None:
if origin.result and not origin.phantom_result:
origin.phantom_result = self.ooi_repository.load_bulk_as_list(set(origin.result), valid_time)
origin.result = []
elif origin.phantom_result and not origin.result:
origin.result = [result.reference for result in origin.phantom_result]
origin.phantom_result = []
self.origin_repository.save(origin, valid_time)

def process_event(self, event: DBEvent) -> None:
# handle event
event_handler_name = f"_on_{event.operation_type.value}_{event.entity_type}"
Expand Down
3 changes: 2 additions & 1 deletion octopoes/octopoes/models/origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import BaseModel, Field

from octopoes.models import Reference
from octopoes.models import OOI, Reference


class OriginType(Enum):
Expand All @@ -22,6 +22,7 @@ class Origin(BaseModel):
source: Reference
source_method: str | None = None # None for bits and normalizers
result: list[Reference] = Field(default_factory=list)
phantom_result: list[OOI] | None = None # None for anything other than nibblet
parameters_hash: str | None = None # None for anything other than nibblet
parameters_references: list[Reference | None] | None = None # None for anything other than nibblet
task_id: UUID | None = None
Expand Down
11 changes: 8 additions & 3 deletions octopoes/octopoes/repositories/origin_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def list_origins(
limit: int | None = None,
source: Reference | None = None,
result: Reference | None = None,
phantom_result: Reference | None = None,
method: str | list[str] | None = None,
parameters_hash: int | None = None,
parameters_references: list[Reference] | None = None,
Expand Down Expand Up @@ -78,6 +79,7 @@ def list_origins(
limit: int | None = None,
source: Reference | None = None,
result: Reference | None = None,
phantom_result: Reference | None = None,
method: str | list[str] | None = None,
parameters_hash: int | None = None,
parameters_references: list[Reference] | None = None,
Expand All @@ -94,6 +96,9 @@ def list_origins(
if result:
where_parameters["result"] = str(result)

if phantom_result:
where_parameters["phantom_result"] = str(phantom_result)

if method:
where_parameters["method"] = method

Expand All @@ -114,12 +119,12 @@ def list_origins(
results = self.session.client.query(query, valid_time=valid_time)
return [self.deserialize(r[0]) for r in results]

def get(self, id_: str, valid_time: datetime) -> Origin:
def get(self, origin_id: str, valid_time: datetime) -> Origin:
try:
return self.deserialize(self.session.client.get_entity(id_, valid_time))
return self.deserialize(self.session.client.get_entity(origin_id, valid_time))
except HTTPStatusError as e:
if e.response.status_code == HTTPStatus.NOT_FOUND:
raise ObjectNotFoundException(id_)
raise ObjectNotFoundException(origin_id)
else:
raise e

Expand Down
Loading