Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3389 - Add possibility to exclude a file or files matching a regexp from a folder copy #171

Merged
merged 1 commit into from
Sep 22, 2013
Merged

Fixes #3389 - Add possibility to exclude a file or files matching a regexp from a folder copy #171

merged 1 commit into from
Sep 22, 2013

Conversation

nperron
Copy link
Contributor

@nperron nperron commented Aug 20, 2013

Fixes #3389 - Add possibility to exclude a file or files matching a regexp from a folder copy

@jooooooon
Copy link
Member

@nperron, GitHub says this PR can't be merged. Can you rebase, and confirm it should be reviewed?

@nperron
Copy link
Contributor Author

nperron commented Sep 6, 2013

I've reworked, rebased and updated this PR.

The diff with the previous version of the Technique is:

diff -Naurw 1.4/copyFileFromSharedFolder.st 1.5/copyFileFromSharedFolder.st
--- 1.4/copyFileFromSharedFolder.st 2013-09-06 15:45:08.890069171 +0200
+++ 1.5/copyFileFromSharedFolder.st 2013-09-06 17:12:22.673821939 +0200
@@ -25,6 +25,12 @@
                 &COPYFILE_NAME:{name |"copyfile[&i&][name]" string => "&name&";
 }&

+                &COPYFILE_EXCLUDE_INCLUDE:{exclude_include |"copyfile[&i&][exclude_include]" string => "&exclude_include&";
+}&
+
+                &COPYFILE_EXCLUDE_INCLUDE_OPTION:{exclude_include_option |"copyfile[&i&][exclude_include_option]" string => "&exclude_include_option&";
+}&
+
                 &COPYFILE_RECURSION:{rec |"copyfile[&i&][recursion]" string => "&rec&";
 }&

@@ -74,11 +80,15 @@

       "is_file_${index}" not => isdir("${copyfile[${index}][destination]}");
       "exist_${index}" expression => fileexists("${copyfile[${index}][destination]}");
+      "need_exclusion_${index}" and => { isvariable("copyfile[${index}][exclude_include]"), strcmp("${copyfile[${index}][exclude_include_option]}", "exclude") };
+      "need_inclusion_${index}" and => { isvariable("copyfile[${index}][exclude_include]"), strcmp("${copyfile[${index}][exclude_include_option]}", "include") };
+      "apply_regex_${index}"    or  => { "need_exclusion_${index}", "need_inclusion_${index}"};

                 &COPYFILE_SUID:{suid |"enable_suid_&i&" expression => strcmp("&suid&", "true");
 }&
                 &COPYFILE_SGID:{sgid |"enable_sgid_&i&" expression => strcmp("&sgid&", "true");
 }&
+
                 # Set a class to define when we need to run the post-modification hook
                 &COPYFILE_POST_HOOK_RUN:{run |"execute_command_&i&" expression => strcmp("&run&", "true");
 }&
@@ -90,9 +100,24 @@
   files:
     is_valid.iteration_2::

+      # If it's a directory, without exclusion
+      "$(copyfile[$(index)][destination])"
+        copy_from    => scp("&SHARED_FILES_FOLDER&/$(copyfile[$(index)][name])", "$(server_info.cfserved)", "$(copyfile[$(index)][compare_method])", "false", "false", "false"),
+        depth_search => recurse("$(copyfile[$(index)][recursion])"),
+        perms        => mog(
+                            "$(copyfile[$(index)][perm])",
+                            "$(copyfile[$(index)][owner])",
+                           "$(copyfile[$(index)][group])"
+                           ),
+        comment      => "Enforce content of $(copyfile[$(index)][destination]) based on the content on the Rudder server with $(copyfile[$(index)][compare_method]) method",
+        classes      => kept_if_else("copy_file_$(index)_kept", "copy_file_$(index)_modified", "copy_file_$(index)_failed"),
+        ifvarclass   => "(!exist_$(index)|!is_file_$(index)).!apply_regex_${index}";
+
+       # If it's a directory, with exclusion
       "${copyfile[${index}][destination]}"
         copy_from    => scp("&SHARED_FILES_FOLDER&/${copyfile[${index}][name]}", "${server_info.cfserved}", "${copyfile[${index}][compare_method]}", "false", "false", "false"),
         depth_search => recurse("${copyfile[${index}][recursion]}"),
+        file_select  => exclude("${copyfile[${index}][exclude_include]}"),
         perms        => mog(
                             "${copyfile[${index}][perm]}",
                             "${copyfile[${index}][owner]}",
@@ -100,7 +125,21 @@
                            ),
         comment      => "Enforce content of ${copyfile[${index}][destination]} based on the content on the Rudder server with ${copyfile[${index}][compare_method]} method",
         classes      => kept_if_else("copy_file_${index}_kept", "copy_file_${index}_modified", "copy_file_${index}_failed"),
-        ifvarclass   => "!exist_${index}|!is_file_${index}";
+        ifvarclass   => "(!exist_${index}|!is_file_${index}).need_exclusion_${index}";
+
+       # If it's a directory, with inclusion
+      "${copyfile[${index}][destination]}"
+        copy_from    => scp("&SHARED_FILES_FOLDER&/${copyfile[${index}][name]}", "${server_info.cfserved}", "${copyfile[${index}][compare_method]}", "false", "false", "false"),
+        depth_search => recurse("${copyfile[${index}][recursion]}"),
+        file_select  => by_name("${copyfile[${index}][exclude_include]}"),
+        perms        => mog(
+                            "${copyfile[${index}][perm]}",
+                            "${copyfile[${index}][owner]}",
+                            "${copyfile[${index}][group]}"
+                           ),
+        comment      => "Enforce content of ${copyfile[${index}][destination]} based on the content on the Rudder server with ${copyfile[${index}][compare_method]} method with inclusion of '${copyfile[${index}][exclude_include]}'",
+        classes      => kept_if_else("copy_file_${index}_kept", "copy_file_${index}_modified", "copy_file_${index}_failed"),
+        ifvarclass   => "(!exist_${index}|!is_file_${index}).need_inclusion_${index}";

     # If it s a file, the depth_search prevents from enforcing the file content
     # Besides it is possible to specify suid or sgid only for a file since this
@@ -113,7 +152,7 @@
                           "${copyfile[${index}][owner]}",
                           "${copyfile[${index}][group]}"
                          ),
-        comment    => "Enforce content of file ${copyfile[${index}][destination]} based on the content on the Rudder server with ${copyfile[${index}][compare_method]} method",
+        comment    => "Enforce content of file ${copyfile[${index}][destination]} based on the content on the Rudder server with ${copyfile[${index}][compare_method]} method with exclusion of '${copyfile[${index}][exclude_include]}'",
         classes    => kept_if_else("copy_file_${index}_kept", "copy_file_${index}_modified", "copy_file_${index}_failed"),
         ifvarclass => "exist_${index}.is_file_${index}";

diff -Naurw 1.4/metadata.xml 1.5/metadata.xml
--- 1.4/metadata.xml    2013-09-06 15:45:08.890069171 +0200
+++ 1.5/metadata.xml    2013-09-06 17:12:22.673821939 +0200
@@ -49,6 +49,36 @@
         <DESCRIPTION>Path of the file to be copied</DESCRIPTION>
       <LONGDESCRIPTION>This is the relative path of the file/folder to be copied, on the Rudder policy server</LONGDESCRIPTION>
       </INPUT>
+          <SECTION name="Exclusion/Inclusion" multivalued="false" component="false" displayPriority="low">
+            <SELECT1>
+              <NAME>COPYFILE_EXCLUDE_INCLUDE_OPTION</NAME>
+              <DESCRIPTION>Exclude or include files from the copy</DESCRIPTION>
+              <LONGDESCRIPTION>Limit list of files to copy (include) or don't copy some files matching a pattern (exclude). Only applies if the path to copy from is a directory.</LONGDESCRIPTION>
+              <ITEM>
+                <VALUE>none</VALUE>
+                <LABEL>No include/exclude rules</LABEL>
+              </ITEM>
+              <ITEM>
+                <VALUE>exclude</VALUE>
+                <LABEL>Exclude file(s) matching</LABEL>
+              </ITEM>
+              <ITEM>
+               <VALUE>include</VALUE>
+               <LABEL>Include file(s) matching</LABEL>
+              </ITEM>
+              <CONSTRAINT>
+                <DEFAULT>none</DEFAULT>
+              </CONSTRAINT>
+            </SELECT1>
+        <INPUT>
+          <NAME>COPYFILE_EXCLUDE_INCLUDE</NAME>
+          <DESCRIPTION>File name patterns to exclude or include</DESCRIPTION>
+        <LONGDESCRIPTION>If one or several files should be excluded or included in this copy, please insert their name or a regular expression matching the appropriate file name(s))</LONGDESCRIPTION>
+              <CONSTRAINT>
+                <MAYBEEMPTY>true</MAYBEEMPTY>
+              </CONSTRAINT>
+        </INPUT>
+          </SECTION>
       <INPUT>
         <NAME>COPYFILE_DESTINATION</NAME>
         <DESCRIPTION>Destination of the file</DESCRIPTION>
                                                                                                                                                                                                                     129,29        Bas

jooooooon added a commit that referenced this pull request Sep 22, 2013
…le_or_regexp_from_folder_copy_BIS

Fixes #3389 - Add possibility to exclude a file or files matching a regexp from a folder copy
@jooooooon jooooooon merged commit 4371b89 into Normation:branches/rudder/2.4 Sep 22, 2013
amousset pushed a commit to amousset/rudder-techniques that referenced this pull request Dec 8, 2015
…rrect_migration_after_2_6_upgrade

Fixes #4062: Prevent an upgrade failure in case of a property modificati...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants