File tree 1 file changed +29
-4
lines changed
1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change 3
3
require_relative '../bundle/bundler/setup'
4
4
5
5
require 'gerry'
6
+ require 'set'
6
7
7
- uri_str , flag = ARGV
8
+ uri_str , * flags = ARGV
8
9
if uri_str . nil?
9
10
script = File . basename ( __FILE__ )
10
- puts "Usage : #{ script } <uri>"
11
+ puts "Usage : #{ script } <uri> [-u] "
11
12
puts "Example : #{ script } [user:password@]host[:port]"
13
+ puts
14
+ puts " -u List only unused groups (those that have no associated permissions)."
12
15
exit
13
16
end
14
17
21
24
Gerry ::Client . default_options . update ( verify : false )
22
25
client = Gerry . new ( "#{ uri . scheme } ://#{ uri . host } " , uri . user , uri . password )
23
26
24
- client . groups . keys . each do |name |
25
- puts name
27
+ if flags . include? ( '-u' )
28
+ used_groups = Set . new
29
+
30
+ client . projects . keys . each_slice ( 100 ) do |projects |
31
+ client . access ( projects ) . values . each do |info |
32
+ info [ 'local' ] . values . each do |permissions |
33
+ permissions [ 'permissions' ] . values . each do |info |
34
+ info [ 'rules' ] . keys . each do |group |
35
+ used_groups . add ( group )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ client . groups . each do |name , info |
43
+ if !used_groups . include? ( info [ 'id' ] )
44
+ puts name
45
+ end
46
+ end
47
+ else
48
+ client . groups . keys . each do |name |
49
+ puts name
50
+ end
26
51
end
You can’t perform that action at this time.
0 commit comments