Class: CF::UAA::GroupCli

Inherits:
CommonCli show all
Defined in:
lib/uaa/cli/group.rb

Instance Method Summary collapse

Methods inherited from CommonCli

#askd, #auth_header, #clientid, #clientname, #clientsecret, #complain, #debug?, #handle_request, #passcode, #scim_common_list, #scim_get_helper, #scim_get_object, #scim_get_user_object, #scim_request, #trace?, #update_target_info, #username, #userpwd, #verified_pwd

Methods inherited from Topic

#add_command, #ask, #ask_pwd, commands, define_option, desc, #gripe, #help_col_start, #initialize, #opt_help, #opt_strs, option_defs, #opts, #pp, #print_tree, #say, #say_cmd_helper, #say_command_help, #say_commands, #say_definition, #say_help, #terminal_columns, topic

Constructor Details

This class inherits a constructor from CF::UAA::Topic

Instance Method Details

#gname(name) ⇒ Object



24
# File 'lib/uaa/cli/group.rb', line 24

def gname(name) name || ask("Group name") end

#id_set(objs) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/uaa/cli/group.rb', line 101

def id_set(objs)
  objs.each_with_object(Set.new) {|o, s|
    id = o.is_a?(String)? o: (o["id"] || o["value"] || o["memberid"])
    raise BadResponse, "no id found in response of current members" unless id
    s << id
  }
end

#update_members(scim, name, attr, users, add = true) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/uaa/cli/group.rb', line 109

def update_members(scim, name, attr, users, add = true)
    group = scim_get_object(scim, :group, gname(name))
    old_ids = id_set(group[attr] || [])
    new_ids = id_set(scim.ids(:user, *users))
    if add
      raise "not all users found, none added" unless new_ids.size == users.size
      group[attr] = (old_ids + new_ids).to_a
      raise "no new users given" unless group[attr].size > old_ids.size
    else
      raise "not all users found, none deleted" unless new_ids.size == users.size
      group[attr] = (old_ids - new_ids).to_a
      raise "no existing users to delete" unless group[attr].size < old_ids.size
      group.delete(attr) if group[attr].empty?
    end
    scim.put(:group, group)
    "success"
end