Skip to content

Commit e1aab42

Browse files
committed
Merge pull request redhat-openstack#275 from cmurphy/change_password
(MODULES-1085) Allow changing of user password
2 parents edd56fb + ecd4120 commit e1aab42

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ def create
3232
end
3333
end
3434

35+
def change_password
36+
rabbitmqctl('change_password', resource[:name], resource[:password])
37+
end
38+
39+
def password
40+
nil
41+
end
42+
43+
44+
def check_password
45+
response = rabbitmqctl('eval', 'rabbit_auth_backend_internal:check_user_login(<<"' + resource[:name] + '">>, [{password, <<"' + resource[:password] +'">>}]).')
46+
if response.include? 'invalid credentials'
47+
false
48+
else
49+
true
50+
end
51+
end
52+
3553
def destroy
3654
rabbitmqctl('delete_user', resource[:name])
3755
end

lib/puppet/type/rabbitmq_user.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@
1818
newvalues(/^\S+$/)
1919
end
2020

21-
# newproperty(:password) do
22-
newparam(:password) do
23-
desc 'User password to be set *on creation*'
21+
newproperty(:password) do
22+
desc 'User password to be set *on creation* and validated each run'
23+
def insync?(is)
24+
provider.check_password
25+
end
26+
def set(value)
27+
provider.change_password
28+
end
29+
def change_to_s(current, desired)
30+
"password has been changed"
31+
end
2432
end
2533

2634
newproperty(:admin) do

0 commit comments

Comments
 (0)