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

Function to return a canonified map

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Open
    • Priority: (None)
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Complexity:
      S

      Description

      A canonified map is a commonly used pattern in CFEngine that is used when you have classes based on variable data. Canonfication is important when checking if a class based on some variable since the variable value may contain characters that are not valid in classes.

      Illustrating a canonified map
      bundle agent main
      {
        vars:
          "list" slist => { "one-one", "two-two" };
      
      
          # This is a common pattern
          # Indicies not canonified, values are
          "c_map[$(list)]"
            string => canonify( $(list) );
      
          # It's less common to need a reversed canonified map
          # Indicies canonified, values not
          "map_c[$(c_map[$(list)])]"
            string => "$(list)";
      
         # NOTE: It might be nice to have a function that produced a canonified map as
         # a data container instead of having to build a classic array by iterating.
         # Relavent conversations:
         # https://github.com/cfengine/core/pull/2425#issuecomment-162309393
         # https://github.com/cfengine/core/pull/2425#issuecomment-166554668
      }  
      
      Variable name                            Variable value                                               Meta tags                               
      default:main.c_map[one-one]              one_one                                                      source=promise                          
      default:main.c_map[two-two]              two_two                                                      source=promise                          
      default:main.list                         {"one-one","two-two"}                                       source=promise                          
      default:main.map_c[one_one]              one-one                                                      source=promise                          
      default:main.map_c[two_two]              two-two                                                      source=promise                          
      

      It might be useful and more performant to have a function that can return a canonified map as a data container.

      canonified_map( list_or_data_container_or_classic_array, [canonify_values|canonify_keys] );

      • Default to canonify_values
      Illustrating a function to return a canonified map
      bundle agent main
      {
        vars:
          "list" slist => { "one-one", "two-two" };
      
      
          # Indicies not canonified, values are
          "c_map1"
            data => canonified_map( list );
          "c_map2"
            data => canonified_map( list, canonify_values );
      
          # It's less common to need a reversed canonified map
          # Indicies canonified, values not
          "map_c"
            data => canonified_map( list, canonify_keys );
      }  
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel