This repository has been archived by the owner on Apr 14, 2018. It is now read-only.
/
orgunit.rb
69 lines (56 loc) · 2.2 KB
/
orgunit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'thor'
require 'gtool'
require 'gdata'
module Gtool
module Provision
class OrgUnit < Thor
Gtool::CLI.register self, "orgunit", "orgunit [COMMAND]", "GData user provisioning"
namespace :orgunit
class_option "debug", :type => :boolean, :desc => "Enable debug output", :aliases => "-d"
class_option "noop", :type => :boolean, :desc => "Enable noop mode", :aliases => "-n"
desc "list", "List organizational units"
def list
connection = Gtool::Auth.connection(options)
orgunits = GData::Provision::OrgUnit.all(connection)
fields = GData::Provision::OrgUnit.attribute_names
field_names = GData::Provision::OrgUnit.attribute_titles
rows = orgunits.map do |orgunit|
fields.map {|f| orgunit.send f}
end
rows.unshift field_names
print_table rows
say "#{rows.length - 1} entries.", :cyan
end
desc "get ORGUNIT", "Get an orgunit"
def get(orgunit_name)
connection = Gtool::Auth.connection(options)
orgunit = GData::Provision::OrgUnit.get(connection, orgunit_name)
fields = GData::Provision::OrgUnit.attribute_names
field_names = GData::Provision::OrgUnit.attribute_titles
if orgunit.nil?
say "Organizational unit '#{orgunit_name}' not found!", :red
else
properties = fields.map {|f| orgunit.send f}
print_table field_names.zip(properties)
end
end
desc "members ORGUNIT", "Get the members of an orgunit"
def members(orgunit_name)
connection = Gtool::Auth.connection(options)
orgunit = GData::Provision::OrgUnit.get(connection, orgunit_name)
fields = GData::Provision::OrgMember.attribute_names
field_names = GData::Provision::OrgMember.attribute_titles
members = orgunit.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
def self.banner(task, namespace = true, subcommand = false)
"#{basename} #{task.formatted_usage(self, true, subcommand)}"
end
end
end
end