in src/handlers/push_handler.py [0:0]
def push_chronicle_by_tenant(self, event: BaseModel, tenant_name: str):
tenant = self._modular_client.tenant_service().get(tenant_name)
tenant = modular_helpers.assert_tenant_valid(tenant, event.customer)
chronicle, configuration = next(
self._integration_service.get_chronicle_adapters(tenant),
(None, None),
)
if not chronicle or not configuration:
raise (
ResponseFactory(HTTPStatus.BAD_REQUEST)
.message(
f'Tenant {tenant.name} does not have linked chronicle '
f'configuration'
)
.exc()
)
creds = self._mcs.get_by_application(
chronicle.credentials_application_id, tenant
)
if not creds:
raise (
ResponseFactory(HTTPStatus.BAD_REQUEST)
.message('Cannot resolve credentials for Chronicle')
.exc()
)
client = ChronicleV2Client(
url=chronicle.endpoint,
credentials=creds.GOOGLE_APPLICATION_CREDENTIALS,
customer_id=chronicle.instance_customer_id,
)
collection = self._rs.tenant_latest_collection(tenant)
collection.fetch_all()
collection.fetch_meta()
metadata = self._ls.get_customer_metadata(tenant.customer_name)
code, message = self._push_chronicle(
client=client,
configuration=configuration,
tenant=tenant,
collection=collection,
metadata=metadata,
)
match code:
case HTTPStatus.OK:
return build_response(
self.get_chronicle_dto(tenant, chronicle)
)
case _:
return build_response(
content=message, code=HTTPStatus.SERVICE_UNAVAILABLE
)