mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix tag handling code for rabbitmq_user.present
This commit is contained in:
parent
3b6d25b4e9
commit
08868cb32a
1 changed files with 21 additions and 22 deletions
|
@ -73,20 +73,14 @@ def _check_perms_changes(name, newperms, runas=None, existing=None):
|
|||
return perm_need_change
|
||||
|
||||
|
||||
def _check_tags_changes(name, new_tags, runas=None):
|
||||
def _get_current_tags(name, runas=None):
|
||||
'''
|
||||
Whether Rabbitmq user's tags need to be changed
|
||||
'''
|
||||
if new_tags:
|
||||
if isinstance(new_tags, str):
|
||||
new_tags = new_tags.split()
|
||||
try:
|
||||
users = __salt__['rabbitmq.list_users'](runas=runas)[name] - set(new_tags)
|
||||
except CommandExecutionError as err:
|
||||
log.error('Error: {0}'.format(err))
|
||||
return []
|
||||
return list(users)
|
||||
else:
|
||||
try:
|
||||
return list(__salt__['rabbitmq.list_users'](runas=runas)[name])
|
||||
except CommandExecutionError as err:
|
||||
log.error('Error: {0}'.format(err))
|
||||
return []
|
||||
|
||||
|
||||
|
@ -165,17 +159,22 @@ def present(name,
|
|||
{'old': 'Removed password.',
|
||||
'new': ''}})
|
||||
|
||||
new_tags = _check_tags_changes(name, tags, runas=runas)
|
||||
if new_tags:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['rabbitmq.set_user_tags'](name, tags, runas=runas)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'tags':
|
||||
{'old': tags,
|
||||
'new': list(new_tags)}})
|
||||
if tags is not None:
|
||||
current_tags = _get_current_tags(name, tags, runas=runas)
|
||||
if isinstance(tags, str):
|
||||
tags = tags.split()
|
||||
# Diff the tags sets. Symmetric difference operator ^ will give us
|
||||
# any element in one set, but not both
|
||||
if set(tags) ^ set(current_tags):
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['rabbitmq.set_user_tags'](name, tags, runas=runas)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'tags':
|
||||
{'old': current_tags,
|
||||
'new': tags}})
|
||||
try:
|
||||
existing_perms = __salt__['rabbitmq.list_user_permissions'](name, runas=runas)
|
||||
except CommandExecutionError as err:
|
||||
|
|
Loading…
Add table
Reference in a new issue