Skip to content

Commit

Permalink
Add work on adding subcomponent validation to integrations
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
  • Loading branch information
Swiddis committed Apr 13, 2023
1 parent 0f7a629 commit 1a178f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions scripts/integrations-cli/integrations_cli/helpers/validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import jsonschema
from returns.result import Failure, Result, safe
from returns.pipeline import is_successful
import os

from .constants import SCHEMAS

Expand All @@ -15,9 +17,20 @@ def validate_instance(instance: dict, schema: dict) -> dict:
return instance


def validate_config(config: dict) -> Result[dict, Exception]:
def validate_config(config: dict, name: str) -> Result[dict, Exception]:
try:
return validate_instance(config, SCHEMAS["integration.schema"])
result = validate_instance(config, SCHEMAS["integration.schema"])
if not is_successful(result):
return result
# TODO assumes component is named same thing as mapping
# This is not true for e.g. logs
# Need to load catalog to see what the expected name is

# for component in config["components"]:
# path = os.path.join(f"integrations/{name}/schema", f"{component}.mapping")
# if not os.path.exists(path):
# return Failure(FileNotFoundError(f"Component `{component}` is absent from schema"))
return result
except KeyError as err:
return Failure(err)

Expand Down
6 changes: 3 additions & 3 deletions scripts/integrations-cli/integrations_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def create(name: str):
click.echo(colored(f"Integration created at '{integration_path}'", "green"))


def validate_component(path: str, validator) -> Result[dict, Exception]:
def validate_component(path: str, name: str, validator) -> Result[dict, Exception]:
with open(path, "r", encoding="utf-8") as item_data:
loaded = json.load(item_data)
result = validator(loaded)
result = validator(loaded, name)
if not is_successful(result):
msg = str(result.failure)
msg = ("> " + msg).replace("\n", "\n> ")
Expand All @@ -109,7 +109,7 @@ def full_integration_is_valid(name: str) -> bool:
encountered_errors = False
for item, validator in integration_parts.items():
item_path = os.path.join(integration_path, item)
if not is_successful(validate_component(item_path, validator)):
if not is_successful(validate_component(item_path, name, validator)):
encountered_errors = True
return not encountered_errors

Expand Down

0 comments on commit 1a178f3

Please sign in to comment.