Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for module manifest schema #621

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we maybe want another unit test here for type="module"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep....can do

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")