Skip to content

Commit

Permalink
Merge branch 'main' into tokenauth-2fa-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dekkers committed Jul 22, 2024
2 parents 0d9595f + c554126 commit c769fc0
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions rocky/rocky/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def observed_at(self) -> datetime:

return ret
except ValueError:
messages.error(self.request, _("Can not parse date, falling back to show current date."))
messages.error(
self.request,
_("Can not parse date, falling back to show current date."),
)
return datetime.now(timezone.utc)


Expand All @@ -97,33 +100,61 @@ def get_origins(
reference: Reference,
organization: Organization,
) -> tuple[list[OriginData], list[OriginData], list[OriginData]]:
declarations: list[OriginData] = []
observations: list[OriginData] = []
inferences: list[OriginData] = []
results = declarations, observations, inferences

try:
origins = self.octopoes_api_connector.list_origins(self.observed_at, result=reference)
origin_data = [OriginData(origin=origin) for origin in origins]
except Exception as e:
logger.error(
"Could not load origins for OOI: %s from octopoes, error: %s",
reference,
e,
)
return results

for origin in origin_data:
if origin.origin.origin_type != OriginType.OBSERVATION or not origin.origin.task_id:
continue
try:
bytes_client = get_bytes_client(organization.code)
bytes_client.login()
except HTTPError as e:
logger.error(e)
return results

try:
client = get_bytes_client(organization.code)
client.login()
katalogus = get_katalogus(organization.code)

normalizer_data = client.get_normalizer_meta(origin.origin.task_id)
boefje_id = normalizer_data["raw_data"]["boefje_meta"]["boefje"]["id"]
origin.normalizer = normalizer_data
origin.boefje = get_katalogus(organization.code).get_plugin(boefje_id)
for origin in origins:
origin = OriginData(origin=origin)
if origin.origin.origin_type != OriginType.OBSERVATION or not origin.origin.task_id:
if origin.origin.origin_type == OriginType.DECLARATION:
declarations.append(origin)
elif origin.origin.origin_type == OriginType.INFERENCE:
inferences.append(origin)
continue

try:
normalizer_data = bytes_client.get_normalizer_meta(origin.origin.task_id)
except HTTPError as e:
logger.error(
"Could not load Normalizer meta for task_id: %s, error: %s",
origin.origin.task_id,
e,
)
else:
boefje_id = normalizer_data["raw_data"]["boefje_meta"]["boefje"]["id"]
origin.normalizer = normalizer_data
try:
origin.boefje = katalogus.get_plugin(boefje_id)
except HTTPError as e:
logger.error(e)
logger.error(
"Could not load boefje: %s from katalogus, error: %s",
boefje_id,
e,
)
observations.append(origin)

return (
[origin for origin in origin_data if origin.origin.origin_type == OriginType.DECLARATION],
[origin for origin in origin_data if origin.origin.origin_type == OriginType.OBSERVATION],
[origin for origin in origin_data if origin.origin.origin_type == OriginType.INFERENCE],
)
except Exception as e:
logger.error(e)
return [], [], []
return results

def handle_connector_exception(self, exception: Exception):
if isinstance(exception, ObjectNotFoundException):
Expand Down

0 comments on commit c769fc0

Please sign in to comment.