Skip to content

Commit

Permalink
Additional fixes and changes for rubocop warnings (reworks #460)
Browse files Browse the repository at this point in the history
  • Loading branch information
William Yardley committed Sep 4, 2017
1 parent ed4faaa commit 96bd913
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
44 changes: 18 additions & 26 deletions lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
require 'puppet/provider/rabbitmqctl'

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl'))
Puppet::Type.type(:rabbitmq_user).provide(
:rabbitmqctl,
:parent => Puppet::Provider::Rabbitmqctl
parent: Puppet::Provider::Rabbitmqctl
) do

if Puppet::PUPPETVERSION.to_f < 3
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment HOME: '/tmp'
end
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment HOME: '/tmp'
end

defaultfor feature: :posix

def initialize(value={})
def initialize(value = {})
super(value)
@property_flush = {}
end
Expand All @@ -27,17 +23,17 @@ def self.instances
raise Puppet::Error, "Cannot parse invalid user line: #{line}" unless line =~ %r{^(\S+)\s+\[(.*?)\]$}
new(name: Regexp.last_match(1))
new(
:ensure => :present,
:name => Regexp.last_match(1),
:tags => Regexp.last_match(2).split(/,\s*/)
)
ensure: 'present',
name: Regexp.last_match(1),
tags: Regexp.last_match(2).split(%r{/,\s*/})
)
end
end

def self.prefetch(resources)
users = instances
resources.each_key do |user|
if provider = users.find { |u| u.name == user }
if (provider = users.find { |u| u.name == user })
resources[user].provider = provider
end
end
Expand Down Expand Up @@ -66,8 +62,7 @@ def password=(password)
rabbitmqctl('change_password', @resource[:name], password)
end

def password
end
def password; end

def check_password(password)
check_access_control = [
Expand All @@ -82,7 +77,7 @@ def check_password(password)

def tags
# do not expose the administrator tag for admins
@property_hash[:tags].reject { |tag| tag == admin_tag }
@property_hash[:tags].reject { |tag| tag == admin_tag }
end

def tags=(tags)
Expand Down Expand Up @@ -119,8 +114,6 @@ def make_user_admin
rabbitmqctl('set_user_tags', resource[:name], usertags.entries.sort)
end

private

def get_user_tags # rubocop:disable Style/AccessorMethodName
match = rabbitmqctl('-q', 'list_users').split(%r{\n}).map do |line|
line.match(%r{^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]})
Expand All @@ -142,17 +135,16 @@ def admin=(state)
end

def flush
unless @property_flush.empty?
tags = @property_flush[:tags] || @resource[:tags]
tags << admin_tag if @resource[:admin] == :true
rabbitmqctl('set_user_tags', @resource[:name], tags)
@property_flush.clear
end
return if @property_flush.empty?
tags = @property_flush[:tags] || @resource[:tags]
tags << admin_tag if @resource[:admin] == :true
rabbitmqctl('set_user_tags', @resource[:name], tags)
@property_flush.clear
end

private

def admin_tag
'administrator'
end

end
6 changes: 3 additions & 3 deletions lib/puppet/type/rabbitmq_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

newproperty(:password) do
desc 'User password to be set *on creation* and validated each run'
def insync?(is)
def insync?
provider.check_password(should)
end

def change_to_s(current, desired)
"password has been changed"
def change_to_s
'password has been changed'
end
end

Expand Down

0 comments on commit 96bd913

Please sign in to comment.