Last active
August 29, 2015 14:10
-
-
Save tzz/3c43de4abf458a771d64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body common control | |
{ | |
bundlesequence => { "legacy" }; | |
inputs => { "$(sys.libdir)/stdlib.cf" }; | |
} | |
bundle agent legacy | |
{ | |
vars: | |
"groups" data => parsejson('{ | |
"groupa": { | |
"gid": "1000", | |
"members": [ "usera", "userb" ] | |
}, | |
"groupb": { | |
"gid": "1001", | |
"members": [ "userc", "userd" ] | |
} | |
}'); | |
"unsorted_keys" slist => getindices("groups"); | |
"keys" slist => sort(unsorted_keys, "lex"); | |
methods: | |
"addgroup" | |
usebundle => add_legacy_group(@(groups), $(keys)); | |
"report" | |
usebundle => report_legacy_groups(); | |
} | |
bundle agent add_legacy_group(dg, group) | |
{ | |
vars: | |
"members" slist => getvalues("dg[$(group)][members]"); | |
"gid" string => "$(dg[$(group)][gid])"; | |
"strmembers" string => join(",", members); | |
"created_$(group)" | |
meta => { "groupcreation" }, | |
string => format("%s:x:%s:%s", $(group), $(gid), $(strmembers)); | |
"ary[$(group)]" string => "$(created_$(group))"; | |
reports: | |
"$(this.bundle): collecting data for $(group): members $(strmembers), GID $(gid)"; | |
"$(this.bundle): collected data for $(group): $(created_$(group))"; | |
} | |
bundle agent report_legacy_groups() | |
{ | |
vars: | |
"created" slist => variablesmatching(".*", "groupcreation"); | |
"collected[$(created)]" string => "$($(created))"; | |
"todo" data => mergedata(collected); | |
"todo_s" string => format("%S", todo); | |
"ary_import" data => mergedata("add_legacy_group.ary"); | |
"ary_import_s" string => format("%S", ary_import); | |
reports: | |
"$(this.bundle): $(created) = $(collected[$(created)])"; | |
"$(this.bundle): as JSON: $(todo_s)"; | |
"$(this.bundle): broken ary import as JSON: $(ary_import_s)"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment