Skip to content

Commit

Permalink
Use single-quoted strings when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Charreau committed Dec 20, 2023
1 parent 751f659 commit 809db6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions lib/puppet/provider/elastic_stack_keystore/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ def self.run_keystore(args, service, stdin = nil)
}

password = case service
when "elasticsearch"
when 'elasticsearch'
File.file?(elastic_keystore_password_file_bak) ? elastic_keystore_password_bak : elastic_keystore_password
else
''
end

cmd = [command("#{service}_keystore")]
if args[0] == "create" || args[0] == "has-passwd"
if args[0] == 'create' || args[0] == 'has-passwd'
options[:failonfail] = false
options[:combine] = true
elsif args[0] == "passwd"
elsif args[0] == 'passwd'
options[:combine] = true
if File.file?(elastic_keystore_password_file_bak)

Check failure on line 90 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
stdin = "#{elastic_keystore_password_bak}\n#{elastic_keystore_password}\n#{elastic_keystore_password}"
Expand All @@ -94,8 +94,8 @@ def self.run_keystore(args, service, stdin = nil)
end
end

if service == "elasticsearch"
unless args[0] == "passwd" || args[0] == "has-passwd"
if service == 'elasticsearch'
unless args[0] == 'passwd' || args[0] == 'has-passwd'

Check failure on line 98 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/SoleNestedConditional: Consider merging nested conditions into outer `if` conditions.
if has_passwd?(service)

Check failure on line 99 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/SoleNestedConditional: Consider merging nested conditions into outer `unless` conditions.
unless password.strip.empty?

Check failure on line 100 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Metrics/BlockNesting: Avoid more than 3 levels of block nesting. (https://rubystyle.guide#three-is-the-number-thou-shalt-count)

Check failure on line 100 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/SoleNestedConditional: Consider merging nested conditions into outer `if` conditions.
if stdin.nil?

Check failure on line 101 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
Expand Down Expand Up @@ -135,7 +135,7 @@ def self.present_keystores(configdir, service, password = '')
keystore_file = File.join(configdir, "#{service}.keystore")
if File.file?(keystore_file)
current_password = case service
when "elasticsearch"
when 'elasticsearch'
if has_passwd?(service)
File.file?(elastic_keystore_password_file_bak) ? elastic_keystore_password_bak : elastic_keystore_password(password.value)

Check failure on line 140 in lib/puppet/provider/elastic_stack_keystore/ruby.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/IndentationStyle: Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
else
Expand All @@ -147,7 +147,7 @@ def self.present_keystores(configdir, service, password = '')
end
settings = {}
run_keystore(['list'], service).split("\n").each do |setting|
if service == "kibana"
if service == 'kibana'
settings[setting] = ''
else
settings[setting] = run_keystore(['show', setting], service)
Expand All @@ -168,7 +168,7 @@ def self.present_keystores(configdir, service, password = '')
def self.configdir(service)
dir = get_envvar(service, '(ES|KBN)_PATH_CONF')
if dir.empty?
File.join("/etc", service)
File.join('/etc', service)
else
dir
end
Expand All @@ -180,7 +180,7 @@ def self.get_envvar(service, env)
if File.file?(defaults_file)
File.readlines(defaults_file).each do |line|
next if line =~ /^#/
key,value = line.split "="
key,value = line.split '='
if key =~ /#{env}/
val = value.gsub(/"/, '').strip
end
Expand Down Expand Up @@ -252,7 +252,7 @@ def flush
&& @property_hash[:settings][setting] == value

args = ['add', '--force']
args << '--stdin' if service == "kibana"
args << '--stdin' if service == 'kibana'
args << setting
debug(self.class.run_keystore(args, service, value))
end
Expand All @@ -269,16 +269,16 @@ def flush

keystore_settings = self.class.run_keystore(['list'], service).split("\n").each do |setting|
settings = {}
if service == "kibana"
if service == 'kibana'
settings[setting] = ''
else
settings[setting] = self.class.run_keystore(['show', setting], service)
end
settings
end

# if service == "elasticsearch" && @property_flush.key?(:password)
if service == "elasticsearch"
# if service == 'elasticsearch' && @property_flush.key?(:password)
if service == 'elasticsearch'
# set and update keystore password if needed
self.class.keystore_password_management(service)
# unlink backup file containing keystore password (synced)
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/elastic_stack_keystore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def insync?(value)
def is_to_s(value)
debug("into is_to_s #{value}")
# hide sensitive data
value.map { |k,v| [k, "xxxx"] }.to_h.inspect
value.map { |k,v| [k, 'xxxx'] }.to_h.inspect
end

def should_to_s(value)
debug("into should_to_s #{value}")
# hide sensitive data
value.map { |k,v| [k, "xxxx"] }.to_h.inspect
value.map { |k,v| [k, 'xxxx'] }.to_h.inspect
end

def change_to_s(currentvalue, newvalue)
Expand Down

0 comments on commit 809db6c

Please sign in to comment.