jgrouper 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +78 -62
- data/README.rdoc +11 -2
- data/bin/jgrouper-export +44 -3
- data/lib/jgrouper/exporter.rb +36 -37
- data/lib/jgrouper/field.rb +54 -0
- data/lib/jgrouper/group.rb +75 -2
- data/lib/jgrouper/group_type.rb +87 -0
- data/lib/jgrouper/member.rb +1 -1
- data/lib/jgrouper/source.rb +63 -0
- data/lib/jgrouper/stem.rb +53 -2
- data/lib/jgrouper/subject.rb +13 -0
- data/lib/jgrouper/version.rb +1 -1
- data/lib/jgrouper.rb +23 -2
- metadata +5 -2
data/HISTORY.md
CHANGED
|
@@ -1,46 +1,62 @@
|
|
|
1
1
|
JGrouper History
|
|
2
2
|
================
|
|
3
3
|
|
|
4
|
+
2013-08-15 JGrouper v0.5.0
|
|
5
|
+
--------------------------
|
|
6
|
+
* Add `JGrouper.start_root_session()`
|
|
7
|
+
* Add `JGrouper::Field`
|
|
8
|
+
* Add `JGrouper::Group#to_hash()`
|
|
9
|
+
* Add `JGrouper::Group#to_hash()`
|
|
10
|
+
* Add `JGrouper::GroupType`
|
|
11
|
+
* Add `JGrouper::Source`
|
|
12
|
+
* Add `JGrouper::Stem#root?()`
|
|
13
|
+
* Add `JGrouper::Stem#to_yaml()`
|
|
14
|
+
* Add `JGrouper::Stem#to_yaml()`
|
|
15
|
+
* Add `JGrouper::Subject#to_hash()`
|
|
16
|
+
* Add `JGrouper::Subject#to_yaml()`
|
|
17
|
+
* Update `JGrouper::Export` and `bin/jgrouper-export` to export to YAML
|
|
18
|
+
|
|
19
|
+
|
|
4
20
|
2013-07-18 JGrouper v0.4.2
|
|
5
21
|
--------------------------
|
|
6
|
-
* Fix
|
|
22
|
+
* Fix `JGrouper::AuditArchiver` end-of-day calculation
|
|
7
23
|
|
|
8
24
|
|
|
9
25
|
2013-07-18 JGrouper v0.4.1
|
|
10
26
|
--------------------------
|
|
11
|
-
* Update
|
|
12
|
-
* Update
|
|
27
|
+
* Update `JGrouper::AuditArchiver` to detect re-archive attempts and increment date
|
|
28
|
+
* Update `JGrouper::AuditArchiver` earliest entry detection (again)
|
|
13
29
|
|
|
14
30
|
|
|
15
31
|
2013-07-05 JGrouper v0.4.0
|
|
16
32
|
--------------------------
|
|
17
|
-
* Add
|
|
33
|
+
* Add `--batch-size NUMBER` to `jgrouper-audit-archiver`
|
|
18
34
|
* Add more code examples
|
|
19
|
-
* Update
|
|
20
|
-
* Update
|
|
21
|
-
* Update
|
|
22
|
-
* Update
|
|
35
|
+
* Update `JGrouper::AuditArchiver` to append to output files
|
|
36
|
+
* Update `JGrouper::AuditArchiver` to lock output file
|
|
37
|
+
* Update `JGrouper::AuditArchiver` to prune from database in batches to better support large datasets
|
|
38
|
+
* Update `JGrouper::AuditArchiver` earliest entry detection
|
|
23
39
|
|
|
24
40
|
|
|
25
41
|
2013-06-27 JGrouper v0.3.0
|
|
26
42
|
--------------------------
|
|
27
|
-
* Add
|
|
28
|
-
* Add
|
|
29
|
-
* Add
|
|
30
|
-
* Add
|
|
31
|
-
* Add
|
|
32
|
-
* Add
|
|
33
|
-
* Improve
|
|
34
|
-
* Fix various
|
|
35
|
-
* Fix
|
|
36
|
-
* Fix
|
|
43
|
+
* Add `bin/jgrouper-grant`
|
|
44
|
+
* Add `JGrouper::Group.find()`
|
|
45
|
+
* Add `JGrouper::Group.grant()`
|
|
46
|
+
* Add `JGrouper::Privilege`
|
|
47
|
+
* Add `JGrouper::Stem.grant()`
|
|
48
|
+
* Add `JGrouper::Subject`
|
|
49
|
+
* Improve `JGrouper::Stem.find()` error handling
|
|
50
|
+
* Fix various `to_s` bugs
|
|
51
|
+
* Fix `JGrouper::Member.find()` error handling
|
|
52
|
+
* Fix `JGrouper::Stem.stems()`
|
|
37
53
|
|
|
38
54
|
|
|
39
55
|
2013-05-17 JGrouper v0.2.0
|
|
40
56
|
--------------------------
|
|
41
|
-
* Add
|
|
42
|
-
* Add
|
|
43
|
-
* Add
|
|
57
|
+
* Add `-d directory` option to `jgrouper-audit-archiver`
|
|
58
|
+
* Add `-n number of days` option to `jgrouper-audit-archiver`
|
|
59
|
+
* Add `-S stop date` option to `jgrouper-audit-archiver`
|
|
44
60
|
|
|
45
61
|
|
|
46
62
|
2013-05-15 JGrouper v0.1.1
|
|
@@ -52,65 +68,65 @@ JGrouper History
|
|
|
52
68
|
--------------------------
|
|
53
69
|
Starting over with a more clear design in mind.
|
|
54
70
|
|
|
55
|
-
* Add
|
|
56
|
-
* Add
|
|
57
|
-
* Add
|
|
58
|
-
* Add
|
|
59
|
-
* Add
|
|
60
|
-
* Add
|
|
61
|
-
* Add
|
|
62
|
-
* Add
|
|
63
|
-
* Add
|
|
64
|
-
* Add
|
|
65
|
-
* Add
|
|
66
|
-
* Add
|
|
67
|
-
* Add
|
|
71
|
+
* Add `bin/jgrouper-audit-archiver`
|
|
72
|
+
* Add `bin/jgrouper-export`
|
|
73
|
+
* Add `JGrouper.home!()`
|
|
74
|
+
* Add `JGrouper::AuditArchiver`
|
|
75
|
+
* Add `JGrouper::Exporter`
|
|
76
|
+
* Add `JGrouper::Group`
|
|
77
|
+
* Add `JGrouper::Member`
|
|
78
|
+
* Add `JGrouper::Member.find()`
|
|
79
|
+
* Add `JGrouper::Stem`
|
|
80
|
+
* Add `JGrouper::Stem.find()`
|
|
81
|
+
* Add `JGrouper::Stem#groups()`
|
|
82
|
+
* Add `JGrouper::Stem.root()`
|
|
83
|
+
* Add `JGrouper::Stem#stems()`
|
|
68
84
|
|
|
69
85
|
|
|
70
86
|
2012-11-20 JGrouper v0.0.5
|
|
71
87
|
--------------------------
|
|
72
|
-
* Add
|
|
73
|
-
* Add
|
|
74
|
-
* Add
|
|
75
|
-
* Add
|
|
76
|
-
* Add
|
|
77
|
-
* Add
|
|
78
|
-
* Add
|
|
79
|
-
* Fix
|
|
88
|
+
* Add `JGrouper::Group#add_type`
|
|
89
|
+
* Add `JGrouper::Group#delete_type`
|
|
90
|
+
* Add `JGrouper::Group#method_missing`
|
|
91
|
+
* Add `JGrouper::Group#types`
|
|
92
|
+
* Add `JGrouper::GroupType#method_missing`
|
|
93
|
+
* Add `JGrouper::Stem#method_missing`
|
|
94
|
+
* Add `JGrouper::Subject#method_missing`
|
|
95
|
+
* Fix `JGrouper::Group` tests
|
|
80
96
|
|
|
81
97
|
|
|
82
98
|
2012-10-04 JGrouper v0.0.4
|
|
83
99
|
--------------------------
|
|
84
|
-
* Add
|
|
85
|
-
* Add
|
|
86
|
-
* Add
|
|
87
|
-
* Extracted
|
|
100
|
+
* Add `JGrouper::Group`
|
|
101
|
+
* Add `JGrouper::Group.find`
|
|
102
|
+
* Add `JGrouper::Group` support to `JGrouper::Shell`
|
|
103
|
+
* Extracted `JGrouper::Shell` to its own gem
|
|
88
104
|
|
|
89
105
|
|
|
90
106
|
2012-08-17 JGrouper v0.0.3
|
|
91
107
|
--------------------------
|
|
92
|
-
* Add
|
|
93
|
-
* Add
|
|
94
|
-
* Rename
|
|
95
|
-
* Rename
|
|
96
|
-
* Add
|
|
97
|
-
* Add
|
|
98
|
-
* Add
|
|
99
|
-
* Add
|
|
100
|
-
* Add
|
|
101
|
-
* Add
|
|
102
|
-
* Add
|
|
108
|
+
* Add `JGrouper::Shell`
|
|
109
|
+
* Add `bin/jgrouper` interactive shell
|
|
110
|
+
* Rename `JGrouper::Stem#root_stem` to `JGrouper::Stem#root`
|
|
111
|
+
* Rename `JGrouper::Subject#root_subject` to `JGrouper::Subject#root`
|
|
112
|
+
* Add `JGrouper::GroupType.delete(name)`
|
|
113
|
+
* Add `JGrouper::Stem.create( name, display_name = nil )`
|
|
114
|
+
* Add `JGrouper::Stem#add_stem( name, display_name = nil )`
|
|
115
|
+
* Add `JGrouper::Stem.find(name)`
|
|
116
|
+
* Add `JGrouper::Subject::TestCase`
|
|
117
|
+
* Add `JGrouper::GroupType::TestCase`
|
|
118
|
+
* Add `JGrouper::Stem::TestCase`
|
|
103
119
|
|
|
104
120
|
|
|
105
121
|
2012-08-10 JGrouper v0.0.2
|
|
106
122
|
--------------------------
|
|
107
|
-
* Add
|
|
108
|
-
* Add
|
|
109
|
-
* Add
|
|
123
|
+
* Add `JGrouper::GroupType`
|
|
124
|
+
* Add `JGrouper::Stem#to_json`
|
|
125
|
+
* Add `JGrouper::Subject#to_json`
|
|
110
126
|
|
|
111
127
|
|
|
112
128
|
2012-08-10 JGrouper v0.0.1
|
|
113
129
|
--------------------------
|
|
114
|
-
* Add
|
|
115
|
-
* Add
|
|
130
|
+
* Add `JGrouper::Stem.root_stem`
|
|
131
|
+
* Add `JGrouper::Subject.root_subject`
|
|
116
132
|
|
data/README.rdoc
CHANGED
|
@@ -71,15 +71,24 @@
|
|
|
71
71
|
archiver.archive { |entry| ... audit log entry being archived ... }
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
+
=== Exporter
|
|
75
|
+
|
|
76
|
+
require 'jgrouper'
|
|
77
|
+
require 'jgrouper/exporter'
|
|
78
|
+
|
|
79
|
+
JGrouper::Exporter do |exporter|
|
|
80
|
+
exporter.export 'stem:to:export', lambda { |_| puts _.to_yaml }
|
|
81
|
+
end
|
|
82
|
+
|
|
74
83
|
=== Scripts
|
|
75
84
|
|
|
76
85
|
Archive Grouper audit log entries to disk:
|
|
77
86
|
|
|
78
87
|
% jgrouper-audit-archiver -h
|
|
79
88
|
|
|
80
|
-
Export
|
|
89
|
+
Export Groups registry to YAML:
|
|
81
90
|
|
|
82
|
-
% jgrouper-
|
|
91
|
+
% jgrouper-export -h
|
|
83
92
|
|
|
84
93
|
Grant privileges:
|
|
85
94
|
|
data/bin/jgrouper-export
CHANGED
|
@@ -3,19 +3,26 @@
|
|
|
3
3
|
require 'jgrouper'
|
|
4
4
|
require 'jgrouper/exporter'
|
|
5
5
|
require 'optparse'
|
|
6
|
+
require 'thread'
|
|
7
|
+
require 'yaml'
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
JGrouper::Exporter.new do |exporter|
|
|
9
11
|
|
|
12
|
+
directory = Dir.pwd
|
|
13
|
+
|
|
10
14
|
opts = OptionParser.new do |opts|
|
|
11
15
|
opts.banner = "USAGE: #{ File.basename(__FILE__) } [-h]"
|
|
12
16
|
|
|
17
|
+
opts.on( '-d', '--directory DIR', 'Write output to this directory [DEFAULT: .]' ) do |value|
|
|
18
|
+
directory = value
|
|
19
|
+
end
|
|
13
20
|
opts.on_tail('-h', '--help', "Show this message") do
|
|
14
21
|
puts opts
|
|
15
22
|
exit
|
|
16
23
|
end
|
|
17
|
-
opts.on_tail( '-v', '--[no-]verbose', 'Enable verbose mode [DEFAULT: no]' ) do |
|
|
18
|
-
exporter.verbose =
|
|
24
|
+
opts.on_tail( '-v', '--[no-]verbose', 'Enable verbose mode [DEFAULT: no]' ) do |value|
|
|
25
|
+
exporter.verbose = value
|
|
19
26
|
end
|
|
20
27
|
end.parse!
|
|
21
28
|
|
|
@@ -27,7 +34,41 @@ JGrouper::Exporter.new do |exporter|
|
|
|
27
34
|
exit 1
|
|
28
35
|
end
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
raise "ERROR: directory does not exist - #{directory}" unless File.directory?(directory)
|
|
38
|
+
|
|
39
|
+
done = false
|
|
40
|
+
queue = Queue.new
|
|
41
|
+
|
|
42
|
+
Thread.abort_on_exception = true
|
|
43
|
+
consumer = Thread.new do
|
|
44
|
+
JGrouper.start_root_session
|
|
45
|
+
|
|
46
|
+
# TODO GzipWriter?
|
|
47
|
+
fn = File.join directory, 'jgrouper-export.yaml'
|
|
48
|
+
File.open( fn, 'w' ) do |fh|
|
|
49
|
+
fh.flock File::LOCK_EX
|
|
50
|
+
|
|
51
|
+
loop do
|
|
52
|
+
while queue.size > 0
|
|
53
|
+
value = queue.pop
|
|
54
|
+
fh.puts value.to_yaml
|
|
55
|
+
end
|
|
56
|
+
if done && queue.empty?
|
|
57
|
+
break
|
|
58
|
+
end
|
|
59
|
+
sleep 0.1
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
fh.flock File::LOCK_UN
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
producer = Thread.new do
|
|
66
|
+
exporter.export base: ARGV.shift, block: lambda { |_| queue << _ ; sleep 0.1 if queue.size > 100 }
|
|
67
|
+
done = true
|
|
68
|
+
Thread.stop
|
|
69
|
+
end
|
|
70
|
+
consumer.join
|
|
71
|
+
|
|
31
72
|
end
|
|
32
73
|
|
|
33
74
|
# vim: syntax=ruby
|
data/lib/jgrouper/exporter.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require 'csv'
|
|
2
1
|
|
|
3
2
|
module JGrouper # :nodoc:
|
|
4
3
|
#
|
|
5
|
-
# = JGrouper::Exporter - Export
|
|
4
|
+
# = JGrouper::Exporter - Export Groups registry.
|
|
6
5
|
#
|
|
7
6
|
# == USAGE
|
|
8
7
|
#
|
|
@@ -10,7 +9,7 @@ module JGrouper # :nodoc:
|
|
|
10
9
|
# require 'jgrouper/exporter'
|
|
11
10
|
#
|
|
12
11
|
# JGrouper::Exporter do |exporter|
|
|
13
|
-
# exporter.export 'stem:to:export'
|
|
12
|
+
# exporter.export 'stem:to:export', lambda { |_| puts _.to_yaml }
|
|
14
13
|
# end
|
|
15
14
|
#
|
|
16
15
|
class Exporter
|
|
@@ -18,55 +17,55 @@ module JGrouper # :nodoc:
|
|
|
18
17
|
attr_writer :verbose
|
|
19
18
|
|
|
20
19
|
def initialize
|
|
21
|
-
@
|
|
22
|
-
@fh = nil
|
|
23
|
-
@verbose = false
|
|
20
|
+
@verbose = false
|
|
24
21
|
yield self if block_given?
|
|
25
22
|
self
|
|
26
23
|
end
|
|
27
24
|
|
|
28
25
|
#
|
|
29
|
-
# Export
|
|
26
|
+
# Export Groups registry.
|
|
30
27
|
#
|
|
31
|
-
def export(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
def export(params)
|
|
29
|
+
stem = params[:base] ? Stem.find( params[:base] ) : Stem.root
|
|
30
|
+
raise "ERROR: stem not found" if stem.nil?
|
|
31
|
+
raise "ERROR: :block not specified" unless params[:block]
|
|
32
|
+
raise "ERROR: :block is not a block" unless params[:block].kind_of?(Proc)
|
|
33
|
+
|
|
34
|
+
# TODO Multiple readers?
|
|
35
|
+
txt = stem.root? ? 'root stem' : "stem #{stem.name}"
|
|
36
|
+
log "exporting #{txt} ..."
|
|
37
|
+
if stem.root? # TODO Configurable?
|
|
38
|
+
export_group_types params[:block]
|
|
39
|
+
export_sources params[:block]
|
|
40
|
+
end
|
|
41
|
+
export_stem stem, params[:block]
|
|
42
|
+
log "exporting #{txt} - done"
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
g = %w( display_extension extension name ).collect { |k| child.send(k) }
|
|
43
|
-
g << CSV.generate_line( child.members.collect { |m| "#{ m.subject_source_id }|#{ m.subject_type_id }|#{ m.subject_id }" } ).chomp
|
|
44
|
+
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
# Export group types.
|
|
47
|
+
def export_group_types(p)
|
|
48
|
+
log 'exporting group types ...'
|
|
49
|
+
p.call JGrouper::GroupType
|
|
50
|
+
end
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
# Export subject sources.
|
|
53
|
+
def export_sources(p)
|
|
54
|
+
log 'exporting subject sources ...'
|
|
55
|
+
p.call JGrouper::Source
|
|
56
|
+
end
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
# Export stem and childen.
|
|
59
|
+
def export_stem( stem, p )
|
|
60
|
+
log "exporting stem #{stem.name} ..."
|
|
61
|
+
p.call stem
|
|
62
|
+
stem.groups { |child| p.call child }
|
|
63
|
+
stem.stems { |child| export_stem(child, p) }
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
|
|
57
67
|
private
|
|
58
68
|
|
|
59
|
-
#
|
|
60
|
-
# Open filehandle for writing or raise exception if a) directory does not exist or b) file does exist.
|
|
61
|
-
# TODO DRY
|
|
62
|
-
#
|
|
63
|
-
def filehandle(directory, file)
|
|
64
|
-
raise "ERROR: directory does not exist - #{directory}" unless File.directory?(directory)
|
|
65
|
-
fn = File.join directory, file
|
|
66
|
-
raise "ERROR: file already exists - #{fn}" if File.exists?(fn)
|
|
67
|
-
File.open(fn, 'w') { |fh| @fh = fh ; yield self ; @fh = nil }
|
|
68
|
-
end
|
|
69
|
-
|
|
70
69
|
# TODO Use Logger...
|
|
71
70
|
# TODO DRY
|
|
72
71
|
def log(msg)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
module JGrouper # :nodoc:
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# = JGrouper::Field - Grouper Group Field
|
|
6
|
+
#
|
|
7
|
+
# == Usage
|
|
8
|
+
#
|
|
9
|
+
# require 'jgrouper'
|
|
10
|
+
#
|
|
11
|
+
# TODO
|
|
12
|
+
#
|
|
13
|
+
class Field
|
|
14
|
+
|
|
15
|
+
def initialize( obj = nil )
|
|
16
|
+
@obj = obj
|
|
17
|
+
yield self if block_given?
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# For passing methods on to Grouper Field object.
|
|
23
|
+
#
|
|
24
|
+
def method_missing(meth, *args, &block)
|
|
25
|
+
super if @obj.nil?
|
|
26
|
+
begin
|
|
27
|
+
block.call @obj.send(meth, *args) if block
|
|
28
|
+
@obj.send(meth, *args)
|
|
29
|
+
rescue NoMethodError
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_hash
|
|
35
|
+
{
|
|
36
|
+
'kind' => 'field',
|
|
37
|
+
'name' => @obj.get_name,
|
|
38
|
+
'uuid' => @obj.get_uuid,
|
|
39
|
+
'nullable' => @obj.get_is_nullable,
|
|
40
|
+
'required' => @obj.get_required,
|
|
41
|
+
'privilege' => {
|
|
42
|
+
'read' => @obj.get_read_privilege,
|
|
43
|
+
'write' => @obj.get_write_privilege
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to_yaml
|
|
49
|
+
to_hash.to_yaml
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
data/lib/jgrouper/group.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require 'csv'
|
|
2
1
|
|
|
3
2
|
module JGrouper # :nodoc:
|
|
4
3
|
|
|
@@ -24,7 +23,7 @@ module JGrouper # :nodoc:
|
|
|
24
23
|
#
|
|
25
24
|
def self.find(name)
|
|
26
25
|
begin
|
|
27
|
-
obj = JGroupFinder.find_by_name
|
|
26
|
+
obj = JGroupFinder.find_by_name JGrouper.start_root_session, name, false
|
|
28
27
|
rescue => e
|
|
29
28
|
warn "JGrouper::Group.find(#{name}) => #{e}"
|
|
30
29
|
end
|
|
@@ -51,11 +50,85 @@ module JGrouper # :nodoc:
|
|
|
51
50
|
end
|
|
52
51
|
end
|
|
53
52
|
|
|
53
|
+
def to_hash
|
|
54
|
+
begin
|
|
55
|
+
mod_subj = JGrouper::Subject.new( @obj.get_modify_subject )
|
|
56
|
+
rescue edu.internet2.middleware.subject.SubjectNotFoundException
|
|
57
|
+
mod_subj = nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
hash = {
|
|
61
|
+
'kind' => 'group',
|
|
62
|
+
'uuid' => @obj.get_uuid,
|
|
63
|
+
'name' => @obj.get_name,
|
|
64
|
+
'display_name' => @obj.get_display_name,
|
|
65
|
+
'extension' => @obj.get_extension,
|
|
66
|
+
'display_extension' => @obj.get_display_extension,
|
|
67
|
+
'description' => @obj.get_description,
|
|
68
|
+
'parent' => {
|
|
69
|
+
'name' => @obj.get_parent_stem_name,
|
|
70
|
+
'uuid' => @obj.get_parent_uuid,
|
|
71
|
+
},
|
|
72
|
+
'create' => {
|
|
73
|
+
'subject' => JGrouper::Subject.new( @obj.get_create_subject ).to_hash,
|
|
74
|
+
'time' => Time.at( @obj.get_create_time_long / 1000 ).to_datetime.rfc3339
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
begin
|
|
79
|
+
mod_subj = JGrouper::Subject.new( @obj.get_modify_subject )
|
|
80
|
+
hash['modify'] = {
|
|
81
|
+
'subject' => mod_subj ? mod_subj.to_hash : nil,
|
|
82
|
+
'time' => Time.at( @obj.get_modify_time_long / 1000 ).to_datetime.rfc3339
|
|
83
|
+
}
|
|
84
|
+
rescue
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# TODO Ugly
|
|
88
|
+
unless @obj.get_admins.empty? &&
|
|
89
|
+
@obj.get_optins.empty? &&
|
|
90
|
+
@obj.get_optouts.empty? &&
|
|
91
|
+
@obj.get_readers.empty? &&
|
|
92
|
+
@obj.get_updaters.empty &&
|
|
93
|
+
@obj.get_viewers.empty?
|
|
94
|
+
hash['privileges'] = {}
|
|
95
|
+
hash['privileges']['admin'] = @obj.get_admins.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_admins.empty?
|
|
96
|
+
hash['privileges']['optin'] = @obj.get_optins.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_optins.empty?
|
|
97
|
+
hash['privileges']['optout'] = @obj.get_optouts.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_optouts.empty?
|
|
98
|
+
hash['privileges']['read'] = @obj.get_readers.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_readers.empty?
|
|
99
|
+
hash['privileges']['update'] = @obj.get_updaters.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_updaters.empty?
|
|
100
|
+
hash['privileges']['view'] = @obj.get_viewers.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_viewers.empty?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
hash['types'] = @obj.get_removable_types.collect { |_| { 'name' => _.get_name, 'uuid' => _.get_uuid } } unless @obj.get_removable_types.empty?
|
|
104
|
+
hash['attributes'] = @obj.get_attributes_map(false).inject({}) { |h, (k,v)| h[k] = v.get_value ; h } unless @obj.get_attributes_map(false).empty?
|
|
105
|
+
hash['alternate_names'] = @obj.get_alternate_names.collect { |_| _ } unless @obj.get_alternate_names.empty?
|
|
106
|
+
|
|
107
|
+
hash['role'] = 'role' if 'role' == @obj.get_type_of_group.to_string
|
|
108
|
+
|
|
109
|
+
composite = @obj.get_composite(false)
|
|
110
|
+
if composite
|
|
111
|
+
hash['composite'] = {
|
|
112
|
+
'type' => composite.get_type.get_name,
|
|
113
|
+
'left' => { 'name' => composite.get_left_group.get_name, 'uuid' => composite.get_left_group.get_uuid },
|
|
114
|
+
'right' => { 'name' => composite.get_right_group.get_name, 'uuid' => composite.get_right_group.get_uuid }
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
hash['members'] = @obj.get_immediate_members.collect { |_| JGrouper::Subject.new( _.get_subject ).to_hash } unless @obj.get_immediate_members.empty?
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
hash
|
|
121
|
+
end
|
|
122
|
+
|
|
54
123
|
def to_s
|
|
55
124
|
return nil if @obj.nil?
|
|
56
125
|
%w( name display_name uuid ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp
|
|
57
126
|
end
|
|
58
127
|
|
|
128
|
+
def to_yaml
|
|
129
|
+
to_hash.to_yaml
|
|
130
|
+
end
|
|
131
|
+
|
|
59
132
|
end
|
|
60
133
|
end
|
|
61
134
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
|
|
2
|
+
module JGrouper # :nodoc:
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# = JGrouper::GroupType - Grouper Group Type
|
|
6
|
+
#
|
|
7
|
+
# == Usage
|
|
8
|
+
#
|
|
9
|
+
# require 'jgrouper'
|
|
10
|
+
#
|
|
11
|
+
# TODO
|
|
12
|
+
#
|
|
13
|
+
class GroupType
|
|
14
|
+
|
|
15
|
+
def initialize( obj = nil )
|
|
16
|
+
@obj = obj
|
|
17
|
+
yield self if block_given?
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Find all group types.
|
|
23
|
+
#
|
|
24
|
+
def self.all
|
|
25
|
+
JGroupTypeFinder.find_all.collect { |_| self.new _ }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Find group type by name. Returns +JGrouper::GroupType+ or +nil+.
|
|
30
|
+
#
|
|
31
|
+
def self.find(name)
|
|
32
|
+
begin
|
|
33
|
+
obj = JGroupTypeFinder.find name, false
|
|
34
|
+
rescue => e
|
|
35
|
+
warn "JGrouper::GroupType.find(#{name}) => #{e}"
|
|
36
|
+
end
|
|
37
|
+
return nil if obj.nil?
|
|
38
|
+
group_type = self.new obj
|
|
39
|
+
yield group_type if block_given?
|
|
40
|
+
group_type
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#
|
|
44
|
+
# For passing methods on to Grouper GroupType object.
|
|
45
|
+
#
|
|
46
|
+
def method_missing(meth, *args, &block)
|
|
47
|
+
super if @obj.nil?
|
|
48
|
+
begin
|
|
49
|
+
block.call @obj.send(meth, *args) if block
|
|
50
|
+
@obj.send(meth, *args)
|
|
51
|
+
rescue NoMethodError
|
|
52
|
+
super
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_hash
|
|
57
|
+
hash = {
|
|
58
|
+
'kind' => 'group_type',
|
|
59
|
+
'name' => @obj.get_name,
|
|
60
|
+
'uuid' => @obj.get_uuid,
|
|
61
|
+
'assignable' => @obj.get_is_assignable,
|
|
62
|
+
'internal' => @obj.get_is_internal,
|
|
63
|
+
'create' => {
|
|
64
|
+
'uuid' => @obj.get_creator_uuid,
|
|
65
|
+
'time' => Time.at( @obj.get_create_time / 1000 ).to_datetime.rfc3339
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
unless @obj.get_fields.empty?
|
|
69
|
+
hash['fields'] = @obj.get_fields.collect { |_| JGrouper::Field.new(_).to_hash }
|
|
70
|
+
end
|
|
71
|
+
hash
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.to_yaml
|
|
75
|
+
{
|
|
76
|
+
'kind' => 'group_types',
|
|
77
|
+
'group_types' => all.collect { |_| self.new(_).to_hash }
|
|
78
|
+
}.to_yaml
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def to_yaml
|
|
82
|
+
to_hash.to_yaml
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
data/lib/jgrouper/member.rb
CHANGED
|
@@ -23,7 +23,7 @@ module JGrouper # :nodoc:
|
|
|
23
23
|
#
|
|
24
24
|
def self.find(uuid)
|
|
25
25
|
begin
|
|
26
|
-
m = MemberFinder.find_by_uuid
|
|
26
|
+
m = MemberFinder.find_by_uuid JGrouper.start_root_session, uuid, false
|
|
27
27
|
rescue => e
|
|
28
28
|
warn "JGrouper::Member.find(#{uuid}) => #{e}"
|
|
29
29
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
module JGrouper # :nodoc:
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# = JGrouper::Source - Grouper Subject Source
|
|
6
|
+
#
|
|
7
|
+
# == Usage
|
|
8
|
+
#
|
|
9
|
+
# require 'jgrouper'
|
|
10
|
+
#
|
|
11
|
+
# TODO
|
|
12
|
+
#
|
|
13
|
+
class Source
|
|
14
|
+
|
|
15
|
+
def initialize( obj = nil )
|
|
16
|
+
@obj = obj
|
|
17
|
+
yield self if block_given?
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Find all subject sources.
|
|
23
|
+
#
|
|
24
|
+
def self.all
|
|
25
|
+
JSourceManager.get_instance.get_sources.collect { |_| self.new _ }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# For passing methods on to Grouper Source object.
|
|
30
|
+
#
|
|
31
|
+
def method_missing(meth, *args, &block)
|
|
32
|
+
super if @obj.nil?
|
|
33
|
+
begin
|
|
34
|
+
block.call @obj.send(meth, *args) if block
|
|
35
|
+
@obj.send(meth, *args)
|
|
36
|
+
rescue NoMethodError
|
|
37
|
+
super
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_hash
|
|
42
|
+
{
|
|
43
|
+
'kind' => 'source',
|
|
44
|
+
'id' => @obj.get_id,
|
|
45
|
+
'name' => @obj.get_name,
|
|
46
|
+
'init_params' => @obj.get_init_params.inject({}) { |h, (k,v)| h[k] = v ; h }
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.to_yaml
|
|
51
|
+
{
|
|
52
|
+
'kind' => 'sources',
|
|
53
|
+
'sources' => all.collect { |_| self.new(_).to_hash }
|
|
54
|
+
}.to_yaml
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def to_yaml
|
|
58
|
+
to_hash.to_yaml
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
data/lib/jgrouper/stem.rb
CHANGED
|
@@ -24,7 +24,7 @@ module JGrouper # :nodoc:
|
|
|
24
24
|
#
|
|
25
25
|
def self.find(name)
|
|
26
26
|
begin
|
|
27
|
-
obj = StemFinder.find_by_name
|
|
27
|
+
obj = StemFinder.find_by_name JGrouper.start_root_session, name, false
|
|
28
28
|
rescue => e
|
|
29
29
|
warn "JGrouper::Group.find(#{name}) => #{e}"
|
|
30
30
|
end
|
|
@@ -66,13 +66,20 @@ module JGrouper # :nodoc:
|
|
|
66
66
|
# Find Grouper root stem. Returns +JGrouper::Stem+ or +nil+.
|
|
67
67
|
#
|
|
68
68
|
def self.root
|
|
69
|
-
obj = StemFinder.find_root_stem
|
|
69
|
+
obj = StemFinder.find_root_stem JGrouper.start_root_session
|
|
70
70
|
return nil if obj.nil?
|
|
71
71
|
stem = self.new obj
|
|
72
72
|
yield stem if block_given?
|
|
73
73
|
stem
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
#
|
|
77
|
+
# Is this the root stem?
|
|
78
|
+
#
|
|
79
|
+
def root?
|
|
80
|
+
name.empty?
|
|
81
|
+
end
|
|
82
|
+
|
|
76
83
|
#
|
|
77
84
|
# Yield child stems.
|
|
78
85
|
#
|
|
@@ -84,11 +91,55 @@ module JGrouper # :nodoc:
|
|
|
84
91
|
end
|
|
85
92
|
end
|
|
86
93
|
|
|
94
|
+
def to_hash
|
|
95
|
+
hash = {
|
|
96
|
+
'kind' => 'stem',
|
|
97
|
+
'uuid' => @obj.get_uuid,
|
|
98
|
+
'name' => @obj.get_name,
|
|
99
|
+
'display_name' => @obj.get_display_name,
|
|
100
|
+
'extension' => @obj.get_extension,
|
|
101
|
+
'display_extension' => @obj.get_display_extension
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
hash['description'] = @obj.get_description unless @obj.get_description.empty?
|
|
105
|
+
|
|
106
|
+
hash['create'] = {
|
|
107
|
+
'subject' => JGrouper::Subject.new( @obj.get_create_subject ).to_hash,
|
|
108
|
+
'time' => Time.at( @obj.get_create_time_long / 1000 ).to_datetime.rfc3339
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
begin
|
|
112
|
+
mod_subj = JGrouper::Subject.new( @obj.get_modify_subject )
|
|
113
|
+
hash['modify'] = {
|
|
114
|
+
'subject' => mod_subj ? mod_subj.to_hash : nil,
|
|
115
|
+
'time' => Time.at( @obj.get_modify_time_long / 1000 ).to_datetime.rfc3339
|
|
116
|
+
}
|
|
117
|
+
rescue
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
unless @obj.get_creators.empty? && @obj.get_stemmers.empty?
|
|
121
|
+
hash['privileges'] = {}
|
|
122
|
+
hash['privileges']['create'] = @obj.get_creators.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_creators.empty?
|
|
123
|
+
hash['privileges']['stem'] = @obj.get_stemmers.collect { |_| JGrouper::Subject.new(_).to_hash } unless @obj.get_stemmers.empty?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
hash['stems'] = @obj.child_stems.collect { |_| { 'name' => _.get_name, 'uuid' => _.get_uuid } } unless @obj.child_stems.empty?
|
|
127
|
+
hash['groups'] = @obj.child_groups.collect { |_| { 'name' => _.get_name, 'uuid' => _.get_uuid } } unless @obj.child_groups.empty?
|
|
128
|
+
|
|
129
|
+
hash['parent'] = { 'name' => @obj.get_parent_stem.get_name, 'uuid' => @obj.get_parent_uuid } unless root?
|
|
130
|
+
|
|
131
|
+
hash
|
|
132
|
+
end
|
|
133
|
+
|
|
87
134
|
def to_s
|
|
88
135
|
return nil if @obj.nil?
|
|
89
136
|
%w( name display_name uuid ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp
|
|
90
137
|
end
|
|
91
138
|
|
|
139
|
+
def to_yaml
|
|
140
|
+
to_hash.to_yaml
|
|
141
|
+
end
|
|
142
|
+
|
|
92
143
|
end
|
|
93
144
|
end
|
|
94
145
|
|
data/lib/jgrouper/subject.rb
CHANGED
|
@@ -48,11 +48,24 @@ module JGrouper # :nodoc:
|
|
|
48
48
|
|
|
49
49
|
def to_grouper; @obj; end
|
|
50
50
|
|
|
51
|
+
def to_hash
|
|
52
|
+
{
|
|
53
|
+
'kind' => 'subject',
|
|
54
|
+
'id' => @obj.get_id,
|
|
55
|
+
'source' => @obj.get_source_id,
|
|
56
|
+
'type' => @obj.get_type_name
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
|
|
51
60
|
def to_s
|
|
52
61
|
return nil if @obj.nil?
|
|
53
62
|
%w( id type_name source_id name ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp
|
|
54
63
|
end
|
|
55
64
|
|
|
65
|
+
def to_yaml
|
|
66
|
+
to_hash.to_yaml
|
|
67
|
+
end
|
|
68
|
+
|
|
56
69
|
end
|
|
57
70
|
end
|
|
58
71
|
|
data/lib/jgrouper/version.rb
CHANGED
data/lib/jgrouper.rb
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
require 'java'
|
|
2
2
|
|
|
3
|
+
require 'jgrouper/field'
|
|
3
4
|
require 'jgrouper/group'
|
|
5
|
+
require 'jgrouper/group_type'
|
|
4
6
|
require 'jgrouper/member'
|
|
5
7
|
require 'jgrouper/privilege'
|
|
8
|
+
require 'jgrouper/source'
|
|
6
9
|
require 'jgrouper/stem'
|
|
7
10
|
require 'jgrouper/subject'
|
|
8
11
|
require 'jgrouper/version'
|
|
@@ -81,15 +84,24 @@ require 'jgrouper/version'
|
|
|
81
84
|
# archiver.archive { |entry| ... audit log entry being archived ... }
|
|
82
85
|
# end
|
|
83
86
|
#
|
|
87
|
+
# === Exporter
|
|
88
|
+
#
|
|
89
|
+
# require 'jgrouper'
|
|
90
|
+
# require 'jgrouper/exporter'
|
|
91
|
+
#
|
|
92
|
+
# JGrouper::Exporter do |exporter|
|
|
93
|
+
# exporter.export 'stem:to:export', lambda { |_| puts _.to_yaml }
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
84
96
|
# === Scripts
|
|
85
97
|
#
|
|
86
98
|
# Archive Grouper audit log entries to disk:
|
|
87
99
|
#
|
|
88
100
|
# % jgrouper-audit-archiver -h
|
|
89
101
|
#
|
|
90
|
-
# Export
|
|
102
|
+
# Export Groups registry to YAML:
|
|
91
103
|
#
|
|
92
|
-
# % jgrouper-
|
|
104
|
+
# % jgrouper-export -h
|
|
93
105
|
#
|
|
94
106
|
# Grant privileges:
|
|
95
107
|
#
|
|
@@ -158,13 +170,22 @@ module JGrouper
|
|
|
158
170
|
|
|
159
171
|
# TODO Do this for everything?
|
|
160
172
|
%w(
|
|
173
|
+
edu.internet2.middleware.grouper.Field
|
|
161
174
|
edu.internet2.middleware.grouper.GroupFinder
|
|
175
|
+
edu.internet2.middleware.grouper.GroupTypeFinder
|
|
162
176
|
edu.internet2.middleware.grouper.privs.Privilege
|
|
177
|
+
edu.internet2.middleware.subject.provider.SourceManager
|
|
163
178
|
).each do |klass|
|
|
164
179
|
java_import klass do |pkg, cls| "J#{cls}"; end
|
|
165
180
|
end
|
|
166
181
|
end
|
|
167
182
|
|
|
183
|
+
# TODO Block method?
|
|
184
|
+
def self.start_root_session
|
|
185
|
+
# TODO Block method?
|
|
186
|
+
GrouperSession.start_root_session
|
|
187
|
+
end
|
|
188
|
+
|
|
168
189
|
end
|
|
169
190
|
|
|
170
191
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jgrouper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: jruby-jars
|
|
@@ -100,9 +100,12 @@ files:
|
|
|
100
100
|
- lib/jgrouper.rb
|
|
101
101
|
- lib/jgrouper/audit_archiver.rb
|
|
102
102
|
- lib/jgrouper/exporter.rb
|
|
103
|
+
- lib/jgrouper/field.rb
|
|
103
104
|
- lib/jgrouper/group.rb
|
|
105
|
+
- lib/jgrouper/group_type.rb
|
|
104
106
|
- lib/jgrouper/member.rb
|
|
105
107
|
- lib/jgrouper/privilege.rb
|
|
108
|
+
- lib/jgrouper/source.rb
|
|
106
109
|
- lib/jgrouper/stem.rb
|
|
107
110
|
- lib/jgrouper/subject.rb
|
|
108
111
|
- lib/jgrouper/version.rb
|