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

Sync with template repo #5

Merged
merged 20 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion app/actions/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import importlib
import inspect
from typing import Optional

from pydantic import BaseModel
from app.services.utils import UISchemaModelMixin


class ActionConfiguration(BaseModel):
class ActionConfiguration(UISchemaModelMixin, BaseModel):
pass


Expand Down
94 changes: 68 additions & 26 deletions app/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import asyncio
import datetime
import json

import pydantic
import pytest
from unittest.mock import MagicMock
from app import settings
from gcloud.aio import pubsub
from gundi_core.schemas.v2 import Integration, IntegrationActionConfiguration, IntegrationActionSummary
from gundi_core.schemas.v2 import Integration
from gundi_core.events import (
SystemEventBaseModel,
IntegrationActionCustomLog,
CustomActivityLog,
IntegrationActionStarted,
Expand All @@ -28,9 +26,9 @@
CustomWebhookLog,
LogLevel
)

from app.actions import PullActionConfiguration
from app.webhooks import GenericJsonTransformConfig, GenericJsonPayload, WebhookPayload
from app.services.utils import GlobalUISchemaOptions, FieldWithUIOptions, UIOptions
from app.webhooks import GenericJsonTransformConfig, GenericJsonPayload, WebhookPayload, WebhookConfiguration


class AsyncMock(MagicMock):
Expand Down Expand Up @@ -107,9 +105,9 @@ def integration_v2():
'value': 'auth'}, 'data': {'token': 'testtoken2a97022f21732461ee103a08fac8a35'}}],
'additional': {},
'default_route': {'id': '5abf3845-7c9f-478a-bc0f-b24d87038c4b', 'name': 'Gundi X Provider - Default Route'},
'status': {'id': 'mockid-b16a-4dbd-ad32-197c58aeef59', 'is_healthy': True,
'details': 'Last observation has been delivered with success.',
'observation_delivered_24hrs': 50231, 'last_observation_delivered_at': '2023-03-31T11:20:00+0200'}}
'status': 'healthy',
'status_details': '',
}
)


Expand Down Expand Up @@ -139,6 +137,14 @@ def integration_v2_with_webhook():
"allowed_devices_list": {"title": "Allowed Devices List", "type": "array", "items": {}},
"deduplication_enabled": {"title": "Deduplication Enabled", "type": "boolean"}},
"required": ["allowed_devices_list", "deduplication_enabled"]
},
"ui_schema": {
"allowed_devices_list": {
"ui:widget": "select"
},
"deduplication_enabled": {
"ui:widget": "radio"
}
}
}
},
Expand All @@ -163,13 +169,8 @@ def integration_v2_with_webhook():
},
"additional": {},
"default_route": None,
"status": {
"id": "mockid-b16a-4dbd-ad32-197c58aeef59",
"is_healthy": True,
"details": "Last observation has been delivered with success.",
"observation_delivered_24hrs": 50231,
"last_observation_delivered_at": "2023-03-31T11:20:00+0200"
}
"status": "healthy",
"status_details": "",
}
)

Expand Down Expand Up @@ -218,6 +219,17 @@ def integration_v2_with_webhook_generic():
"description": "Output type for the transformed data: 'obv' or 'event'"
}
}
},
"ui_schema": {
"jq_filter": {
"ui:widget": "textarea"
},
"json_schema": {
"ui:widget": "textarea"
},
"output_type": {
"ui:widget": "text"
}
}
}
},
Expand Down Expand Up @@ -455,13 +467,8 @@ def integration_v2_with_webhook_generic():
},
"additional": {},
"default_route": None,
"status": {
"id": "mockid-b16a-4dbd-ad32-197c58aeef59",
"is_healthy": True,
"details": "Last observation has been delivered with success.",
"observation_delivered_24hrs": 50231,
"last_observation_delivered_at": "2023-03-31T11:20:00+0200"
}
"status": "healthy",
"status_details": "",
}
)

Expand Down Expand Up @@ -898,7 +905,30 @@ def mock_publish_event(gcp_pubsub_publish_response):


class MockPullActionConfiguration(PullActionConfiguration):
lookback_days: int = 10
lookback_days: int = FieldWithUIOptions(
30,
le=30,
ge=1,
title="Data lookback days",
description="Number of days to look back for data.",
ui_options=UIOptions(
widget="range",
)
)
force_fetch: bool = FieldWithUIOptions(
False,
title="Force fetch",
description="Force fetch even if in a quiet period.",
ui_options=UIOptions(
widget="select",
)
)
ui_global_options = GlobalUISchemaOptions(
order=[
"lookback_days",
"force_fetch",
],
)


@pytest.fixture
Expand Down Expand Up @@ -1172,9 +1202,21 @@ class MockWebhookPayloadModel(WebhookPayload):
lon: float


class MockWebhookConfigModel(pydantic.BaseModel):
allowed_devices_list: list
deduplication_enabled: bool
class MockWebhookConfigModel(WebhookConfiguration):
allowed_devices_list: list = FieldWithUIOptions(
...,
title="Allowed Devices List",
ui_options=UIOptions(
widget="list",
)
)
deduplication_enabled: bool = FieldWithUIOptions(
...,
title="Deduplication Enabled",
ui_options=UIOptions(
widget="radio",
)
)


@pytest.fixture
Expand Down
5 changes: 3 additions & 2 deletions app/services/self_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@


async def register_integration_in_gundi(gundi_client, type_slug=None, service_url=None):
#from ..webhooks.configurations import LiquidTechPayload
#print(GenericJsonTransformConfig.schema_json())
# Prepare the integration name and value
integration_type_slug = type_slug or INTEGRATION_TYPE_SLUG
if not integration_type_slug:
Expand All @@ -38,6 +36,7 @@ async def register_integration_in_gundi(gundi_client, type_slug=None, service_ur
_, config_model = handler
action_name = action_id.replace("_", " ").title()
action_schema = json.loads(config_model.schema_json())
action_ui_schema = config_model.ui_schema()
if issubclass(config_model, AuthActionConfiguration):
action_type = ActionTypeEnum.AUTHENTICATION.value
elif issubclass(config_model, PullActionConfiguration):
Expand All @@ -53,6 +52,7 @@ async def register_integration_in_gundi(gundi_client, type_slug=None, service_ur
"value": action_id,
"description": f"{integration_type_name} {action_name} action",
"schema": action_schema,
"ui_schema": action_ui_schema,
"is_periodic_action": True if issubclass(config_model, PullActionConfiguration) else False,
}
)
Expand All @@ -70,6 +70,7 @@ async def register_integration_in_gundi(gundi_client, type_slug=None, service_ur
"value": f"{integration_type_slug}_webhook",
"description": f"Webhook Integration with {integration_type_name}",
"schema": json.loads(config_model.schema_json()),
"ui_schema": config_model.ui_schema(),
}

logger.info(f"Registering '{integration_type_slug}' with actions: '{actions}'")
Expand Down
Loading