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 path option to list_resources cli command so that specific fil… #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions servicecatalog_puppet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ def run(what, tail):


@cli.command()
def list_resources():
core.list_resources()
@click.option('--path','-p', default=False, multiple=True)

def list_resources(path):
core.list_resources(path)


@cli.command()
Expand Down
69 changes: 38 additions & 31 deletions servicecatalog_puppet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,46 +722,53 @@ def run(what, tail):
)


def list_resources():
def list_resources(path):
click.echo("# Framework resources")

click.echo("## SSM Parameters used")
click.echo(f"- {constants.CONFIG_PARAM_NAME}")
click.echo(f"- {constants.CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN}")

for file in Path(__file__).parent.resolve().glob("*.template.yaml"):
if 'empty.template.yaml' == file.name:
continue
template_contents = Template(open(file, 'r').read()).render()
template = cfn_tools.load_yaml(template_contents)
click.echo(f"## Resources for stack: {file.name.split('.')[0]}")
table_data = [
['Logical Name', 'Resource Type', 'Name', ],
]
table = terminaltables.AsciiTable(table_data)
for logical_name, resource in template.get('Resources').items():
resource_type = resource.get('Type')
name = '-'
type_to_name = {
'AWS::IAM::Role': 'RoleName',
'AWS::SSM::Parameter': 'Name',
'AWS::S3::Bucket': 'BucketName',
'AWS::CodePipeline::Pipeline': 'Name',
'AWS::CodeBuild::Project': 'Name',
'AWS::CodeCommit::Repository': 'RepositoryName',
'AWS::SNS::Topic': 'TopicName',
'AWS::SQS::Queue': 'QueueName',
}
puppet_file = Path(__file__).parent.resolve().glob("*.template.yaml")
for file in puppet_file:
list_resources_table(file)

if path:
for p in path:
product_file = Path().parent.resolve().glob(p)
for f in product_file:
list_resources_table(f)

def list_resources_table(file):
template_contents = Template(open(file, 'r').read()).render()
template = cfn_tools.load_yaml(template_contents)
click.echo(f"## Resources for stack: {file.name.split('.')[0]}")
table_data = [
['Logical Name', 'Resource Type', 'Name', ],
]
table = terminaltables.AsciiTable(table_data)
for logical_name, resource in template.get('Resources').items():
resource_type = resource.get('Type')
name = '-'
type_to_name = {
'AWS::IAM::Role': 'RoleName',
'AWS::SSM::Parameter': 'Name',
'AWS::S3::Bucket': 'BucketName',
'AWS::CodePipeline::Pipeline': 'Name',
'AWS::CodeBuild::Project': 'Name',
'AWS::CodeCommit::Repository': 'RepositoryName',
'AWS::SNS::Topic': 'TopicName',
'AWS::SQS::Queue': 'QueueName',
}

if type_to_name.get(resource_type) is not None:
name = resource.get('Properties', {}).get(type_to_name.get(resource_type), 'Not Specified')
if not isinstance(name, str):
name = cfn_tools.dump_yaml(name)
if type_to_name.get(resource_type) is not None:
name = resource.get('Properties', {}).get(type_to_name.get(resource_type), 'Not Specified')
if not isinstance(name, str):
name = cfn_tools.dump_yaml(name)

table_data.append([logical_name, resource_type, name])
table_data.append([logical_name, resource_type, name])

click.echo(table.table)
click.echo(f"n.b. AWS::StackName evaluates to {constants.BOOTSTRAP_STACK_NAME}")
click.echo(table.table)


def import_product_set(f, name, portfolio_name):
Expand Down