Browse Source

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.
changes/70/598470/1
Roger Luethi 1 year ago
parent
commit
049eb35d46
2 changed files with 10 additions and 12 deletions
  1. 2
    4
      libraries/openstack_user.rb
  2. 8
    8
      spec/user_spec.rb

+ 2
- 4
libraries/openstack_user.rb View File

@@ -85,16 +85,14 @@ module OpenstackclientCookbook
85 85
       user = connection.users.find { |u| u.name == user_name }
86 86
       domain = connection.domains.find { |p| p.name == domain_name }
87 87
       role = connection.roles.find { |r| r.name == role_name }
88
-      connection.grant_domain_user_role(
89
-        domain.id, user.id, role.id) if role && domain && user
88
+      user.grant_role role.id if role && domain && user
90 89
     end
91 90
 
92 91
     action :revoke_domain do
93 92
       user = connection.users.find { |u| u.name == user_name }
94 93
       domain = connection.domains.find { |p| p.name == domain_name }
95 94
       role = connection.roles.find { |r| r.name == role_name }
96
-      connection.revoke_domain_user_role(
97
-        domain.id, user.id, role.id) if role && domain && user
95
+      user.revoke_role  role.id if role && domain && user
98 96
     end
99 97
   end
100 98
 end

+ 8
- 8
spec/user_spec.rb View File

@@ -35,7 +35,9 @@ describe 'openstackclient_test::user' do
35 35
   let(:found_user) do
36 36
     double :find,
37 37
            id: 4,
38
-           destroy: true
38
+           destroy: true,
39
+           grant_role: true,
40
+           revoke_role: true
39 41
   end
40 42
 
41 43
   let(:users_populated) do
@@ -155,9 +157,7 @@ describe 'openstackclient_test::user' do
155 157
              users: users_populated,
156 158
              domains: domains_populated,
157 159
              roles: roles_populated,
158
-             projects: projects_populated,
159
-             grant_domain_user_role: true,
160
-             revoke_domain_user_role: true
160
+             projects: projects_populated
161 161
     end
162 162
 
163 163
     before do
@@ -244,14 +244,14 @@ describe 'openstackclient_test::user' do
244 244
     end
245 245
 
246 246
     it do
247
-      expect(connection_dub).to receive(:grant_domain_user_role)
248
-        .with(5, 4, 3)
247
+      expect(found_user).to receive(:grant_role)
248
+        .with(3)
249 249
       chef_run
250 250
     end
251 251
 
252 252
     it do
253
-      expect(connection_dub).to receive(:revoke_domain_user_role)
254
-        .with(5, 4, 3)
253
+      expect(found_user).to receive(:revoke_role)
254
+        .with(3)
255 255
       chef_run
256 256
     end
257 257
   end

Loading…
Cancel
Save