implement actual_template_hash method
This commit is contained in:
parent
dfb8c82469
commit
0e6de0444e
@ -17,7 +17,7 @@ module Devops
|
|||||||
stack_template_attrs = {
|
stack_template_attrs = {
|
||||||
id: stack_template_id,
|
id: stack_template_id,
|
||||||
provider: provider,
|
provider: provider,
|
||||||
template_body: serialize(actual_template_hash(template_preset_hash, template_attrs))
|
template_body: serialize(actual_template_hash(template_attrs))
|
||||||
}
|
}
|
||||||
template_model = Model::StackTemplateFactory.create(provider, stack_template_attrs)
|
template_model = Model::StackTemplateFactory.create(provider, stack_template_attrs)
|
||||||
end
|
end
|
||||||
@ -36,8 +36,42 @@ module Devops
|
|||||||
unserialize(template_preset_body)
|
unserialize(template_preset_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def actual_template_hash(template_preset_hash, params)
|
def actual_template_hash(template_attrs)
|
||||||
|
actual = template_preset_body.dup
|
||||||
|
template_attrs.each do |key, value|
|
||||||
|
path = param_attrs_pathes_in_preset[key.to_sym]
|
||||||
|
next unless path
|
||||||
|
insert_value_at(actual, value, path)
|
||||||
|
end
|
||||||
|
actual
|
||||||
|
end
|
||||||
|
|
||||||
|
# returns hash with keys lists. Better to show an example:
|
||||||
|
# Imagine tha t template is the following:
|
||||||
|
# {
|
||||||
|
# template: {
|
||||||
|
# users_count: %users_count%
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# So param_attrs_pathes_in_preset will be
|
||||||
|
# {users_count: [:template, :users_count]}
|
||||||
|
def param_attrs_pathes_in_preset
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
# given hash = {t: {a: nil}}, value = 1, path = [:t, :a] returns
|
||||||
|
# {t: {a: 1}}
|
||||||
|
def insert_value_at(hash, value, path)
|
||||||
|
current = hash
|
||||||
|
path.each_with_index do |key, i|
|
||||||
|
if i == path.size - 1
|
||||||
|
current[key] = value
|
||||||
|
else
|
||||||
|
current = current[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
# some templates may be YAML files
|
# some templates may be YAML files
|
||||||
|
|||||||
@ -20,7 +20,7 @@ module Devops
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_stack_template
|
def self.build_stack_template
|
||||||
lamda {
|
lamda {
|
||||||
# check_privileges("stack_template_presets", "r")
|
# check_privileges("stack_template_presets", "r")
|
||||||
check_privileges('stack_template', 'w')
|
check_privileges('stack_template', 'w')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user