Skip to content

Commit

Permalink
Merge pull request #621 from dgraeber/fix/modulemanifestschema
Browse files Browse the repository at this point in the history
adding support for module manifest schema
  • Loading branch information
dgraeber authored Jun 13, 2024
2 parents cf073c0 + da1b6f7 commit cf1a8f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions seedfarmer/cli_groups/_list_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
11 changes: 9 additions & 2 deletions seedfarmer/mgmt/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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]")
18 changes: 16 additions & 2 deletions test/unit-test/test_mgmt_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

0 comments on commit cf1a8f5

Please sign in to comment.