summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Luethi <rl@patchworkscience.org>2017-11-10 15:43:58 +0100
committerRoger Luethi <rl@patchworkscience.org>2017-11-10 17:03:03 +0100
commit049eb35d46a44f87552347926bf5ba7555699373 (patch)
treee29fbac07c525a7e25d6fc0fe5272d26d7b60d57
parentae02bdc63297c58fb641c291b4172b57e4f2d869 (diff)
Use user model for grant_domain, revoke_domain
Unlike the rest of the library, openstack_user's grant_domain and revoke_domain actions bypass the fog models and call directly into the requests. It works, but it is inconsistent and confusing. This patch uses user.grant_role instead of directly calling connection.grant_domain_user_role. Likewise for revoke_domain.
-rw-r--r--libraries/openstack_user.rb6
-rw-r--r--spec/user_spec.rb16
2 files changed, 10 insertions, 12 deletions
diff --git a/libraries/openstack_user.rb b/libraries/openstack_user.rb
index 4fd8d2d..fd1822a 100644
--- a/libraries/openstack_user.rb
+++ b/libraries/openstack_user.rb
@@ -85,16 +85,14 @@ module OpenstackclientCookbook
85 user = connection.users.find { |u| u.name == user_name } 85 user = connection.users.find { |u| u.name == user_name }
86 domain = connection.domains.find { |p| p.name == domain_name } 86 domain = connection.domains.find { |p| p.name == domain_name }
87 role = connection.roles.find { |r| r.name == role_name } 87 role = connection.roles.find { |r| r.name == role_name }
88 connection.grant_domain_user_role( 88 user.grant_role role.id if role && domain && user
89 domain.id, user.id, role.id) if role && domain && user
90 end 89 end
91 90
92 action :revoke_domain do 91 action :revoke_domain do
93 user = connection.users.find { |u| u.name == user_name } 92 user = connection.users.find { |u| u.name == user_name }
94 domain = connection.domains.find { |p| p.name == domain_name } 93 domain = connection.domains.find { |p| p.name == domain_name }
95 role = connection.roles.find { |r| r.name == role_name } 94 role = connection.roles.find { |r| r.name == role_name }
96 connection.revoke_domain_user_role( 95 user.revoke_role role.id if role && domain && user
97 domain.id, user.id, role.id) if role && domain && user
98 end 96 end
99 end 97 end
100end 98end
diff --git a/spec/user_spec.rb b/spec/user_spec.rb
index 55464bb..0eec778 100644
--- a/spec/user_spec.rb
+++ b/spec/user_spec.rb
@@ -35,7 +35,9 @@ describe 'openstackclient_test::user' do
35 let(:found_user) do 35 let(:found_user) do
36 double :find, 36 double :find,
37 id: 4, 37 id: 4,
38 destroy: true 38 destroy: true,
39 grant_role: true,
40 revoke_role: true
39 end 41 end
40 42
41 let(:users_populated) do 43 let(:users_populated) do
@@ -155,9 +157,7 @@ describe 'openstackclient_test::user' do
155 users: users_populated, 157 users: users_populated,
156 domains: domains_populated, 158 domains: domains_populated,
157 roles: roles_populated, 159 roles: roles_populated,
158 projects: projects_populated, 160 projects: projects_populated
159 grant_domain_user_role: true,
160 revoke_domain_user_role: true
161 end 161 end
162 162
163 before do 163 before do
@@ -244,14 +244,14 @@ describe 'openstackclient_test::user' do
244 end 244 end
245 245
246 it do 246 it do
247 expect(connection_dub).to receive(:grant_domain_user_role) 247 expect(found_user).to receive(:grant_role)
248 .with(5, 4, 3) 248 .with(3)
249 chef_run 249 chef_run
250 end 250 end
251 251
252 it do 252 it do
253 expect(connection_dub).to receive(:revoke_domain_user_role) 253 expect(found_user).to receive(:revoke_role)
254 .with(5, 4, 3) 254 .with(3)
255 chef_run 255 chef_run
256 end 256 end
257 end 257 end