Add support for yaml format policy files
This patch adds a 'file_format' field to the policies definition to allow overriding the default file format which is currently json. Change-Id: Iec610053a9250cb78c2a17bfc2c197bf55d9df86 Related-Bug: #1885602
This commit is contained in:
parent
8959ad8dc3
commit
4622709879
@ -28,13 +28,19 @@
|
||||
# (optional) Group for the policy file
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*file_format*]
|
||||
# (optional) Format for file contents. Valid values
|
||||
# are 'json' or 'yaml'.
|
||||
# Defaults to 'json'.
|
||||
#
|
||||
define openstacklib::policy::base (
|
||||
$file_path,
|
||||
$key,
|
||||
$value = '',
|
||||
$file_mode = '0640',
|
||||
$file_user = undef,
|
||||
$file_group = undef,
|
||||
$value = '',
|
||||
$file_mode = '0640',
|
||||
$file_user = undef,
|
||||
$file_group = undef,
|
||||
$file_format = 'json',
|
||||
) {
|
||||
|
||||
ensure_resource('file', $file_path, {
|
||||
@ -45,9 +51,22 @@ define openstacklib::policy::base (
|
||||
content => '{}'
|
||||
})
|
||||
|
||||
case $file_format {
|
||||
'json': {
|
||||
$file_lens = 'Json.lns'
|
||||
}
|
||||
'yaml': {
|
||||
$file_lens = 'Yaml.lns'
|
||||
}
|
||||
default: {
|
||||
fail("${file_format} is an unsupported policy file format. Choose 'json' or 'yaml'.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Add entry if it doesn't exists
|
||||
augeas { "${file_path}-${key}-${value}-add":
|
||||
lens => 'Json.lns',
|
||||
lens => $file_lens,
|
||||
incl => $file_path,
|
||||
changes => [
|
||||
"set dict/entry[last()+1] \"${key}\"",
|
||||
@ -58,7 +77,7 @@ define openstacklib::policy::base (
|
||||
|
||||
# Requires that the entry is added before this call or it will fail.
|
||||
augeas { "${file_path}-${key}-${value}" :
|
||||
lens => 'Json.lns',
|
||||
lens => $file_lens,
|
||||
incl => $file_path,
|
||||
changes => "set dict/entry[*][.=\"${key}\"]/string \"${value}\"",
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Oslo policy is moving towards yaml as a policy file format and is
|
||||
deprecating json. Policy definitons now may contain a 'file_format'
|
||||
field to specify 'yaml' or 'json' as a file format.
|
@ -21,6 +21,25 @@ describe 'openstacklib::policy' do
|
||||
:value => 'foo:bar'
|
||||
)}
|
||||
end
|
||||
context 'with yaml configuration' do
|
||||
let :params do
|
||||
{
|
||||
:policies => {
|
||||
'foo' => {
|
||||
'file_path' => '/etc/octavia/policy.yaml',
|
||||
'key' => 'context_is_admin',
|
||||
'value' => 'foo:bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__policy__base('foo').with(
|
||||
:file_path => '/etc/octavia/policy.yaml',
|
||||
:key => 'context_is_admin',
|
||||
:value => 'foo:bar'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
|
Loading…
x
Reference in New Issue
Block a user