Merge pull request #33723 from rallytime/bp-33641

Back-port #33641 to 2016.3
This commit is contained in:
Mike Place 2016-06-03 09:07:53 -07:00
commit 56eab363ff

View File

@ -305,9 +305,27 @@ 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
try:
version = [int(i) for i in __salt__['pkg.version']('rabbitmq-server').split('-')[0].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 version[0] >= 3 and version[1] >= 5 and version[2] >= 7:
res = __salt__['cmd.run'](
['rabbitmqctl', 'authenticate_user', name, password],
runas=runas,
output_loglevel='quiet',
python_shell=False)
msg = 'password-check'
return _format_response(res, msg)
cmd = ('rabbit_auth_backend_internal:check_user_login'
'(<<"{0}">>, [{{password, <<"{1}">>}}]).').format(
name.replace('"', '\\"'),