providers/user.rb
# does the user have the rights listed on the vhost?
# empty perm_list means we're checking for any permissions
does the user have the rights listed on the vhost.
empty perm_list means we're checking for any permissions
does the user have the rights listed on the vhost . empty perm_list means we ' re checking for any permissions
def user_has_expected_permissions?(name, vhost, perm_list = nil)
  vhost = '/' if vhost.nil? 
  cmd = if Gem::Version.new(installed_rabbitmq_version) >= Gem::Version.new('3.7.10')
          "rabbitmqctl -s list_user_permissions #{name} | grep \"^#{vhost}\\s\""
        else
          "rabbitmqctl -q list_user_permissions #{name} | grep \"^#{vhost}\\s\""
        end
  cmd = Mixlib::ShellOut.new(cmd, :env => shell_environment)
  cmd.run_command
  Chef::Log.debug "rabbitmq_user_has_expected_permissions?: #{cmd}"
  Chef::Log.debug "rabbitmq_user_has_expected_permissions?: #{cmd.stdout}"
  Chef::Log.debug "rabbitmq_user_has_expected_permissions?: #{cmd.exitstatus}"
  if perm_list.nil? && cmd.stdout.empty?
    Chef::Log.debug 'rabbitmq_user_has_expected_permissions?: no permissions found'
    return true
  end
  if perm_list == %(\"#{cmd.stdout}\").undump.split.drop(1)
    Chef::Log.debug 'rabbitmq_user_has_expected_permissions?: matching permissions already found'
    return true
  end
  Chef::Log.debug 'rabbitmq_user_has_expected_permissions?: permissions found but do not match'
  false
end
def user_has_expected_permissions? ( name , vhost , perm_list = nil ) vhost = '/' if vhost . nil? cmd = if Gem :: Version . new ( installed_rabbitmq_version ) >= Gem :: Version . new ( '3.7.10' ) "rabbitmqctl -s list_user_permissions #{name} | grep \"^#{vhost}\\s\"" else "rabbitmqctl -q list_user_permissions #{name} | grep \"^#{vhost}\\s\"" end cmd = Mixlib :: ShellOut . new ( cmd , :env => shell_environment ) cmd . run_command Chef :: Log . debug "rabbitmq_user_has_expected_permissions?: #{cmd}" Chef :: Log . debug "rabbitmq_user_has_expected_permissions?: #{cmd.stdout}" Chef :: Log . debug "rabbitmq_user_has_expected_permissions?: #{cmd.exitstatus}" if perm_list . nil? && cmd . stdout . empty? Chef :: Log . debug 'rabbitmq_user_has_expected_permissions?: no permissions found' return true end if perm_list == %(\"#{cmd.stdout}\") . undump . split . drop ( 1 ) Chef :: Log . debug 'rabbitmq_user_has_expected_permissions?: matching permissions already found' return true end Chef :: Log . debug 'rabbitmq_user_has_expected_permissions?: permissions found but do not match' false end
does the user have the rights listed on the vhost?
does the user have the rights listed on the vhost?
# rubocop:enable all # no permissions found and none expected # existing match search
name
<not_specific>
vhost
<not_specific>
perm_list
<not_specific>