Class: Gtool::Provision::Group
- Inherits:
-
Thor
- Object
- Thor
- Gtool::Provision::Group
- Includes:
- Util
- Defined in:
- lib/gtool/provision/group.rb
Class Method Summary collapse
Instance Method Summary collapse
- #addmember(groupname, member) ⇒ Object
- #addowner(groupname, owner) ⇒ Object
- #create(groupname) ⇒ Object
- #delete(groupname) ⇒ Object
- #delmember(groupname, member) ⇒ Object
- #delowner(groupname, owner) ⇒ Object
- #get(groupname) ⇒ Object
- #list ⇒ Object
- #members(groupname) ⇒ Object
- #owners(groupname) ⇒ Object
- #update(groupname) ⇒ Object
Methods included from Util
Class Method Details
.banner(task, namespace = true, subcommand = false) ⇒ Object
186 187 188 |
# File 'lib/gtool/provision/group.rb', line 186 def self.(task, namespace = true, subcommand = false) "#{basename} #{task.formatted_usage(self, true, subcommand)}" end |
Instance Method Details
#addmember(groupname, member) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/gtool/provision/group.rb', line 109 def addmember(groupname, member) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) if group.nil? say "Group '#{groupname}' not found!", :red else group.add_member member invoke "group:members", [groupname] end end |
#addowner(groupname, owner) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/gtool/provision/group.rb', line 161 def addowner(groupname, owner) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) if group.nil? say "Group '#{groupname}' not found!", :red else group.add_owner owner invoke "group:owners", [groupname] end end |
#create(groupname) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gtool/provision/group.rb', line 48 def create(groupname) connection = Gtool::Auth.connection() group = GProv::Provision::Group.new(:connection => connection) group.group_id = groupname group.group_name = ask "Group name:" group. = ask "Email Permission:" group. = ask "Permission Preset:" group.description = ask "Group Description:" group.create! invoke "group:get", [group.group_id] end |
#delete(groupname) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gtool/provision/group.rb', line 72 def delete(groupname) connection = Gtool::Auth.connection() invoke "group:get", [groupname] group = GProv::Provision::Group.get(connection, groupname) if group.nil? say "Group #{groupname} not found!", :red elsif (yes? "Permanently delete this group?") and (groupname == ask("Type in #{groupname} to confirm:")) group.delete! else say "Not deleting group \"#{groupname}\".", :yellow end end |
#delmember(groupname, member) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gtool/provision/group.rb', line 122 def delmember(groupname, member) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) if group.nil? say "Group '#{groupname}' not found!", :red else group.del_member member invoke "group:members", [groupname] end end |
#delowner(groupname, owner) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/gtool/provision/group.rb', line 174 def delowner(groupname, owner) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) if group.nil? say "Group '#{groupname}' not found!", :red else group.del_owner owner invoke "group:owners", [groupname] end end |
#get(groupname) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gtool/provision/group.rb', line 33 def get(groupname) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) fields = GProv::Provision::Group.attribute_names field_names = GProv::Provision::Group.attribute_titles if group.nil? say "Group '#{groupname}' not found!", :red else properties = fields.map {|f| group.send f} print_table field_names.zip(properties) end end |
#list ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gtool/provision/group.rb', line 17 def list connection = Gtool::Auth.connection() groups = GProv::Provision::Group.all(connection) fields = GProv::Provision::Group.attribute_names field_names = GProv::Provision::Group.attribute_titles rows = groups.map do |group| fields.map {|f| group.send f} end rows.unshift field_names print_table rows say "#{rows.length - 1} entries.", :cyan end |
#members(groupname) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gtool/provision/group.rb', line 87 def members(groupname) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) fields = GProv::Provision::Member.attribute_names field_names = GProv::Provision::Member.attribute_titles if group.nil? say "Group '#{groupname}' not found!", :red else members = group.list_members rows = members.map do |member| fields.map {|f| member.send f} end rows.unshift field_names print_table rows say "#{rows.length - 1} entries.", :cyan end end |
#owners(groupname) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gtool/provision/group.rb', line 135 def owners(groupname) connection = Gtool::Auth.connection() group = GProv::Provision::Group.get(connection, groupname) fields = GProv::Provision::Owner.attribute_names field_names = GProv::Provision::Owner.attribute_titles if group.nil? say "Group '#{groupname}' not found!", :red else owners = group.list_owners if owners.nil? say "Group #{groupname} has no owners!", :red else rows = owners.map { |owner| fields.map {|f| owner.send f} } rows.unshift field_names # XXX https://github.com/wycats/thor/issues/100 # print_table rows puts rows.join("\n") say "#{rows.length - 1} entries.", :cyan end end end |
#update(groupname) ⇒ Object
67 68 69 |
# File 'lib/gtool/provision/group.rb', line 67 def update(groupname) say "#{self.class}#update not implemented!", :yellow end |