Skip to content

Commit

Permalink
adding more warnings to the validate command
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnfaherty committed Sep 6, 2022
1 parent 221fa3b commit f22538b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
venv
output.svg
.idea
*.iml
/ServiceCatalogPuppet/
Expand Down
11 changes: 4 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.189.0"
version = "0.190.0"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down Expand Up @@ -55,3 +55,4 @@ jmespath = "^0.10.0"
deepdiff = "^5.3.0"
deepmerge = "^0.2.1"
yamale = "^3.0.8"
colorama = "^0.4.5"
43 changes: 33 additions & 10 deletions servicecatalog_puppet/commands/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from servicecatalog_puppet import asset_helpers
from servicecatalog_puppet import config
from servicecatalog_puppet import constants
from servicecatalog_puppet import print_utils
from servicecatalog_puppet import manifest_utils
from servicecatalog_puppet import yaml_utils

Expand Down Expand Up @@ -222,31 +223,53 @@ def validate(f):
for collection_type in constants.ALL_SECTION_NAMES:
collection_to_check = manifest.get(collection_type, {})
for collection_name, collection_item in collection_to_check.items():
#
# Check the tags in deploy_to that are not defined
#
for deploy_to in collection_item.get("deploy_to", {}).get("tags", []):
tag_to_check = deploy_to.get("tag")
if tags_defined_by_accounts.get(tag_to_check) is None:
print(
f"{collection_type}.{collection_name} uses tag {tag_to_check} in deploy_to that does not exist"
print_utils.warn(
f"{collection_type}.{collection_name} uses tag {tag_to_check} in deploy_to that does not exist",
)

#
# Check the depends_on where the dependency is not present
#
for depends_on in collection_item.get("depends_on", []):
if isinstance(depends_on, str):
if manifest.get(constants.LAUNCHES).get(depends_on) is None:
print(
f"{collection_type}.{collection_name} uses {depends_on} in depends_on that does not exist"
print_utils.warn(
f"{collection_type}.{collection_name} uses {depends_on} in depends_on that does not exist",
)
else:
tt = constants.SECTION_SINGULAR_TO_PLURAL.get(
depends_on.get("type", constants.LAUNCH)
)
dd = depends_on.get("name")
if manifest.get(tt).get(dd) is None:
print(
f"{collection_type}.{collection_name} uses {depends_on} in depends_on that does not exist"
)

click.echo("Finished validating: {}".format(f.name))
click.echo("Finished validating: OK")
print_utils.warn(f"{collection_type}.{collection_name} uses {depends_on} in depends_on that does not exist",)

#
# Check depends_on is present when parameters names match outputs defined elsewhere
#
for parameter_name, parameter_details in collection_item.get("parameters", {}).items():
if parameter_details.get("ssm"):
output_name = parameter_details.get("ssm").get("name")
for needle_section_name in constants.ALL_SECTION_NAMES_THAT_GENERATE_OUTPUTS:
for needle_action_name, needle_action_details in manifest.get(needle_section_name, {}).items():
for needle_output in needle_action_details.get("outputs", {}).get("ssm", []):
if output_name == needle_output.get("param_name"):
found = False
for dependency in collection_item.get("depends_on", []):
plural = constants.SECTION_SINGULAR_TO_PLURAL.get(dependency.get("type", constants.LAUNCH))
if dependency.get("name") == needle_action_name and plural == needle_section_name:
found = True
if not found:
print_utils.error(f"{output_name} is used in {collection_type}.{collection_name} from {needle_section_name}.{needle_action_name} but is not in depends_on")

print_utils.echo("Finished validating: {}".format(f.name))
print_utils.echo("Finished validating: OK")


def import_product_set(f, name, portfolio_name):
Expand Down
6 changes: 6 additions & 0 deletions servicecatalog_puppet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
SIMULATE_POLICIES,
TAG_POLICIES,
]
ALL_SECTION_NAMES_THAT_GENERATE_OUTPUTS = [
LAUNCHES,
STACKS,
APPS,
WORKSPACES,
]

ALL_SPOKE_EXECUTABLE_SECTION_NAMES = [
LAUNCHES,
Expand Down
25 changes: 25 additions & 0 deletions servicecatalog_puppet/print_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import click


def echo(message):
click.secho(
message,
)


def warn(message):
click.secho(
message,
err=True,
fg="yellow",
)


def error(message):
click.secho(
message,
err=True,
fg="red",
)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'boto3==1.20.5',
'cfn-flip==1.2.3',
'click==7.0',
'colorama>=0.4.5,<0.5.0',
'colorclass==2.2.0',
'deepdiff>=5.3.0,<6.0.0',
'deepmerge>=0.2.1,<0.3.0',
Expand All @@ -61,7 +62,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.189.0',
'version': '0.190.0',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit f22538b

Please sign in to comment.