本文整理汇总了Python中cfn_sphere.file_loader.FileLoader.get_yaml_or_json_file方法的典型用法代码示例。如果您正苦于以下问题:Python FileLoader.get_yaml_or_json_file方法的具体用法?Python FileLoader.get_yaml_or_json_file怎么用?Python FileLoader.get_yaml_or_json_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfn_sphere.file_loader.FileLoader
的用法示例。
在下文中一共展示了FileLoader.get_yaml_or_json_file方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_file_value
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def handle_file_value(value, working_dir):
components = value.split('|', 3)
if len(components) == 3:
url = components[2]
return FileLoader.get_file(url, working_dir)
elif len(components) == 4:
url = components[2]
pattern = components[3]
file_content = FileLoader.get_yaml_or_json_file(url, working_dir)
try:
return jmespath.search(pattern, file_content)
except JMESPathError as e:
raise CfnSphereException(e)
else:
raise CfnSphereException("Invalid format for |File| macro, it must be |File|<path>[|<pattern>]")
示例2: create_or_update_stacks
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def create_or_update_stacks(self):
existing_stacks = self.cfn.get_stack_names()
desired_stacks = self.config.stacks
stack_processing_order = DependencyResolver().get_stack_order(desired_stacks)
if len(stack_processing_order) > 1:
self.logger.info(
"Will process stacks in the following order: {0}".format(", ".join(stack_processing_order)))
for stack_name in stack_processing_order:
stack_config = self.config.stacks.get(stack_name)
template = FileLoader.get_cloudformation_template(stack_config.template_url,stack_config.working_dir)
transformed_template = CloudFormationTemplateTransformer.transform_template(template)
if stack_config.stack_policy_url:
self.logger.info("Using stack policy from {0}".format(stack_config.stack_policy_url))
stack_policy = FileLoader.get_yaml_or_json_file(stack_config.stack_policy_url, stack_config.working_dir)
else:
stack_policy = None
parameters = self.parameter_resolver.resolve_parameter_values(stack_name, stack_config)
merged_parameters = self.parameter_resolver.update_parameters_with_cli_parameters(
parameters=parameters,
cli_parameters=self.cli_parameters,
stack_name=stack_name)
self.logger.debug("Parameters after merging with cli options: {0}".format(merged_parameters))
stack = CloudFormationStack(template=transformed_template,
parameters=merged_parameters,
tags=stack_config.tags,
name=stack_name,
region=self.config.region,
timeout=stack_config.timeout,
service_role=stack_config.service_role,
stack_policy=stack_policy)
if stack_name in existing_stacks:
self.cfn.validate_stack_is_ready_for_action(stack)
self.cfn.update_stack(stack)
else:
self.cfn.create_stack(stack)
CustomResourceHandler.process_post_resources(stack)
示例3: create_or_update_stacks
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def create_or_update_stacks(self):
existing_stacks = self.cfn.get_stack_names()
desired_stacks = self.config.stacks
stack_processing_order = DependencyResolver().get_stack_order(desired_stacks)
if len(stack_processing_order) > 1:
self.logger.info(
"Will process stacks in the following order: {0}".format(", ".join(stack_processing_order))
)
for stack_name in stack_processing_order:
stack_config = self.config.stacks.get(stack_name)
if stack_config.stack_policy_url:
self.logger.info("Using stack policy from {0}".format(stack_config.stack_policy_url))
stack_policy = FileLoader.get_yaml_or_json_file(stack_config.stack_policy_url, stack_config.working_dir)
else:
stack_policy = None
template = TemplateHandler.get_template(stack_config.template_url, stack_config.working_dir)
parameters = self.parameter_resolver.resolve_parameter_values(stack_name, stack_config, self.cli_parameters)
stack = CloudFormationStack(
template=template,
parameters=parameters,
tags=stack_config.tags,
name=stack_name,
region=self.config.region,
timeout=stack_config.timeout,
service_role=stack_config.service_role,
stack_policy=stack_policy,
failure_action=stack_config.failure_action,
)
if stack_name in existing_stacks:
self.cfn.validate_stack_is_ready_for_action(stack)
self.cfn.update_stack(stack)
else:
self.cfn.create_stack(stack)
CustomResourceHandler.process_post_resources(stack)
示例4: test_get_yaml_or_json_file_raises_exception_on_json_error
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_raises_exception_on_json_error(self, _, json_mock):
json_mock.loads.side_effect = ValueError()
with self.assertRaises(CfnSphereException):
FileLoader.get_yaml_or_json_file('foo.json', 'baa')
示例5: test_get_yaml_or_json_file_raises_exception_on_yaml_error
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_raises_exception_on_yaml_error(self, _, yaml_mock):
yaml_mock.load.side_effect = ScannerError()
with self.assertRaises(CfnSphereException):
FileLoader.get_yaml_or_json_file('foo.yml', 'baa')
示例6: test_get_yaml_or_json_file_raises_exception_invalid_file_extension
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_raises_exception_invalid_file_extension(self, _):
with self.assertRaises(CfnSphereException):
FileLoader.get_yaml_or_json_file('foo.foo', 'baa')
示例7: test_get_yaml_or_json_file_parses_yaml_on_yml_suffix
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_parses_yaml_on_yml_suffix(self, get_file_mock, yaml_mock):
get_file_return_value = Mock()
get_file_mock.return_value = get_file_return_value
FileLoader.get_yaml_or_json_file('foo.yml', 'baa')
yaml_mock.load.assert_called_once_with(get_file_return_value)
示例8: test_get_yaml_or_json_file_accepts_yaml_template_with_getatt_constructor_tag
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_accepts_yaml_template_with_getatt_constructor_tag(self, get_file_mock):
get_file_mock.return_value = "myKey: !GetAtt myResource.attributeName"
result = FileLoader.get_yaml_or_json_file("my-template.yaml", None)
self.assertEqual({"myKey": {"Fn::GetAtt": ["myResource", "attributeName"]}}, result)
示例9: test_get_yaml_or_json_file_accepts_yaml_template_with_ref_constructor_tag
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_accepts_yaml_template_with_ref_constructor_tag(self, get_file_mock):
get_file_mock.return_value = "myKey: !Ref myResource"
result = FileLoader.get_yaml_or_json_file("my-template.yaml", None)
self.assertEqual({"myKey": {"Ref": "myResource"}}, result)
示例10: test_get_yaml_or_json_file_accepts_yaml_with_nested_constructor_tags
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_accepts_yaml_with_nested_constructor_tags(self, get_file_mock):
get_file_mock.return_value = "myKey: !Join [ b, [ !ref a, !ref b] ]"
result = FileLoader.get_yaml_or_json_file("my-template.yaml", None)
self.assertEqual({"myKey": {"Fn::Join": ["b", [{"Ref": "a"}, {"Ref": "b"}]]}}, result)
示例11: test_get_yaml_or_json_file_accepts_yaml_with_cfn_join_constructor_tag
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_yaml_or_json_file [as 别名]
def test_get_yaml_or_json_file_accepts_yaml_with_cfn_join_constructor_tag(self, get_file_mock):
get_file_mock.return_value = "myKey: !Join [ b, [ a, c] ]"
result = FileLoader.get_yaml_or_json_file("my-template.yaml", None)
self.assertEqual({"myKey": {"Fn::Join": ["b", ["a", "c"]]}}, result)