Revision 335b79b6
Added by Benoît PECCATTE about 6 years ago
techniques/fileDistribution/manageKeyValueFile/1.3/changelog | ||
---|---|---|
-- Nicolas Charles <nicolas.charles@normation.com> Tue Sep 12 18:45:08 2017
|
||
* Version 1.1
|
||
** Add an option to be strict on spaces around separator
|
||
-- Nicolas Charles <nicolas.charles@normation.com> Thu Dec 7 17:20:54 2017
|
||
* Version 1.2
|
||
** Convert to multiversionned technique
|
||
-- Benoît Peccatte <benoit.peccatte@normation.com> Thu Feb 15 15:18:30 2018
|
||
* Version 1.3
|
||
** Add post-hook
|
techniques/fileDistribution/manageKeyValueFile/1.3/manage-key-value-file.st | ||
---|---|---|
#####################################################################################
|
||
# Copyright 2016 Normation SAS
|
||
#####################################################################################
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
# it under the terms of the GNU General Public License as published by
|
||
# the Free Software Foundation, Version 3.
|
||
#
|
||
# This program is distributed in the hope that it will be useful,
|
||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
# GNU General Public License for more details.
|
||
#
|
||
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
#
|
||
#####################################################################################
|
||
|
||
bundle agent manage_key_value_file_RudderUniqueID {
|
||
vars:
|
||
&MANAGE_KEY_VALUE_FILEPATH:{file | "file[&i&]" string => "&file&";
|
||
}&
|
||
&MANAGE_KEY_VALUE_KEY:{key | "key[&i&]" string => "&key&";
|
||
}&
|
||
&MANAGE_KEY_VALUE_VALUE:{value | "value[&i&]" string => "&value&";
|
||
}&
|
||
&MANAGE_KEY_VALUE_SEPARATOR:{separator | "separator[&i&]" string => "&separator&";
|
||
}&
|
||
&MANAGE_KEY_VALUE_OPTION:{option | "option[&i&]" string => "&option&";
|
||
}&
|
||
&TRACKINGKEY:{uuid | "trackingkey[&i&]" string => "&uuid&";
|
||
}&
|
||
|
||
|
||
"index" slist => getindices("file");
|
||
|
||
"canonified_file[${index}]" string => canonify("${file[${index}]}");
|
||
"class_prefix_${index}" string => "file_ensure_key_value_${canonified_file[${index}]}";
|
||
"technique_name" string => "Manage keys-values file";
|
||
|
||
|
||
methods:
|
||
"apply_${index}" usebundle => file_ensure_key_value_option("${file[${index}]}", "${key[${index}]}", "${value[${index}]}", "${separator[${index}]}", "${option[${index}]}");
|
||
"report_${index}" usebundle => rudder_common_reports_generic_index("${technique_name}", "${class_prefix_${index}}", "${trackingkey[${index}]}", "File", "${file[${index}]}", "The key -> value ${key[${index}]} ${separator[${index}]} ${value[${index}]} with ${option[${index}]} spacing around the separator", "${index}");
|
||
|
||
}
|
techniques/fileDistribution/manageKeyValueFile/1.3/metadata.xml | ||
---|---|---|
<!--
|
||
Copyright 2015 Normation SAS
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, Version 3.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
-->
|
||
|
||
<!-- This technique lets user define a key-value in a file -->
|
||
<TECHNIQUE name="Manage keys-values in file">
|
||
<DESCRIPTION>Manage keys-values in file</DESCRIPTION>
|
||
<MULTIINSTANCE>true</MULTIINSTANCE>
|
||
<POLICYGENERATION>separated</POLICYGENERATION>
|
||
<COMPATIBLE>
|
||
<OS>Every OS</OS>
|
||
<AGENT version=">= 3.5">cfengine-community</AGENT>
|
||
</COMPATIBLE>
|
||
|
||
<BUNDLES>
|
||
<NAME>manage_key_value_file_RudderUniqueID</NAME>
|
||
</BUNDLES>
|
||
|
||
<TMLS>
|
||
<TML name="manage-key-value-file"/>
|
||
</TMLS>
|
||
|
||
<TRACKINGVARIABLE>
|
||
<SAMESIZEAS>MANAGE_KEY_VALUE_FILEPATH</SAMESIZEAS>
|
||
</TRACKINGVARIABLE>
|
||
|
||
<SECTIONS>
|
||
<SECTION name="File to manage" multivalued="true" >
|
||
<SECTION name="File" component="true" componentKey="MANAGE_KEY_VALUE_FILEPATH">
|
||
<INPUT>
|
||
<NAME>MANAGE_KEY_VALUE_FILEPATH</NAME>
|
||
<DESCRIPTION>Path of the file to manage</DESCRIPTION>
|
||
</INPUT>
|
||
<INPUT>
|
||
<NAME>MANAGE_KEY_VALUE_KEY</NAME>
|
||
<DESCRIPTION>Key to define</DESCRIPTION>
|
||
<CONSTRAINT>
|
||
<TYPE>string</TYPE>
|
||
</CONSTRAINT>
|
||
</INPUT>
|
||
<INPUT>
|
||
<NAME>MANAGE_KEY_VALUE_VALUE</NAME>
|
||
<DESCRIPTION>Value to define</DESCRIPTION>
|
||
<CONSTRAINT>
|
||
<TYPE>string</TYPE>
|
||
<MAYBEEMPTY>true</MAYBEEMPTY>
|
||
</CONSTRAINT>
|
||
</INPUT>
|
||
<INPUT>
|
||
<NAME>MANAGE_KEY_VALUE_SEPARATOR</NAME>
|
||
<DESCRIPTION>Separator between key and value (for example "=")</DESCRIPTION>
|
||
<LONGDESCRIPTION>If you need to use space as a separator, you should use ${ncf_const.s} value.</LONGDESCRIPTION>
|
||
<CONSTRAINT>
|
||
<TYPE>string</TYPE>
|
||
</CONSTRAINT>
|
||
</INPUT>
|
||
<SELECT1>
|
||
<NAME>MANAGE_KEY_VALUE_OPTION</NAME>
|
||
<DESCRIPTION>Prevent spaces around separator</DESCRIPTION>
|
||
<LONGDESCRIPTION>If "No spacing" is selected, this will prevent any spaces around the separator, enforcing strictly KEY=VALUE; otherwise any number of spaces will be accepted before or after the separator.</LONGDESCRIPTION>
|
||
<ITEM>
|
||
<VALUE>strict</VALUE>
|
||
<LABEL>No spacing</LABEL>
|
||
</ITEM>
|
||
<ITEM>
|
||
<VALUE>lax</VALUE>
|
||
<LABEL>Any number of spaces</LABEL>
|
||
</ITEM>
|
||
<CONSTRAINT>
|
||
<DEFAULT>lax</DEFAULT>
|
||
</CONSTRAINT>
|
||
</SELECT1>
|
||
</SECTION>
|
||
</SECTION>
|
||
</SECTIONS>
|
||
</TECHNIQUE>
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_create.cf | ||
---|---|---|
#!/usr/local/bin/ncf -f
|
||
|
||
bundle agent init {
|
||
|
||
methods:
|
||
"any" usebundle => file_remove("/tmp/manage-key-value");
|
||
|
||
}
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_create.metadata | ||
---|---|---|
[{
|
||
"inits": [ "simple_key_create.cf" ],
|
||
"directives": [ "simple_key_replace.json" ],
|
||
"checks": [ "simple_key_replace.rb" ],
|
||
"sharedFiles":[],
|
||
"compliance": 100
|
||
}]
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_replace.cf | ||
---|---|---|
#!/usr/local/bin/ncf -f
|
||
|
||
bundle agent init {
|
||
|
||
methods:
|
||
"any" usebundle => file_enforce_content("/tmp/manage-key-value", "", "true");
|
||
|
||
}
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_replace.json | ||
---|---|---|
{
|
||
"displayName": "Manage keys-values in file /tmp/manage-key-value",
|
||
"shortDescription": "",
|
||
"longDescription": "Set key=value in this file",
|
||
"techniqueName": "manageKeyValueFile",
|
||
"techniqueVersion": "1.0",
|
||
"parameters": {
|
||
"section": {
|
||
"name": "sections",
|
||
"sections": [
|
||
{
|
||
"section": {
|
||
"name": "File to manage",
|
||
"sections": [
|
||
{
|
||
"section": {
|
||
"name": "File",
|
||
"vars": [
|
||
{
|
||
"var": {
|
||
"name": "MANAGE_KEY_VALUE_FILEPATH",
|
||
"value": "/tmp/manage-key-value"
|
||
}
|
||
},
|
||
{
|
||
"var": {
|
||
"name": "MANAGE_KEY_VALUE_KEY",
|
||
"value": "key"
|
||
}
|
||
},
|
||
{
|
||
"var": {
|
||
"name": "MANAGE_KEY_VALUE_SEPARATOR",
|
||
"value": "="
|
||
}
|
||
},
|
||
{
|
||
"var": {
|
||
"name": "MANAGE_KEY_VALUE_VALUE",
|
||
"value": "value"
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
|
||
|
||
}
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_replace.metadata | ||
---|---|---|
[{
|
||
"inits": [ "simple_key_replace.cf" ],
|
||
"directives": [ "simple_key_replace.json" ],
|
||
"checks": [ "simple_key_replace.rb" ],
|
||
"sharedFiles": [],
|
||
"compliance": 100
|
||
}]
|
techniques/fileDistribution/manageKeyValueFile/1.3/tests/simple_key_replace.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe file('/tmp/manage-key-value') do
|
||
it { should be_file }
|
||
it { should be_owned_by 'root' }
|
||
its(:content) { should match /key=value/ }
|
||
end
|
Also available in: Unified diff
Refs #12124: Creation of manageKeyValueFile version 1.3 from 1.2