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..fbdd5c7e 100644 --- a/seedfarmer/cli_groups/_list_group.py +++ b/seedfarmer/cli_groups/_list_group.py @@ -779,8 +779,18 @@ 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", + 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: + 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..5614af0a 100644 --- a/seedfarmer/mgmt/build_info.py +++ b/seedfarmer/mgmt/build_info.py @@ -18,7 +18,9 @@ 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 _logger: logging.Logger = logging.getLogger(__name__) @@ -40,5 +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() -> Dict[str, Any]: - return DeploymentManifest.model_json_schema() +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: + 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 a98beb9a..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(): - bi.get_manifest_schema() +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")