howt to access values in data container

Xander Cage <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
hi,

I tried various functions but its just frustrating...

users.csv

ClassExpression,uid,name,group,ssh_key
weirdos,mscott,Michael 
Scott,pathetic,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
weirdos,jkras,John 
Krasinski,pathetic,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
twats,tflen,Toby 
Flenderson,tedious,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
zombie,fired,Get 
OUT!,buzzoff,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg

test promise:

bundle agent parent_bundle
{
  classes:

      "weirdos";
      "twats";
      "zombie";

  vars:
      "data_file" string => "users.csv";
      "d" data => classfiltercsv($(data_file), "true", 0);

      "parameter_name"        slist => getindices("d");
      "parameter_name_sorted" slist => sort(parameter_name, lex);

      "cvalues"        slist => getvalues("d");
      "cvalues_sorted" slist => sort(cvalues, lex);

      "raw" data => @(d);

  methods:

   "call_remove"     usebundle => child_bundle("$(this.bundle).d"),
                     handle => "dba_user_guard",
                     classes => results("bundle", 
"itsv_DABA_USER_NOT_JUSTIFIED");


  reports:

      "All users in parent function: data: $(with)" with => 
string_mustache("{{%-top-}}", d);

      "Bonkers index is number instead of key name: Key: $(parameter_name) 
-> Value: $(cvalues)";

      "Totally useless for practical usage: $(d[0])";


}

bundle agent child_bundle (info) {

    vars:


          "user_crap1" slist => getindices("$(info)");

          "bla" data => mergedata("info");
          "user_crap2" slist => getindices("$(bla)");

          "user_crap3" slist => getvalues("info[uid]");

          "bla_$(user_crap1)" string => format("%S", "info[$(user_crap1)]");


    reports:

        "child function, only numbers instead if key names : data: $(with)" 
with => string_mustache("{{%-top-}}", user_crap1);

        "child funtion, mergedate produces empty output: $(with)" with => 
string_mustache("{{%-top-}}", user_crap2);

        "child function, getvalues also not working : data: $(with)" with 
=> string_mustache("{{%-top-}}", user_crap3);

        "Some mehtod from the docs, also nothing: $(user_crap1): 
$(bla_$(user_crap1))";

}


bundle agent __main__
{
  methods:
      "parent_bundle";
}

data format:

 {
    "group": "pathetic",
    "name": "Michael Scott",
    "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
    "uid": "mscott"
  },
  {
    "group": "pathetic",
    "name": "John Krasinski",
    "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
    "uid": "jkras"
  },
  {
    "group": "tedious",
    "name": "Toby Flenderson",
    "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
    "uid": "tflen"
  },
  {
    "group": "buzzoff",
    "name": "Get OUT!",
    "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
    "uid": "fired"
  }

how to i access uid, name,...from this structure?

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/66d49fe7-4519-43e5-9724-c3ffbdd5b290n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.