def create_template(path, confirm, yes): confirm = confirm or yes if not confirm: check_update_available() try: working_dir = os.getcwd() resources_dir = get_resources_dir() if str(path).lower().endswith("json"): template_source_path = os.path.join(resources_dir, "template-sceleton.json") else: template_source_path = os.path.join(resources_dir, "template-sceleton.yml") description = click.prompt( 'Stack description to be used in the template', type=str) FileGenerator(working_dir).render_file(template_source_path, path, {"description": description}) click.echo("Template created at {0}".format(path)) except CfnSphereException as e: LOGGER.error(e) sys.exit(1) except Exception as e: LOGGER.error("Failed with unexpected error") LOGGER.exception(e) LOGGER.info( "Please report at https://github.com/cfn-sphere/cfn-sphere/issues!" ) sys.exit(1)
def start_project(confirm, yes): confirm = confirm or yes if not confirm: check_update_available() try: region = click.prompt('AWS Region?', type=str, default="eu-west-1") subdir = click.prompt('Project dir? (leave empty to use current dir)', type=str, default=".") working_dir = os.getcwd() resources_dir = get_resources_dir() config_source_path = os.path.join(resources_dir, "stack_config.yml.jinja2") config_dest_path = os.path.join(subdir, "stacks.yml") template_source_path = os.path.join(resources_dir, "queue.yml") template_dest_path = os.path.join(subdir, "templates", "queue.yml") context = {"region": region, "template_url": "templates/queue.yml"} FileGenerator(working_dir).render_file(config_source_path, config_dest_path, context) FileGenerator(working_dir).render_file(template_source_path, template_dest_path, {}) click.echo( "I created a simple stack config ({0}) and a template ({1}).". format(config_dest_path, template_dest_path)) click.echo( "Modify it to match your requirements and run 'cf sync {0}' to create the stack(s)" .format(config_dest_path)) except CfnSphereException as e: LOGGER.error(e) sys.exit(1) except Exception as e: LOGGER.error("Failed with unexpected error") LOGGER.exception(e) LOGGER.info( "Please report at https://github.com/cfn-sphere/cfn-sphere/issues!" ) sys.exit(1)
def test_is_valid_json(self): result = FileGenerator._is_valid_json("""{"a":"b"}""") self.assertIsNone(result)
def test_is_valid_yaml_raises_exception_on_invalid_yaml(self): with self.assertRaises(CfnSphereException): FileGenerator._is_valid_yaml("""a: b: c""")
def test_is_valid_yaml(self): result = FileGenerator._is_valid_yaml("""a: b""") self.assertIsNone(result)
def test_is_valid_json_raises_exception_on_invalid_json(self): with self.assertRaises(CfnSphereException): FileGenerator._is_valid_json("""{"a":b}""")