Class: OpscodeAcl::GroupAddActor
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- OpscodeAcl::GroupAddActor
- Defined in:
- lib/chef/knife/group_add_actor.rb
Instance Attribute Summary collapse
-
#actor_name ⇒ Object
readonly
Returns the value of attribute actor_name.
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#group_name ⇒ Object
readonly
Returns the value of attribute group_name.
-
#user_map ⇒ Object
readonly
Returns the value of attribute user_map.
Instance Method Summary collapse
- #find_actor_in_map ⇒ Object
- #make_group_for_put(existing_group) ⇒ Object
- #maybe_add_actor(type, actors) ⇒ Object
- #run ⇒ Object
- #save_group(group) ⇒ Object
Instance Attribute Details
#actor_name ⇒ Object (readonly)
Returns the value of attribute actor_name.
23 24 25 |
# File 'lib/chef/knife/group_add_actor.rb', line 23 def actor_name @actor_name end |
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
23 24 25 |
# File 'lib/chef/knife/group_add_actor.rb', line 23 def clients @clients end |
#group_name ⇒ Object (readonly)
Returns the value of attribute group_name.
23 24 25 |
# File 'lib/chef/knife/group_add_actor.rb', line 23 def group_name @group_name end |
#user_map ⇒ Object (readonly)
Returns the value of attribute user_map.
23 24 25 |
# File 'lib/chef/knife/group_add_actor.rb', line 23 def user_map @user_map end |
Instance Method Details
#find_actor_in_map ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/knife/group_add_actor.rb', line 76 def find_actor_in_map @actor_type, @actor_id = if user_map[:users][actor_name] [:user, user_map[:users][actor_name]] else [:client, clients[actor_name]] end if @actor_id.nil? ui.error("no user or client named '#{actor_name}' in actor-map.yaml") exit 1 end true end |
#make_group_for_put(existing_group) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef/knife/group_add_actor.rb', line 54 def make_group_for_put(existing_group) new_group = { "groupname" => existing_group["groupname"], "orgname" => existing_group["orgname"], "actors" => { # users are added to groups via the user's USAG so we never # modify the users directly "users" => existing_group["users"], "clients" => maybe_add_actor(:client, existing_group["clients"]), "groups" => maybe_add_actor(:user, existing_group["groups"]) } } end |
#maybe_add_actor(type, actors) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/chef/knife/group_add_actor.rb', line 68 def maybe_add_actor(type, actors) new_actors = actors.dup if @actor_type == type && !new_actors.include?(@actor_id) new_actors << @actor_id end new_actors end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef/knife/group_add_actor.rb', line 28 def run if !File.exists?("actor-map.yaml") ui.error "unable to find 'actor-map.yaml'. Run 'knife actor map' and try again." exit 1 end actor_map = YAML.load(IO.read("actor-map.yaml")) @user_map = actor_map[:user_map] @clients = actor_map[:clients] @group_name = name_args[0] @actor_name = name_args[1] if !group_name || !actor_name ui.error "must specify GROUP and ACTOR" exit 1 end find_actor_in_map @chef_rest = Chef::REST.new(Chef::Config[:chef_server_url]) group = @chef_rest.get_rest("groups/#{group_name}") save_group(group) end |
#save_group(group) ⇒ Object
49 50 51 52 |
# File 'lib/chef/knife/group_add_actor.rb', line 49 def save_group(group) new_group = make_group_for_put(group) @chef_rest.put_rest("groups/#{new_group["groupname"]}", new_group) end |