Skip to content

Commit 3f7ff60

Browse files
authored
Merge pull request #2 from unity-sds/413-submit-ogc
Add SRL Initiator for EDRGen and New OGC Action Type
2 parents 2f04b33 + 4a9af03 commit 3f7ff60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+254
-131
lines changed

README.md

Lines changed: 121 additions & 55 deletions
Large diffs are not rendered by default.

src/unity_initiator/actions/submit_dag_by_id.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def execute(self):
3434
},
3535
"note": "",
3636
}
37-
response = httpx.post(url, auth=auth, headers=headers, json=body)
37+
response = httpx.post(
38+
url, auth=auth, headers=headers, json=body, verify=False
39+
) # nosec
3840
if response.status_code in (200, 201):
3941
success = True
4042
resp = response.json()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import httpx
2+
3+
from ..utils.logger import logger
4+
from .base import Action
5+
6+
__all__ = ["SubmitOgcProcessExecution"]
7+
8+
9+
class SubmitOgcProcessExecution(Action):
10+
def __init__(self, payload, payload_info, params):
11+
super().__init__(payload, payload_info, params)
12+
logger.info("instantiated %s", __class__.__name__)
13+
14+
def execute(self):
15+
logger.debug("executing execute in %s", __class__.__name__)
16+
url = f"{self._params['ogc_processes_base_api_endpoint']}/processes/{self._params['process_id']}/execution"
17+
logger.info("url: %s", url)
18+
headers = {"Content-Type": "application/json", "Accept": "application/json"}
19+
# body = {
20+
# "inputs": self._params["execution_inputs"],
21+
# "outputs": self._params["execution_outputs"],
22+
# "subscriber": self._params["execution_subscriber"],
23+
# }
24+
body = {
25+
"inputs": {
26+
"payload": self._payload,
27+
"payload_info": self._payload_info,
28+
"on_success": self._params["on_success"],
29+
},
30+
"outputs": None,
31+
"subscriber": None,
32+
}
33+
response = httpx.post(url, headers=headers, json=body, verify=False) # nosec
34+
if response.status_code in (200, 201):
35+
success = True
36+
resp = response.json()
37+
logger.info(
38+
"Successfully triggered the execution of the OGC Process %s: %s",
39+
self._params["process_id"],
40+
resp,
41+
)
42+
else:
43+
success = False
44+
resp = response.text
45+
logger.info(
46+
"Failed to trigger the execution of the OGC Process %s: %s",
47+
self._params["process_id"],
48+
resp,
49+
)
50+
return {"success": success, "response": resp}

src/unity_initiator/resources/routers_schema.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ initiator_config:
2525
# Configuration for matching payload (e.g. url) against a set of compiled regular expressions
2626
# and mapping any matches to a set of evaluators.
2727
regex_config:
28-
regexes: list(compiled_regex(), required=True, min=1)
28+
regexes: list(str, required=True, min=1)
2929
evaluators: list(include("evaluator_config"), required=True, min=1)
3030

3131
# Configuration of actions that submit to evaluators.
@@ -36,7 +36,7 @@ evaluator_config:
3636
# Currently only 2 types of actions are supported:
3737
# 1. submit payload to an SNS topic
3838
# 2. submit payload to an airflow DAG
39-
action_config: any(include("submit_dag_by_id_action"), include("submit_to_sns_topic_action"))
39+
action_config: any(include("submit_dag_by_id_action"), include("submit_to_sns_topic_action"), include("submit_ogc_process_execution_action"))
4040

4141
# Configuration for submitting a payload to an airflow DAG.
4242
submit_dag_by_id_action:
@@ -58,6 +58,17 @@ submit_to_sns_topic_action:
5858
topic_arn: str(required=False)
5959
on_success: include("on_success_actions", required=False)
6060

61+
# Configuration for submitting a OGC process execution.
62+
submit_ogc_process_execution_action:
63+
name: str(equals="submit_ogc_process_execution")
64+
params:
65+
process_id: str()
66+
ogc_processes_base_api_endpoint: str(required=False)
67+
execution_inputs: map(required=False)
68+
execution_outputs: map(required=False)
69+
execution_subscriber: map(required=False)
70+
on_success: include("on_success_actions", required=False)
71+
6172
# Configuration to pass onto the evaluator to use when evaluation is a success.
6273
on_success_actions:
63-
actions: list(include("action_config"), required=True, min=1, max=1)
74+
actions: list(include("action_config"), required=True, min=1, max=1)

src/unity_initiator/router.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import json
3+
import re
34

45
from .evaluator import Evaluator
56
from .utils.conf_utils import YamlConf, YamlConfEncoder
@@ -14,6 +15,15 @@ class Router:
1415
def __init__(self, config_file):
1516
self._config_file = config_file
1617
self._config = YamlConf(self._config_file)
18+
self._compile_regexes()
19+
20+
def _compile_regexes(self):
21+
"""Compile all regex strings in the configuration."""
22+
for url_cfg in (
23+
self._config.get("initiator_config").get("payload_type").get("url", [])
24+
):
25+
if "regexes" in url_cfg:
26+
url_cfg["regexes"] = [re.compile(regex) for regex in url_cfg["regexes"]]
1727

1828
def get_evaluators_by_url(self, url):
1929
found_match = False

terraform-unity/evaluators/sns_sqs_lambda/README.md renamed to terraform-unity/evaluators/sns-sqs-lambda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
| Name | Version |
77
|------|---------|
8-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.4.6 |
8+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.8.2 |
99
| <a name="requirement_archive"></a> [archive](#requirement\_archive) | >=2.4.2 |
1010
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >=5.50.0 |
1111
| <a name="requirement_local"></a> [local](#requirement\_local) | >=2.5.1 |

0 commit comments

Comments
 (0)