Skip to content

Commit

Permalink
Added some event codes and log trains for some basic API Connector ac…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ammar92 committed Sep 10, 2024
1 parent 500b64b commit 414a5a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions octopoes/octopoes/connector/octopoes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from octopoes.models.transaction import TransactionRecord
from octopoes.models.tree import ReferenceTree
from octopoes.models.types import OOIType
from octopoes.types import DECLARATION_CREATED, OBSERVATION_CREATED, ORIGIN_DELETED


class OctopoesAPIConnector:
Expand Down Expand Up @@ -176,14 +177,16 @@ def delete_origin(self, origin_id: str, valid_time: datetime) -> None:

self.session.delete(f"/{self.client}/origins", params=params)

self.logger.info("Deleted origin", origin_id=origin_id, valid_time=valid_time, event_code=ORIGIN_DELETED)

def save_observation(self, observation: Observation) -> None:
self.session.post(
f"/{self.client}/observations",
headers={"Content-Type": "application/json"},
content=observation.model_dump_json(),
)

self.logger.info("Saved observation", observation=observation)
self.logger.info("Saved observation", observation=observation, event_code=OBSERVATION_CREATED)

def save_declaration(self, declaration: Declaration) -> None:
self.session.post(
Expand All @@ -192,7 +195,7 @@ def save_declaration(self, declaration: Declaration) -> None:
content=declaration.model_dump_json(),
)

self.logger.info("Saved declaration", declaration=declaration)
self.logger.info("Saved declaration", declaration=declaration, event_code=DECLARATION_CREATED)

def save_affirmation(self, affirmation: Affirmation) -> None:
self.session.post(
Expand All @@ -201,7 +204,7 @@ def save_affirmation(self, affirmation: Affirmation) -> None:
content=affirmation.model_dump_json(),
)

self.logger.info("Saved affirmation", affirmation=affirmation)
self.logger.info("Saved affirmation", affirmation=affirmation, event_code=DECLARATION_CREATED)

def save_scan_profile(self, scan_profile: ScanProfile, valid_time: datetime):
params = {"valid_time": str(valid_time)}
Expand Down
4 changes: 2 additions & 2 deletions octopoes/octopoes/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from collections import Counter
from collections.abc import Callable, ValuesView
from datetime import datetime, timezone
from logging import getLogger
from time import perf_counter
from typing import Literal, overload

import structlog
from bits.definitions import get_bit_definitions
from bits.runner import BitRunner
from pydantic import TypeAdapter
Expand Down Expand Up @@ -47,7 +47,7 @@
from octopoes.repositories.scan_profile_repository import ScanProfileRepository
from octopoes.xtdb.client import Operation, OperationType, XTDBSession

logger = getLogger(__name__)
logger = structlog.get_logger("octopoes-core-service")
settings = Settings()


Expand Down
5 changes: 5 additions & 0 deletions octopoes/octopoes/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Event codes for certain actions
OBSERVATION_CREATED = 100101
DECLARATION_CREATED = 100201
AFFIRMATION_CREATED = 100301
ORIGIN_DELETED = 100403

0 comments on commit 414a5a9

Please sign in to comment.