Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ inherit_gem:

Metrics:
Enabled: false

Style/IfUnlessModifier:
Enabled: false
61 changes: 10 additions & 51 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-10-20 14:24:21 UTC using RuboCop version 1.64.1.
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
# using RuboCop version 1.75.8.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -13,14 +13,6 @@ Layout/CommentIndentation:
Exclude:
- 'lib/hiera/backend/eyaml/subcommands/help.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'lib/hiera/backend/eyaml/logginghelper.rb'

# Offense count: 1
Lint/DuplicateMethods:
Exclude:
Expand All @@ -45,23 +37,6 @@ Lint/RescueException:
Exclude:
- 'lib/hiera/backend/eyaml/subcommand.rb'

# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'lib/hiera/backend/eyaml_backend.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessAssignment:
Exclude:
- 'features/support/env.rb'
- 'lib/hiera/backend/eyaml/plugins.rb'
- 'lib/hiera/backend/eyaml/subcommand.rb'
- 'lib/hiera/backend/eyaml/subcommands/unknown_command.rb'
- 'lib/hiera/backend/eyaml/subcommands/version.rb'
- 'lib/hiera/backend/eyaml/utils.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Expand All @@ -74,7 +49,7 @@ Lint/UselessMethodDefinition:
# Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'lib/hiera/backend/eyaml/parser/token.rb'
- 'features/support/env.rb'

# Offense count: 1
Naming/AccessorMethodName:
Expand Down Expand Up @@ -107,8 +82,9 @@ Naming/HeredocDelimiterNaming:
- 'lib/hiera/backend/eyaml/subcommands/unknown_command.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, AllowedPatterns.
# Configuration parameters: EnforcedStyle, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns.
# SupportedStyles: snake_case, camelCase
# ForbiddenIdentifiers: __id__, __send__
Naming/MethodName:
Exclude:
- 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb'
Expand All @@ -123,7 +99,7 @@ Naming/MethodParameterName:
# Offense count: 1
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'lib/hiera/backend/eyaml/utils.rb'
Expand Down Expand Up @@ -169,14 +145,13 @@ Security/YAMLLoad:
- 'features/step_definitions/decrypt_steps.rb'
- 'lib/hiera/backend/eyaml_backend.rb'

# Offense count: 9
# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Exclude:
- 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb'
- 'lib/hiera/backend/eyaml/highlinehelper.rb'
- 'lib/hiera/backend/eyaml/logginghelper.rb'
- 'lib/hiera/backend/eyaml/subcommand.rb'
- 'lib/hiera/backend/eyaml_backend.rb'
Expand Down Expand Up @@ -220,7 +195,7 @@ Style/EnvHome:

# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, Mode, AllowedMethods, AllowedPatterns.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
EnforcedStyle: unannotated
Expand Down Expand Up @@ -248,22 +223,6 @@ Style/IdenticalConditionalBranches:
- 'lib/hiera/backend/eyaml/subcommands/decrypt.rb'
- 'lib/hiera/backend/eyaml/subcommands/edit.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb'
- 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
# AllowedMethods: nonzero?
Style/IfWithBooleanLiteralBranches:
Exclude:
- 'lib/hiera/backend/eyaml/highlinehelper.rb'
- 'lib/hiera/backend/eyaml_backend.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapIntoArray:
Expand Down Expand Up @@ -408,9 +367,9 @@ Style/ZeroLengthPredicate:
Exclude:
- 'lib/hiera/backend/eyaml/parser/parser.rb'

# Offense count: 11
# Offense count: 13
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 194
3 changes: 1 addition & 2 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
Dir.glob('features/sandbox/**/*', File::FNM_DOTMATCH).each do |file_name|
next unless File.file? file_name

read_mode = 'r'
read_mode = 'rb' if /\.bin$/.match?(file_name)
'rb' if /\.bin$/.match?(file_name)
file = File.open(file_name, 'r')
file_contents = file.read
file.close
Expand Down
6 changes: 3 additions & 3 deletions hiera-eyaml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Gem::Specification.new do |gem|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.require_paths = ['lib']

gem.add_runtime_dependency 'highline', '>= 2.1', '< 4'
gem.add_runtime_dependency 'optimist', '~> 3.1'
gem.add_dependency 'highline', '>= 2.1', '< 4'
gem.add_dependency 'optimist', '~> 3.1'

gem.add_development_dependency 'rake', '~> 13.2', '>= 13.2.1'
gem.add_development_dependency 'rspec-expectations', '~> 3.13'
gem.add_development_dependency 'voxpupuli-rubocop', '~> 2.8.0'
gem.add_development_dependency 'voxpupuli-rubocop', '~> 3.1.0'

gem.required_ruby_version = '>= 2.7', ' < 4'
end
6 changes: 1 addition & 5 deletions lib/hiera/backend/eyaml/highlinehelper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ def self.read_password

def self.confirm?(message)
result = ask("#{message} (y/N): ")
if result.downcase == 'y' or result.downcase == 'yes'
true
else
false
end
%w[y yes].include?(result.downcase) || false
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/backend/eyaml/logginghelper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.print_message(args)
if hiera?
Hiera.send(hiera_loglevel, message) if threshold.nil? or Eyaml.verbosity_level > threshold
elsif threshold.nil? or Eyaml.verbosity_level > threshold
STDERR.puts self.colorize( message, cli_color )
STDERR.puts self.colorize(message, cli_color)
end
end

Expand Down
8 changes: 2 additions & 6 deletions lib/hiera/backend/eyaml/parser/encrypted_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def initialize

def create_token(string)
md = @regex.match(string)
if EncToken.encrypt_unchanged == false && !md[1].nil? && (md[3] == EncToken.tokens_map[md[1]])
return EncToken.plain_text_value(:string, md[3], md[2], string, md[1])
end
return EncToken.plain_text_value(:string, md[3], md[2], string, md[1]) if EncToken.encrypt_unchanged == false && !md[1].nil? && (md[3] == EncToken.tokens_map[md[1]])

EncToken.decrypted_value(:string, md[3], md[2], string, md[1])
end
Expand All @@ -161,9 +159,7 @@ def initialize

def create_token(string)
md = @regex.match(string)
if EncToken.encrypt_unchanged == false && !md[2].nil? && (md[4] == EncToken.tokens_map[md[2]])
return EncToken.plain_text_value(:string, md[4], md[3], string, md[2])
end
return EncToken.plain_text_value(:string, md[4], md[3], string, md[2]) if EncToken.encrypt_unchanged == false && !md[2].nil? && (md[4] == EncToken.tokens_map[md[2]])

EncToken.decrypted_value(:block, md[4], md[3], string, md[2], md[1])
end
Expand Down
1 change: 0 additions & 1 deletion lib/hiera/backend/eyaml/parser/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Parser
class TokenType
attr_reader :regex

@regex
def create_token(_string)
raise 'Abstract method called'
end
Expand Down
1 change: 0 additions & 1 deletion lib/hiera/backend/eyaml/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def self.find
dependency = spec.dependencies.find { |d| d.name == 'hiera-eyaml' }
next if dependency && !dependency.requirement.satisfied_by?(this_version)

file = nil
file = if gem_version >= Gem::Version.new('1.8.0')
spec.matches_for_glob('**/eyaml_init.rb').first
else
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/backend/eyaml/subcommand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.attach_option(opt)
def self.find(commandname = 'unknown_command')
begin
require "hiera/backend/eyaml/subcommands/#{commandname.downcase}"
rescue Exception => e
rescue Exception
require 'hiera/backend/eyaml/subcommands/unknown_command'
return Hiera::Backend::Eyaml::Subcommands::UnknownCommand
end
Expand Down
1 change: 0 additions & 1 deletion lib/hiera/backend/eyaml/subcommands/unknown_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def self.description
end

def self.execute
subcommands = Eyaml.subcommands
puts <<~EOS
Unknown subcommand#{': ' + Eyaml.subcommand if Eyaml.subcommand}

Expand Down
2 changes: 0 additions & 2 deletions lib/hiera/backend/eyaml/subcommands/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def self.description
end

def self.execute
plugin_versions = {}

Eyaml::LoggingHelper.info "hiera-eyaml (core): #{Eyaml::VERSION}"

Plugins.plugins.each do |plugin|
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/backend/eyaml/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.convert_to_utf_8(string)
return string if orig_encoding == Encoding::UTF_8

string.dup.force_encoding(Encoding::UTF_8)
rescue EncodingError => e
rescue EncodingError
warn "Unable to encode to \"Encoding::UTF_8\" using the original \"#{orig_encoding}\""
string
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/backend/eyaml_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def decrypt(data)
end

def encrypted?(data)
/.*ENC\[.*\]/.match?(data) ? true : false
/.*ENC\[.*\]/.match?(data) || false
end

def parse_answer(data, scope, extra_data = {})
Expand Down