Skip to content

Commit

Permalink
Fix remaining rubocop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Oct 27, 2021
1 parent 7f5da31 commit 175fe0c
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 92 deletions.
1 change: 1 addition & 0 deletions lib/facter/es_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def self.run
end
end
rescue StandardError
# ignore
end
Facter.add(:elasticsearch) do
setcode do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/elastic_parsedfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Puppet::Provider::ElasticParsedFile < Puppet::Provider::ParsedFile
#
# @return String
def self.xpack_config(val)
@default_target ||= "/etc/elasticsearch/#{val}"
@xpack_config ||= "/etc/elasticsearch/#{val}"
end
end
44 changes: 22 additions & 22 deletions lib/puppet/provider/elastic_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def query_string
# Perform a REST API request against the indicated endpoint.
#
# @return Net::HTTPResponse
def self.rest(http, \
req, \
validate_tls = true, \
timeout = 10, \
username = nil, \
password = nil)
def self.rest(http,
req,
timeout = 10,
username = nil,
password = nil,
validate_tls: true)

if username && password
req.basic_auth username, password
Expand Down Expand Up @@ -84,15 +84,15 @@ def self.format_uri(resource_path, property_flush = {})
# @return Array
# an array of Hashes representing the found API objects, whether they be
# templates, pipelines, et cetera.
def self.api_objects(protocol = 'http', \
validate_tls = true, \
host = 'localhost', \
port = 9200, \
timeout = 10, \
username = nil, \
password = nil, \
ca_file = nil, \
ca_path = nil)
def self.api_objects(protocol = 'http',
host = 'localhost',
port = 9200,
timeout = 10,
username = nil,
password = nil,
ca_file = nil,
ca_path = nil,
validate_tls: true)

uri = URI("#{protocol}://#{host}:#{port}/#{format_uri(api_discovery_uri)}")
http = Net::HTTP.new uri.host, uri.port
Expand All @@ -103,7 +103,7 @@ def self.api_objects(protocol = 'http', \
http.send method, arg if arg && http.respond_to?(method)
end

response = rest http, req, validate_tls, timeout, username, password
response = rest http, req, timeout, username, password, validate_tls: validate_tls

results = []

Expand Down Expand Up @@ -151,14 +151,14 @@ def self.prefetch(resources)
p = resource.parameters
[
p[:protocol].value,
p[:validate_tls].value,
p[:host].value,
p[:port].value,
p[:timeout].value,
(p.key?(:username) ? p[:username].value : nil),
(p.key?(:password) ? p[:password].value : nil),
(p.key?(:ca_file) ? p[:ca_file].value : nil),
(p.key?(:ca_path) ? p[:ca_path].value : nil)
(p.key?(:ca_path) ? p[:ca_path].value : nil),
p[:validate_tls].value,
]
# Deduplicate identical settings, and fetch templates
end.uniq
Expand Down Expand Up @@ -228,10 +228,10 @@ def flush
response = self.class.rest(
http,
req,
resource[:validate_tls],
resource[:timeout],
resource[:username],
resource[:password]
resource[:password],
validate_tls: resource[:validate_tls]
)

# Attempt to return useful error output
Expand All @@ -257,14 +257,14 @@ def flush
end
@property_hash = self.class.api_objects(
resource[:protocol],
resource[:validate_tls],
resource[:host],
resource[:port],
resource[:timeout],
resource[:username],
resource[:password],
resource[:ca_file],
resource[:ca_path]
resource[:ca_path],
validate_tls: resource[:validate_tls]
).find do |t|
t[:name] == resource[:name]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/elasticsearch_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
newproperty(:settings) do
desc 'Structured settings for the index in hash form.'

def insync?(is)
Puppet_X::Elastic.asymmetric_compare(should, is)
def insync?(value)
Puppet_X::Elastic.asymmetric_compare(should, value)
end

munge do |value|
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/type/elasticsearch_keystore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
# The keystore utility can only retrieve a list of stored settings,
# so here we only compare the existing settings (sorted) with the
# desired settings' keys
def insync?(is)
def insync?(value)
if resource[:purge]
is.sort == @should.first.keys.sort
value.sort == @should.first.keys.sort
else
(@should.first.keys - is).empty?
(@should.first.keys - value).empty?
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/elasticsearch_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
newproperty(:content) do
desc 'Structured hash for license content data.'

def insync?(is)
def insync?(value)
Puppet_X::Elastic.asymmetric_compare(
should.transform_values { |v| v.is_a?(Hash) ? (v.reject { |s, _| s == 'signature' }) : v },
is
value
)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/type/elasticsearch_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
)
end

def insync?(is)
Puppet_X::Elastic.deep_implode(is) == \
def insync?(value)
Puppet_X::Elastic.deep_implode(value) == \
Puppet_X::Elastic.deep_implode(should)
end
end
Expand Down Expand Up @@ -113,4 +113,5 @@ def insync?(is)
self[:content] = PSON.load(tmp.content)
end
end
# rubocop:enable Style/SignalException
end
4 changes: 2 additions & 2 deletions lib/puppet/type/elasticsearch_user_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

newproperty(:roles, array_matching: :all) do
desc 'Array of roles that the user should belong to.'
def insync?(is)
is.sort == should.sort
def insync?(value)
value.sort == should.sort
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet_x/elastic/plugin_parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.plugin_version(raw_name)
end

# Attempt to guess at the plugin's final directory name
def self.plugin_split(original_string, position, soft_fail = true)
def self.plugin_split(original_string, position, soft_fail: true)
# Try both colon (maven) and slash-delimited (github/elastic.co) names
%w[/ :].each do |delimiter|
parts = original_string.split(delimiter)
Expand Down
8 changes: 5 additions & 3 deletions spec/classes/000_elasticsearch_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
config: { 'node.name' => 'foo' }
}

# rubocop:disable RSpec/MultipleMemoizedHelpers
on_supported_os.each do |os, facts|
context "on #{os}" do
case facts[:os]['family']
Expand Down Expand Up @@ -293,6 +294,7 @@
end
end
end
# rubocop:enable RSpec/MultipleMemoizedHelpers

on_supported_os(
hardwaremodels: ['x86_64'],
Expand Down Expand Up @@ -465,14 +467,14 @@
# This check helps catch dependency cycles.
context 'create_resource' do
# Helper for these tests
def singular(s)
case s
def singular(string)
case string
when 'indices'
'index'
when 'snapshot_repositories'
'snapshot_repository'
else
s[0..-2]
string[0..-2]
end
end

Expand Down
2 changes: 0 additions & 2 deletions spec/defines/003_elasticsearch_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
end

describe 'missing parent class' do
let(:pre_condition) {}

it { is_expected.not_to compile }
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/defines/006_elasticsearch_script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class { "elasticsearch":
end

describe 'missing parent class' do
let(:pre_condition) {}

it { is_expected.not_to compile }
end

Expand Down
2 changes: 0 additions & 2 deletions spec/defines/009_elasticsearch_pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
end

describe 'missing parent class' do
let(:pre_condition) {}

it { is_expected.not_to compile }
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/defines/012_elasticsearch_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
end

describe 'missing parent class' do
let(:pre_condition) {}

it { is_expected.not_to compile }
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/defines/013_elasticsearch_snapshot_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
end

describe 'missing parent class' do
let(:pre_condition) {}

it { is_expected.not_to compile }
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/helpers/unit/provider/elasticsearch_rest_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

describe "#{resource_type}s" do
if singleton
let(:json) { json_1 }
let(:instance) { [example_1] }
let(:json) { json1 }
let(:instance) { [example1] }
else
let(:json) { json_1.merge(json_2) }
let(:instance) { [example_1, example_2] }
let(:json) { json1.merge(json2) }
let(:instance) { [example1, example2] }
end

it "returns #{resource_type}s" do
Expand All @@ -54,16 +54,16 @@
).
to_return(
status: 200,
body: JSON.dump(json_1)
body: JSON.dump(json1)
)

expect(described_class.api_objects(
'http', true, 'localhost', '9200', 10, 'elastic', 'password'
'http', 'localhost', '9200', 10, 'elastic', 'password', validate_tls: true
).map do |provider|
described_class.new(
provider
).instance_variable_get(:@property_hash)
end).to contain_exactly(example_1)
end).to contain_exactly(example1)
end
end

Expand All @@ -73,16 +73,16 @@
with(headers: { 'Accept' => 'application/json' }).
to_return(
status: 200,
body: JSON.dump(json_1)
body: JSON.dump(json1)
)

expect(described_class.api_objects(
'https', true, 'localhost', '9200', 10
'https', 'localhost', '9200', 10, validate_tls: true
).map do |provider|
described_class.new(
provider
).instance_variable_get(:@property_hash)
end).to contain_exactly(example_1)
end).to contain_exactly(example1)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'vault'

require 'simp/beaker_helpers'
include Simp::BeakerHelpers
include Simp::BeakerHelpers # rubocop:disable Style/MixinUsage

require_relative 'spec_helper_tls'
require_relative 'spec_utilities'
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative 'helpers/class_shared_examples'
require 'rspec-puppet-utils'
require 'rspec-puppet-facts'
include RspecPuppetFacts
include RspecPuppetFacts # rubocop:disable Style/MixinUsage

def fixture_path
File.expand_path(File.join(__FILE__, '..', 'fixtures'))
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def vault_available?

def http_retry(url)
retries ||= 0
open(url).read
URI.parse(url).open.read
rescue StandardError
retry if (retries += 1) < 3
end
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/provider/elasticsearch_index/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

require_relative '../../../helpers/unit/provider/elasticsearch_rest_shared_examples'

describe Puppet::Type.type(:elasticsearch_index).provider(:ruby) do
describe Puppet::Type.type(:elasticsearch_index).provider(:ruby) do # rubocop:disable RSpec/MultipleMemoizedHelpers
let(:name) { 'test-index' }

let(:example_1) do
let(:example1) do
{
name: 'index-one',
ensure: :present,
Expand Down Expand Up @@ -35,7 +35,7 @@
}
end

let(:json_1) do
let(:json1) do
{
'index-one' => {
'settings' => {
Expand Down Expand Up @@ -64,7 +64,7 @@
}
end

let(:example_2) do
let(:example2) do
{
name: 'index-two',
ensure: :present,
Expand All @@ -84,7 +84,7 @@
}
end

let(:json_2) do
let(:json2) do
{
'index-two' => {
'settings' => {
Expand Down
Loading

0 comments on commit 175fe0c

Please sign in to comment.