Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2794

Add a function to remove a key from data container

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Built-in functions
    • Labels:
      None

      Description

      Hello,

      Please add new function to remove a key from data containter.

      Workaround is posible through regex_replace() with storejson() and parsejson() but only if string is not over size limit (around 4KB now). For bigger containers is no way. For example:

      "foo" data => '{"arch":"x86_64","icinga_agent":"cf3","os":"linux"}';
      "foo_str" string => storejson("foo");
      "tmp" string => regex_replace("$(foo_str)", "(.*?)(,\n)?\s*\"icinga_agent\":\s*\".*?\!(.*?)", "\1\3", "gm");
      "new" data => parsejson("tmp")

      Second workaround is merging an empty value, but the key stay in containter (thanks to Bas):

      vars:
        "foo" data => '{"arch":"x86_64","icinga_agent":"cf3","os":"linux"}';
        "foo_1" data => '{ "icinga_agent" : [] }';
        "merge" data => mergedata("foo", "foo_1");
      reports:
        "foo: $(foo)";
        "merge: $(merge)"
      
      R: foo: x86_64
      R: foo: cf3
      R: foo: linux
      R: merge: x86_64
      R: merge: linux
      

      Thanks

      Michal Svamberg

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              svamberg Michal Švamberg
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel