cf-uaac 3.13.0 → 3.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe342c673876fa863a16c2da17b1bd624f5a0924
4
- data.tar.gz: e7fdd1f8fbd5719171140051355443eed0a73648
3
+ metadata.gz: 8ef367062c3e28c384a318cbf086099558e965a4
4
+ data.tar.gz: 2cc9ad180ad1a8ccdb88eab48191cc8931bd336c
5
5
  SHA512:
6
- metadata.gz: f00cbc1ee59f2b3fecc665721f118c45ae0a536de5b70129f26f4c84f4b0025ccc1be71f1565ab7c21797a5ec9be7fae5c8d6ad70dbab0e725bea7c9ea2b3df1
7
- data.tar.gz: 901faa8b5087b9264e044edd210cc5725669fe0112737e1b6e358cbec354f6a617e45a6f84e2a9ae7a92ea4a1baa5604c4e438e7abe7cbb1535027eb253b9e2b
6
+ metadata.gz: c56c0743dbede318336371e6d731d0f6d895a949f41905bc60cd492348a8ae818b21cf4f0f7cbb85ebc5ae3a5b46195c44e674315a074fa97d3df55325adbfc6
7
+ data.tar.gz: ade14cd1d7aeec495397587b486327cf046794e68c8a5a902005b25f0124b8db7c9d50e966f828bcf3fe390ee0c15bc4e22c75a4e52de6481f1249598a50c17a
data/cf-uaac.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.require_paths = ['lib']
34
34
 
35
35
  # dependencies
36
- s.add_runtime_dependency 'cf-uaa-lib', '~> 3.10.0'
36
+ s.add_runtime_dependency 'cf-uaa-lib', '~> 3.11'
37
37
  s.add_development_dependency 'bundler', '~> 1.14'
38
38
  s.add_development_dependency 'rake', '~> 10.3', '>= 10.3.1'
39
39
  s.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
data/lib/uaa/cli/group.rb CHANGED
@@ -106,30 +106,108 @@ class GroupCli < CommonCli
106
106
  }
107
107
  end
108
108
 
109
- def update_members(scim, name, attr, users, add = true)
110
- group = scim_get_object(scim, :group, gname(name))
111
- old_ids = id_set(group[attr] || [])
112
- new_ids = id_set(scim.ids(:user, *users))
113
- if add
114
- raise "not all users found, none added" unless new_ids.size == users.size
115
- group[attr] = (old_ids + new_ids).to_a
116
- raise "no new users given" unless group[attr].size > old_ids.size
117
- else
118
- raise "not all users found, none deleted" unless new_ids.size == users.size
119
- group[attr] = (old_ids - new_ids).to_a
120
- raise "no existing users to delete" unless group[attr].size < old_ids.size
121
- group.delete(attr) if group[attr].empty?
109
+ def find_members(scim, members)
110
+ found_members = []
111
+
112
+ scim.ids(:user, *members).each do |member|
113
+ found_members << {
114
+ 'type' => 'USER',
115
+ 'value' => member['id'],
116
+ 'origin' => member['origin']
117
+ }
118
+ end
119
+
120
+ found_members
121
+ end
122
+
123
+ def union(old_members, new_members)
124
+ old_ids = id_set(old_members)
125
+ all_members = old_members.clone
126
+
127
+ new_members.each do |member|
128
+ unless old_ids.include?(member['value'])
129
+ all_members << member
122
130
  end
123
- scim.put(:group, group)
124
- "success"
131
+ end
132
+
133
+ all_members
134
+ end
135
+
136
+ def difference(old_members, new_members)
137
+ new_ids = id_set(new_members)
138
+
139
+ old_members.reject do |member|
140
+ new_ids.include?(member['value'])
141
+ end
142
+ end
143
+
144
+ def add_members(scim, name, members)
145
+ group = scim_get_object(scim, :group, gname(name))
146
+
147
+ old_members = (group['members'] || [])
148
+ new_members = find_members(scim, members)
149
+
150
+ unless new_members.size == members.size
151
+ raise 'not all users found, none added'
152
+ end
153
+
154
+ group['members'] = union(old_members, new_members)
155
+
156
+ unless group['members'].size > old_members.size
157
+ raise 'no new users given'
158
+ end
159
+
160
+ scim.put(:group, group)
161
+ 'success'
162
+ end
163
+
164
+ def delete_members(scim, name, members)
165
+ group = scim_get_object(scim, :group, gname(name))
166
+
167
+ old_members = (group['members'] || [])
168
+ new_members = find_members(scim, members)
169
+
170
+ unless new_members.size == members.size
171
+ raise 'not all users found, none deleted'
172
+ end
173
+
174
+ group['members'] = difference(old_members, new_members)
175
+
176
+ unless group['members'].size < old_members.size
177
+ raise 'no existing users to delete'
178
+ end
179
+
180
+ group.delete('members') if group['members'].empty?
181
+
182
+ scim.put(:group, group)
183
+ 'success'
184
+ end
185
+
186
+ def update_members(scim, name, attr, users, add = true)
187
+ group = scim_get_object(scim, :group, gname(name))
188
+ old_ids = id_set(group[attr] || [])
189
+ new_ids = id_set(scim.ids(:user, *users))
190
+ if add
191
+ raise 'not all users found, none added' unless new_ids.size == users.size
192
+ group[attr] = (old_ids + new_ids).to_a
193
+ raise 'no new users given' unless group[attr].size > old_ids.size
194
+ else
195
+ raise 'not all users found, none deleted' unless new_ids.size == users.size
196
+ group[attr] = (old_ids - new_ids).to_a
197
+ raise 'no existing users to delete' unless group[attr].size < old_ids.size
198
+ group.delete(attr) if group[attr].empty?
199
+ end
200
+
201
+ scim.put(:group, group)
202
+ 'success'
125
203
  end
126
204
 
127
205
  desc "member add [name] [users...]", "add members to a group" do |name, *users|
128
- pp scim_request { |scim| update_members(scim, name, "members", users) }
206
+ pp scim_request { |scim| add_members(scim, name, users) }
129
207
  end
130
208
 
131
209
  desc "member delete [name] [users...]", "remove members from a group" do |name, *users|
132
- pp scim_request { |scim| update_members(scim, name, "members", users, false) }
210
+ pp scim_request { |scim| delete_members(scim, name, users) }
133
211
  end
134
212
 
135
213
  desc "group reader add [name] [users...]", "add users who can read the members" do |name, *users|
@@ -14,6 +14,6 @@
14
14
  # Cloud Foundry namespace
15
15
  module CF
16
16
  module UAA
17
- CLI_VERSION = '3.13.0'
17
+ CLI_VERSION = '3.13.1'
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-uaac
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.0
4
+ version: 3.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Syer
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-07-10 00:00:00.000000000 Z
15
+ date: 2017-07-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: cf-uaa-lib
@@ -20,14 +20,14 @@ dependencies:
20
20
  requirements:
21
21
  - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: 3.10.0
23
+ version: '3.11'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: 3.10.0
30
+ version: '3.11'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: bundler
33
33
  requirement: !ruby/object:Gem::Requirement