Fix runas in code order and make the check_password work with the new >3.5.7 version

This commit is contained in:
Nathan Delhaye 2016-08-05 17:13:15 +02:00
parent 4d8119b88b
commit f75eb2ecc7

View file

@ -307,18 +307,24 @@ def check_password(name, password, runas=None):
salt '*' rabbitmq.check_password rabbit_user password
'''
# try to get the rabbitmq-version - adapted from _get_rabbitmq_plugin
if runas is None:
runas = salt.utils.get_user()
try:
res = __salt__['cmd.run'](['rabbitmqctl', 'status'], runas=runas, python_shell=False)
server_version = re.search(r'\{rabbit,"RabbitMQ","(.+)"\}',res).group(1)
server_version = re.search(r'\{rabbit,"RabbitMQ","(.+)"\}',res)
if server_version is None:
raise ValueError("")
server_version = server_version.group(1)
version = [int(i) for i in server_version.split('.')]
except ValueError:
version = (0, 0, 0)
if len(version) < 3:
version = (0, 0, 0)
if runas is None:
runas = salt.utils.get_user()
# rabbitmq introduced a native api to check a username and password in version 3.5.7.
if tuple(version) >= (3, 5, 7):
res = __salt__['cmd.run'](
@ -326,8 +332,8 @@ def check_password(name, password, runas=None):
runas=runas,
output_loglevel='quiet',
python_shell=False)
msg = 'password-check'
return _format_response(res, msg)
return not 'Error:' in res
cmd = ('rabbit_auth_backend_internal:check_user_login'
'(<<"{0}">>, [{{password, <<"{1}">>}}]).').format(