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:
@@ -28,13 +28,19 @@
|
|||||||
# (optional) Group for the policy file
|
# (optional) Group for the policy file
|
||||||
# Defaults to undef
|
# Defaults to undef
|
||||||
#
|
#
|
||||||
|
# [*file_format*]
|
||||||
|
# (optional) Format for file contents. Valid values
|
||||||
|
# are 'json' or 'yaml'.
|
||||||
|
# Defaults to 'json'.
|
||||||
|
#
|
||||||
define openstacklib::policy::base (
|
define openstacklib::policy::base (
|
||||||
$file_path,
|
$file_path,
|
||||||
$key,
|
$key,
|
||||||
$value = '',
|
$value = '',
|
||||||
$file_mode = '0640',
|
$file_mode = '0640',
|
||||||
$file_user = undef,
|
$file_user = undef,
|
||||||
$file_group = undef,
|
$file_group = undef,
|
||||||
|
$file_format = 'json',
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ensure_resource('file', $file_path, {
|
ensure_resource('file', $file_path, {
|
||||||
@@ -45,9 +51,22 @@ define openstacklib::policy::base (
|
|||||||
content => '{}'
|
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
|
# Add entry if it doesn't exists
|
||||||
augeas { "${file_path}-${key}-${value}-add":
|
augeas { "${file_path}-${key}-${value}-add":
|
||||||
lens => 'Json.lns',
|
lens => $file_lens,
|
||||||
incl => $file_path,
|
incl => $file_path,
|
||||||
changes => [
|
changes => [
|
||||||
"set dict/entry[last()+1] \"${key}\"",
|
"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.
|
# Requires that the entry is added before this call or it will fail.
|
||||||
augeas { "${file_path}-${key}-${value}" :
|
augeas { "${file_path}-${key}-${value}" :
|
||||||
lens => 'Json.lns',
|
lens => $file_lens,
|
||||||
incl => $file_path,
|
incl => $file_path,
|
||||||
changes => "set dict/entry[*][.=\"${key}\"]/string \"${value}\"",
|
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'
|
:value => 'foo:bar'
|
||||||
)}
|
)}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
on_supported_os({
|
on_supported_os({
|
||||||
|
Reference in New Issue
Block a user