From bc54af467c25b7c100b9571b42c2ff11cf845abe Mon Sep 17 00:00:00 2001 From: Derek Graeber Date: Wed, 12 Jun 2024 11:20:39 -0400 Subject: [PATCH 1/3] adding support for module manifest schema --- CHANGELOG.md | 1 + seedfarmer/cli_groups/_list_group.py | 16 ++++++++++++++-- seedfarmer/mgmt/build_info.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3153a4cb..51ad72f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch ### New ### Changes +- adding support for module manifest schema generation ### Fixes diff --git a/seedfarmer/cli_groups/_list_group.py b/seedfarmer/cli_groups/_list_group.py index af349bf0..6cd26c22 100644 --- a/seedfarmer/cli_groups/_list_group.py +++ b/seedfarmer/cli_groups/_list_group.py @@ -779,8 +779,20 @@ def list_build_env_params( @list.command( name="schema", help="""Generate the schema that SeedFarmer uses for manifest objects. + Either the deployment manifest or module manifest schema + can be requested. This will return a formatted string of the schema that can be piped to a file. """, ) -def list_manifest_schema() -> None: - print(json.dumps(bi.get_manifest_schema(), indent=2)) +@click.option( + "--type", + "-t", + help="Either 'deployment' or 'module' can be used, default is `deployment`", + required=False, + default="deployment", +) +def list_manifest_schema(type: str) -> None: + if type not in ["deployment", "module"]: + print_bolded(message="Only 'deployment' or 'module' can be passed in", color="yellow") + return + print(json.dumps(bi.get_manifest_schema(type=type), indent=2)) diff --git a/seedfarmer/mgmt/build_info.py b/seedfarmer/mgmt/build_info.py index 27ebee48..22d33f7e 100644 --- a/seedfarmer/mgmt/build_info.py +++ b/seedfarmer/mgmt/build_info.py @@ -19,6 +19,7 @@ from boto3 import Session from seedfarmer.models.manifests._deployment_manifest import DeploymentManifest +from seedfarmer.models.manifests._module_manifest import ModuleManifest from seedfarmer.services import _codebuild as codebuild _logger: logging.Logger = logging.getLogger(__name__) @@ -40,5 +41,10 @@ def get_build_env_params(build_ids: List[str], session: Optional[Session] = None return dict(ChainMap(*list_of_envs)) if list_of_envs else None -def get_manifest_schema() -> Dict[str, Any]: - return DeploymentManifest.model_json_schema() +def get_manifest_schema(type: str) -> Optional[Dict[str, Any]]: + if "deployment" == type.lower(): + return DeploymentManifest.model_json_schema() + elif "module" == type.lower(): + return ModuleManifest.model_json_schema() + else: + return None From 644606de23ffa98f936196d2f2c954f7919df5aa Mon Sep 17 00:00:00 2001 From: Derek Graeber Date: Wed, 12 Jun 2024 11:25:08 -0400 Subject: [PATCH 2/3] updating tests --- test/unit-test/test_mgmt_build_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit-test/test_mgmt_build_info.py b/test/unit-test/test_mgmt_build_info.py index a98beb9a..730771b1 100644 --- a/test/unit-test/test_mgmt_build_info.py +++ b/test/unit-test/test_mgmt_build_info.py @@ -67,4 +67,4 @@ def test_get_build_params(mocker): @pytest.mark.mgmt @pytest.mark.mgmt_build_info def test_validate_group_parameters(): - bi.get_manifest_schema() + bi.get_manifest_schema(type="deployment") From da1b6f713f12a6df96bc22c8fba1d648b502fc32 Mon Sep 17 00:00:00 2001 From: Derek Graeber Date: Thu, 13 Jun 2024 13:09:28 -0400 Subject: [PATCH 3/3] refactoring --- seedfarmer/cli_groups/_list_group.py | 4 +--- seedfarmer/mgmt/build_info.py | 5 +++-- test/unit-test/test_mgmt_build_info.py | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/seedfarmer/cli_groups/_list_group.py b/seedfarmer/cli_groups/_list_group.py index 6cd26c22..fbdd5c7e 100644 --- a/seedfarmer/cli_groups/_list_group.py +++ b/seedfarmer/cli_groups/_list_group.py @@ -787,12 +787,10 @@ def list_build_env_params( @click.option( "--type", "-t", + type=click.Choice(["deployment", "module"], case_sensitive=True), help="Either 'deployment' or 'module' can be used, default is `deployment`", required=False, default="deployment", ) def list_manifest_schema(type: str) -> None: - if type not in ["deployment", "module"]: - print_bolded(message="Only 'deployment' or 'module' can be passed in", color="yellow") - return print(json.dumps(bi.get_manifest_schema(type=type), indent=2)) diff --git a/seedfarmer/mgmt/build_info.py b/seedfarmer/mgmt/build_info.py index 22d33f7e..5614af0a 100644 --- a/seedfarmer/mgmt/build_info.py +++ b/seedfarmer/mgmt/build_info.py @@ -18,6 +18,7 @@ from boto3 import Session +import seedfarmer.errors from seedfarmer.models.manifests._deployment_manifest import DeploymentManifest from seedfarmer.models.manifests._module_manifest import ModuleManifest from seedfarmer.services import _codebuild as codebuild @@ -41,10 +42,10 @@ def get_build_env_params(build_ids: List[str], session: Optional[Session] = None return dict(ChainMap(*list_of_envs)) if list_of_envs else None -def get_manifest_schema(type: str) -> Optional[Dict[str, Any]]: +def get_manifest_schema(type: str) -> Dict[str, Any]: if "deployment" == type.lower(): return DeploymentManifest.model_json_schema() elif "module" == type.lower(): return ModuleManifest.model_json_schema() else: - return None + raise seedfarmer.errors.SeedFarmerException("Schema type selection not in [deployment, module]") diff --git a/test/unit-test/test_mgmt_build_info.py b/test/unit-test/test_mgmt_build_info.py index 730771b1..346d82f4 100644 --- a/test/unit-test/test_mgmt_build_info.py +++ b/test/unit-test/test_mgmt_build_info.py @@ -19,6 +19,7 @@ import pytest from moto import mock_aws +import seedfarmer.errors import seedfarmer.mgmt.build_info as bi from seedfarmer.services._service_utils import boto3_client from seedfarmer.services.session_manager import SessionManager @@ -66,5 +67,18 @@ def test_get_build_params(mocker): @pytest.mark.mgmt @pytest.mark.mgmt_build_info -def test_validate_group_parameters(): +def test_get_deployment_schema(): bi.get_manifest_schema(type="deployment") + + +@pytest.mark.mgmt +@pytest.mark.mgmt_build_info +def test_get_module_schema(): + bi.get_manifest_schema(type="module") + + +@pytest.mark.mgmt +@pytest.mark.mgmt_build_info +def test_get_module_schema_error(): + with pytest.raises(seedfarmer.errors.SeedFarmerException): + bi.get_manifest_schema(type="somethingcrazy")