Project

General

Profile

« Previous | Next » 

Revision b0f89cdd

Added by Félix DALLIDET over 6 years ago

Fixes #11149: Override json technique

View differences:

maintained-techniques
systemSettings/misc/genericVariableDefinition/2.0
systemSettings/misc/partitionSizeMonitoring/3.0
systemSettings/misc/variableFromJsonFile/1.0
systemSettings/misc/variableFromJsonFile/2.0
systemSettings/networking/dnsConfiguration/3.0
systemSettings/networking/hostsConfiguration/2.0
systemSettings/networking/nfsClient/3.0
techniques/systemSettings/misc/variableFromJsonFile/1.0/metadata.xml
-->
<TECHNIQUE name="Variable from JSON file (dict)">
<DEPRECATED>This technique version has been superseded by a new version. It will no longer be available in the next stable version of Rudder. Please upgrade to the latest version.</DEPRECATED>
<DESCRIPTION>Downloads a JSON file from shared-files and reads it into variables. You can use these variables in the form ${your_namespace.variable_name}</DESCRIPTION>
<MULTIINSTANCE>true</MULTIINSTANCE>
<COMPATIBLE>
techniques/systemSettings/misc/variableFromJsonFile/2.0/changelog
-- Felix Dallidet <felix.dallidet@normation.com> Thu Jul 20 18:56:49 2017
* Version 2.0
** Add override option
techniques/systemSettings/misc/variableFromJsonFile/2.0/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/>.
-->
<TECHNIQUE name="Variable from JSON file (dict)">
<DESCRIPTION>Variable content can be overridden by optional json files read from a different place. You can use these variables in the form ${your_namespace.variable_name}</DESCRIPTION>
<MULTIINSTANCE>true</MULTIINSTANCE>
<COMPATIBLE>
<OS>Every OS</OS>
<AGENT version=">= 3.6">cfengine-community</AGENT>
</COMPATIBLE>
<BUNDLES>
<NAME>variable_from_json_file</NAME>
</BUNDLES>
<TMLS>
<TML name="variableFromJsonFile"/>
</TMLS>
<SYSTEMVARS>
<NAME>SHARED_FILES_FOLDER</NAME>
</SYSTEMVARS>
<TRACKINGVARIABLE>
<SAMESIZEAS>VARIABLE_FROM_JSON_FILE_JSON_FILE</SAMESIZEAS>
</TRACKINGVARIABLE>
<SECTIONS>
<SECTION name="File copy" component="true" componentKey="VARIABLE_FROM_JSON_FILE_JSON_FILE" />
<SECTION name="Variable definition" component="true" componentKey="VARIABLE_FROM_JSON_FILE_JSON_FILE" >
<INPUT>
<NAME>VARIABLE_FROM_JSON_FILE_VARIABLE_NAME</NAME>
<DESCRIPTION>Variable name</DESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
<MAYBEEMPTY>false</MAYBEEMPTY>
<REGEX error="The variable name must be of the form my_prefix.my_name">^[\w]+\.[\w]+$</REGEX>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>VARIABLE_FROM_JSON_FILE_BASE_SOURCE</NAME>
<DESCRIPTION>File location</DESCRIPTION>
<ITEM>
<VALUE>remote</VALUE>
<LABEL>Rudder server</LABEL>
</ITEM>
<ITEM>
<VALUE>local</VALUE>
<LABEL>Local node</LABEL>
</ITEM>
<CONSTRAINT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<DEFAULT>remote</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>VARIABLE_FROM_JSON_FILE_BASE_FILE</NAME>
<DESCRIPTION>File path</DESCRIPTION>
<LONGDESCRIPTION>Path relative to /var/rudder/configuration-repository/shared-files/ for remote sources. Absolute path for local ones.</LONGDESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
<MAYBEEMPTY>false</MAYBEEMPTY>
</CONSTRAINT>
</INPUT>
</SECTION>
<SECTION name="Overriding file" multivalued="true" component="true" componentKey="VARIABLE_FROM_JSON_FILE_JSON_FILE" >
<SELECT1>
<NAME>VARIABLE_FROM_JSON_FILE_SOURCE</NAME>
<DESCRIPTION>File location</DESCRIPTION>
<ITEM>
<VALUE>remote</VALUE>
<LABEL>Remote server</LABEL>
</ITEM>
<ITEM>
<VALUE>local</VALUE>
<LABEL>Local node</LABEL>
</ITEM>
<CONSTRAINT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<DEFAULT>remote</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>VARIABLE_FROM_JSON_FILE_JSON_FILE</NAME>
<DESCRIPTION>File path</DESCRIPTION>
<LONGDESCRIPTION>Path relative to /var/rudder/configuration-repository/shared-files/ for remote sources. Absolute path for local ones. It will override the previous one if necessary.</LONGDESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
<MAYBEEMPTY>true</MAYBEEMPTY>
</CONSTRAINT>
</INPUT>
</SECTION>
</SECTIONS>
</TECHNIQUE>
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/file1
{ "key1": "value1", "key2": "value1", "key3": "value1" }
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/file2
{"key2": "value2", "key3": "value2" }
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/file3
{ "key3": "value3" }
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/file6
{"key6":"value6"}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_local.json
{
"displayName": "Var local",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "/tmp/file2"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "local"
}
}
]
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "/tmp/file3"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "local"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "/tmp/file1"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "local"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix6.variable6"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_merging.cf
#!/usr/local/bin/ncf -f
bundle agent init {
methods:
"any" usebundle => file_remove("/tmp/test_output.log");
"any" usebundle => file_enforce_content("/tmp/file1", "{ \"key1\": \"value1\", \"key2\": \"value1\", \"key3\":\"value1\"}", "true");
"any" usebundle => file_enforce_content("/tmp/file2", "{ \"key2\": \"value2\", \"key3\":\"value2\"}", "true");
"any" usebundle => file_enforce_content("/tmp/file3", "{ \"key3\": \"value3\"}", "true");
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_merging.json
{
"displayName": "zzzzzFile content (1,1)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File to manage",
"sections": [
{
"section": {
"name": "Enforce content by section",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_SECTION_MANAGEMENT",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_SECTION_CONTENT",
"value": ""
}
},
{
"var": {
"name": "GENERIC_FILE_SECTION_FOOTER",
"value": ""
}
},
{
"var": {
"name": "GENERIC_FILE_SECTION_HEADER",
"value": ""
}
}
]
}
},
{
"section": {
"name": "Enforce content only in zone",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_MIGRATE_TO_ZONE_BOOLEAN",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_ZONE_FOOTER",
"value": "### End of section managed by Rudder"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_ZONE_HEADER",
"value": "### Beginning of section managed by Rudder"
}
}
]
}
},
{
"section": {
"name": "File",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_CREATE_BOOLEAN",
"value": "true"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_DELETION_BOOLEAN",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_ENFORCE",
"value": "true"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_ENFORCE_CREATE_ONLY_BOOLEAN",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_MODIFICATION_BOOLEAN",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_ONLY_ZONE_BOOLEAN",
"value": "false"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_PATH",
"value": "/tmp/result"
}
}
]
}
},
{
"section": {
"name": "File content",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_PAYLOAD",
"value": "${prefix1.variable1[key1]}\r\n${prefix1.variable1[key2]}\r\n${prefix1.variable1[key3]}\r\n${prefix1.variable1[key4]}\r\n${prefix1.variable1[key5]}\r\n${prefix1.variable1[key6]}\r\n\r\n${prefix2.variable2[key1]}\r\n${prefix2.variable2[key2]}\r\n${prefix2.variable2[key3]}\r\n${prefix2.variable2[key4]}\r\n${prefix2.variable2[key5]}\r\n${prefix2.variable2[key6]}\r\n\r\n${prefix3.variable3[key1]}\r\n${prefix3.variable3[key2]}\r\n${prefix3.variable3[key3]}\r\n${prefix3.variable3[key4]}\r\n${prefix3.variable3[key5]}\r\n${prefix3.variable3[key6]}\r\n\r\n\r\n${prefix4.variable4[key1]}\r\n${prefix4.variable4[key2]}\r\n${prefix4.variable4[key3]}\r\n${prefix4.variable4[key4]}\r\n${prefix4.variable4[key5]}\r\n${prefix4.variable4[key6]}\r\n\r\n\r\n\r\n${prefix6.variable6[key1]}\r\n${prefix6.variable6[key2]}\r\n${prefix6.variable6[key3]}\r\n${prefix6.variable6[key4]}\r\n${prefix6.variable6[key5]}\r\n${prefix6.variable6[key6]}"
}
}
]
}
},
{
"section": {
"name": "Line deletion regular expressions",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_DELETION_REGEXP",
"value": "deleteme.*"
}
}
]
}
},
{
"section": {
"name": "Line replacement regular expressions",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_MODIFICATION_DESTINATION",
"value": ""
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_MODIFICATION_REGEXP",
"value": "replaceme.*"
}
}
]
}
},
{
"section": {
"name": "Permission adjustment",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_GROUP",
"value": "root"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_OWNER",
"value": "root"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_PERM",
"value": "644"
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_PERMISSION_ADJUSTMENT",
"value": "false"
}
}
]
}
},
{
"section": {
"name": "Post-modification hook",
"vars": [
{
"var": {
"name": "GENERIC_FILE_CONTENT_POST_HOOK_COMMAND",
"value": ""
}
},
{
"var": {
"name": "GENERIC_FILE_CONTENT_POST_HOOK_RUN",
"value": "false"
}
}
]
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "checkGenericFileContent",
"techniqueVersion": "7.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_merging.metadata
[{
"inits": ["test_merging.cf"],
"checks": ["test_merging.rb"],
"directives": ["test_merging.json", "test_var_1.json", "test_var_2.json", "test_var_3.json", "test_var_4.json", "test_var_5.json", "test_local.json"],
"sharedFiles":["file1", "file2", "file3", "file6"],
"compliance": 93.94
}]
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_merging.rb
require "spec_helper"
describe file("/tmp/result") do
it { should be_file}
its(:content) { should match /value1\svalue2\svalue3[\s\S]+\${prefix2\.variable2\[key2\]}\svalue3[\s\S]+\${prefix3\.variable3\[key2\]}\svalue3[\s\S]+?(value1\s){3}.*\s.*\svalue6\s+value1\svalue2\svalue3\s(\$\{prefix6\.variable6\[key.\]\}\s){3}/ }
end
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_var_1.json
{
"displayName": "var1 (1,2)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "file2"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "file3"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "file1"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "remote"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix1.variable1"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_var_2.json
{
"displayName": "var2 (1,3)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": ""
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "file3"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "remote"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix2.variable2"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_var_3.json
{
"displayName": "var3 (1,4)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": ""
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "file3"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "remote"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix3.variable3"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_var_4.json
{
"displayName": "var4 (1,5)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "file1"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "file6"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "file2"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "remote"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix4.variable4"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/tests/test_var_5.json
{
"displayName": "var5 (1,6)",
"enabled": true,
"longDescription": "",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "File copy"
}
},
{
"section": {
"name": "Json files to merge",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_JSON_FILE",
"value": "fileThatDoesnotExist"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_SOURCE",
"value": "remote"
}
}
]
}
},
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_FILE",
"value": "file1"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_BASE_SOURCE",
"value": "remote"
}
},
{
"var": {
"name": "VARIABLE_FROM_JSON_FILE_VARIABLE_NAME",
"value": "prefix5.variable5"
}
}
]
}
}
]
}
},
"shortDescription": "",
"techniqueName": "variableFromJsonFile",
"techniqueVersion": "2.0"
}
techniques/systemSettings/misc/variableFromJsonFile/2.0/variableFromJsonFile.st
#####################################################################################
# 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/>.
#
#####################################################################################
bundle agent variable_from_json_file
{
vars:
&VARIABLE_FROM_JSON_FILE_JSON_FILE:{json_file | "json_file[&i&]" string => "&json_file&";
}&
&TRACKINGKEY:{piuuid | "trackingkey[&i&]" string => "&piuuid&";
}&
&VARIABLE_FROM_JSON_FILE_VARIABLE_NAME:{name | "complete_name[&i&]" string => "&name&";
}&
&VARIABLE_FROM_JSON_FILE_BASE_FILE:{base_file | "base_file[&i&]" string => "&base_file&";
}&
&VARIABLE_FROM_JSON_FILE_SOURCE:{source | "sources[&i&]" string => "&source&";
}&
&VARIABLE_FROM_JSON_FILE_BASE_SOURCE:{base_source | "base_sources[&i&]" string => "&base_source&";
}&
"directory_server" string => "/var/rudder/configuration-repository/shared-files";
"directory_agent" string => "/var/rudder/resources";
"directory_agent_canon" string => canonify("${directory_agent}");
"prefix" string => "tmp_merging_json_files";
"variable_index" slist => getindices("complete_name");
"index" slist => getindices("json_file");
"files_index" slist => sort("index", "int");
"tmp_index_1[${variable_index}]" string => eval("${variable_index} -1", "math", "infix");
"index_from_zero[${variable_index}]" string => format("%d", "${tmp_index_1[${variable_index}]}");
"strTok[${variable_index}]" slist => splitstring("${complete_name[${variable_index}]}", "\.", "2");
"prefixes[${variable_index}]" string => nth("strTok[${variable_index}]", 0);
"names[${variable_index}]" string => nth("strTok[${variable_index}]", 1);
#Making an array with the unique trackingkey, with shell for the moment. Waiting for future feature on
# string template implementation in the webapp
"cmd" string => "/usr/bin/uniq << EOF ${const.n}&TRACKINGKEY:{piuuid |&piuuid&};separator="${const.n}"&${const.n}EOF${const.n}";
"long_keys" string => execresult("${cmd}", "useshell");
"long_keys_list" slist => splitstring("${long_keys}", "${const.n}", "999");
"unique_keys[${variable_index}]" string => nth("long_keys_list", "${index_from_zero[${variable_index}]}");
#Making an array containing the complete_name as many times as their respectives
#number of files to merge. The array's length must be equal to the trackingkey array length.
"name_list[${files_index}]" string => "${complete_name[${variable_index}]}",
ifvarclass => "same_key_${variable_index}_${files_index}";
"base_file_canon[${variable_index}]" string => canonify("${base_file[${variable_index}]}");
"json_file_canon[${files_index}]" string => canonify("${json_file[${files_index}]}");
classes:
"same_key_${variable_index}_${files_index}" expression => strcmp("${unique_keys[${variable_index}]}", "${trackingkey[${files_index}]}");
"not_empty_input_${files_index}" not => strcmp("", "${json_file[${files_index}]}");
"base_remote_source_${variable_index}" expression => strcmp("remote", "${base_sources[${variable_index}]}");
"base_local_source_${variable_index}" expression => strcmp("local", "${base_sources[${variable_index}]}");
"remote_source_${files_index}" expression => strcmp("remote", "${sources[${files_index}]}");
"local_source_${files_index}" expression => strcmp("local", "${sources[${files_index}]}");
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";
methods:
#Load the differents Json File
"prepare" usebundle => directory_create("${directory_agent}");
#Base file
#Remote source
"download_base_files_${variable_index}"
usebundle => file_copy_from_remote_source(
"${directory_server}/${base_file[${variable_index}]}",
"${directory_agent}/${base_file_canon[${variable_index}]}"
),
ifvarclass => "base_remote_source_${variable_index}";
#Local source
"download_base_files_${variable_index}"
usebundle => file_copy_from_local_source(
"${base_file[${variable_index}]}",
"${directory_agent}/${base_file_canon[${variable_index}]}"
),
ifvarclass => "base_local_source_${variable_index}";
"apply_base_file_${variable_index}"
usebundle => variable_dict_from_file(
"${prefixes[${variable_index}]}",
"${names[${variable_index}]}",
"${directory_agent}/${base_file_canon[${variable_index}]}"
);
#Others files
#Remote source
"download_other_files_${files_index}"
usebundle => file_copy_from_remote_source(
"${directory_server}/${json_file[${files_index}]}",
"${directory_agent}/${json_file_canon[${files_index}]}"
),
ifvarclass => "not_empty_input_${files_index}.remote_source_${files_index}";
#Local source
"download_other_files_${files_index}"
usebundle => file_copy_from_local_source(
"${json_file[${files_index}]}",
"${directory_agent}/${json_file_canon[${files_index}]}"
),
ifvarclass => "not_empty_input_${files_index}.local_source_${files_index}";
"apply_other_files_${files_index}"
usebundle => variable_dict_from_file(
"${prefix}",
"${json_file_canon[${files_index}]}",
"${directory_agent}/${json_file_canon[${files_index}]}"
),
ifvarclass => "not_empty_input_${files_index}";
#Merging
"merging_${files_index}" usebundle => merge("${name_list[${files_index}]}" , "${prefix}.${json_file_canon[${files_index}]}", "${json_file[${files_index}]}", "${trackingkey[${files_index}]}"),
ifvarclass => "not_empty_input_${files_index}";
#Reporting
#File copy
#Remote
"any" usebundle => rudder_common_reports_generic("variableFromJsonFile", "file_copy_from_remote_source_${directory_agent_canon}_${json_file_canon[${files_index}]}", "${trackingkey[${files_index}]}", "File copy", "${json_file[${files_index}]}", "Copy of ${directory_server}/${json_file[${files_index}]} from the policy server to ${directory_agent}"),
ifvarclass => "not_empty_input_${files_index}.remote_source_${files_index}";
#Local
"any" usebundle => rudder_common_reports_generic("variableFromJsonFile", "file_copy_from_local_source_${directory_agent_canon}_${json_file_canon[${files_index}]}", "${trackingkey[${files_index}]}", "File copy", "${json_file[${files_index}]}", "Copy of ${json_file[${files_index}]} to ${directory_agent}"),
ifvarclass => "not_empty_input_${files_index}.local_source_${files_index}";
#Variable definition
"any" usebundle => rudder_common_reports_generic("variableFromJsonFile", "variable_dict_from_file_${json_file_canon[${files_index}]}", "${trackingkey[${files_index}]}", "Overriding file", "${json_file[${files_index}]}", "${json_file[${files_index}]} loading"),
ifvarclass => "not_empty_input_${files_index}";
#Not applicable
pass3::
"any" usebundle => rudder_common_report("variableFromJsonFile", "result_na", "${trackingkey[${files_index}]}", "File copy", "${json_file[${files_index}]}", "No merging files precised"),
ifvarclass => "!not_empty_input_${files_index}";
"any" usebundle => rudder_common_report("variableFromJsonFile", "result_na", "${trackingkey[${files_index}]}", "Overriding file", "${json_file[${files_index}]}", "No merging files precised"),
ifvarclass => "!not_empty_input_${files_index}";
"any" usebundle => rudder_common_report("variableFromJsonFile", "result_na", "${trackingkey[${files_index}]}", "Variable definition", "${json_file[${files_index}]}", "No merging files precised"),
ifvarclass => "!not_empty_input_${files_index}";
}
bundle agent merge(complete_var_name, file_var, file_name, trackingkey) {
vars:
"strTok" slist => splitstring("${complete_var_name}", "\.", "2");
"prefix" string => nth("strTok", 0);
"name" string => nth("strTok", 1);
methods:
"any" usebundle => variable_dict_merge("${prefix}", "${name}", "${complete_var_name}", "${file_var}");
"any" usebundle => rudder_common_reports_generic("variableFromJsonFile", "variable_dict_merge_${name}", "${trackingkey}", "Variable definition", "${file_name}", "Merging ${file_var} with ${complete_var_name} in ${complete_var_name}");
}

Also available in: Unified diff