Forum: CFEngine Help
Subject: Re: split user passwd array
Author: davidlee
Link to topic: https://cfengine.com/forum/read.php?3,24257,24264#msg-24264

Your design specification wants to be able both to add new users and to edit 
existing users.  We are tempted to think of the former as being fully-fledged 
lines to be added, but the latter as individual fields to be adjusted.  But it 
is worth going back a step and considering the underlying data itself as a set 
of fields, including when adding it.

So perhaps rather than starting from:

vars:   
  "pw" string => "username1:x:1101:1101:user name:/home/user:/bin/bash";
  "pw" string => "username2:x:1102:1101:user name:/home/user:/bin/bash";


consider starting from the basic data itself, something like:

vars:   
  "username1" string => "x";
  "username1" string => "1101";
  "username1" string => "1101";
  "username1" string => "user name 1";
  "username1" string => "/home/username1";
  "username1" string => "/bin/bash";
  # repeat for other users


Admittedly that looks a more verbose starting point.  But it is still clear, 
and cleanly defines your data in its logical form.

At the point where you lead up to promising that user entries exist at all 
(your "append_passwd_starting()") you assemble those arrays into lines; at the 
point where you lead up to promising particular field values are set (your 
"set_user_field()" your data is already fine-grained enough to specify the 
exact fields you wish.

(A full working solution is beyond the scope of this email.  But I hope the 
above sketch gives an idea of another way of approaching these promises.)

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to