diff --git a/.github/workflows/pr_tests.yml b/.github/workflows/pr_tests.yml index d21047e2..62dfeb04 100644 --- a/.github/workflows/pr_tests.yml +++ b/.github/workflows/pr_tests.yml @@ -5,10 +5,11 @@ # ------------------------------------------------------------------------------ # Release Puppet Ruby EOL # PE 2021.Y 7.x 2.7 Quarterly updates +# PE 2023.Y 8.x 3.2 Quarterly updates # -# https://puppet.com/docs/pe/2018.1/component_versions_in_recent_pe_releases.html -# https://puppet.com/misc/puppet-enterprise-lifecycle -# https://puppet.com/docs/pe/2018.1/overview/getting_support_for_pe.html +# https://www.puppet.com/docs/pe/latest/component_versions_in_recent_pe_releases.html +# https://www.puppet.com/products/puppet-enterprise/support-lifecycle +# https://www.puppet.com/docs/pe/latest/getting_support_for_pe # ============================================================================== # # https://docs.github.com/en/actions/reference/events-that-trigger-workflows @@ -35,7 +36,7 @@ jobs: - name: "Install Ruby ${{matrix.puppet.ruby_version}}" uses: ruby/setup-ruby@v1 with: - ruby-version: 2.5 + ruby-version: 2.7 bundler-cache: true - run: | bundle show @@ -49,7 +50,7 @@ jobs: - name: 'Install Ruby ${{matrix.puppet.ruby_version}}' uses: ruby/setup-ruby@v1 with: - ruby-version: 2.5 + ruby-version: 2.7 bundler-cache: true - name: 'Ensure executables are installed' run: | @@ -75,6 +76,9 @@ jobs: - label: 'Puppet 7.x' puppet_version: '~> 7.0' ruby_version: '2.7' + - label: 'Puppet 8.x' + puppet_version: '~> 8.0' + ruby_version: '3.2' env: PUPPET_VERSION: '${{matrix.puppet.puppet_version}}' steps: diff --git a/.rubocop.yml b/.rubocop.yml index b4bb8979..5bc12b23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,10 @@ -require: rubocop-rspec +--- +require: + - rubocop-performance + - rubocop-rspec + - rubocop-rake AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.7 Include: - '*.rb' - 'rakelib/*.rake' @@ -19,489 +23,489 @@ AllCops: - Guardfile - Vagrantfile Layout/ConditionPosition: - Enabled: True + Enabled: true Lint/ElseLayout: - Enabled: True + Enabled: true Lint/UnreachableCode: - Enabled: True + Enabled: true -Lint/UselessComparison: - Enabled: True +Lint/BinaryOperatorWithIdenticalOperands: + Enabled: true Lint/EnsureReturn: - Enabled: True + Enabled: true -Lint/HandleExceptions: - Enabled: True +Lint/SuppressedException: + Enabled: true Lint/LiteralAsCondition: - Enabled: True + Enabled: true Lint/ShadowingOuterLocalVariable: - Enabled: True + Enabled: true Lint/LiteralInInterpolation: - Enabled: True + Enabled: true Style/HashSyntax: - Enabled: False + Enabled: false Style/RedundantReturn: - Enabled: True + Enabled: true Layout/EndOfLine: - Enabled: False + Enabled: false Lint/AmbiguousOperator: - Enabled: True + Enabled: true Lint/AssignmentInCondition: - Enabled: True + Enabled: true Layout/SpaceBeforeComment: - Enabled: True + Enabled: true Style/AndOr: - Enabled: True + Enabled: true Style/RedundantSelf: - Enabled: True + Enabled: true Metrics/BlockLength: - Enabled: False + Enabled: false # Method length is not necessarily an indicator of code quality Metrics/MethodLength: - Enabled: False + Enabled: false # Module length is not necessarily an indicator of code quality Metrics/ModuleLength: - Enabled: False + Enabled: false Style/WhileUntilModifier: - Enabled: True + Enabled: true Lint/AmbiguousRegexpLiteral: - Enabled: True + Enabled: true Security/Eval: - Enabled: True + Enabled: true Layout/BlockAlignment: - Enabled: True + Enabled: true Layout/DefEndAlignment: - Enabled: True + Enabled: true Layout/EndAlignment: - Enabled: True + Enabled: true Lint/DeprecatedClassMethods: - Enabled: True + Enabled: true Lint/Loop: - Enabled: True + Enabled: true Lint/ParenthesesAsGroupedExpression: - Enabled: True + Enabled: true Lint/RescueException: - Enabled: True + Enabled: true -Lint/StringConversionInInterpolation: - Enabled: True +Lint/RedundantStringCoercion: + Enabled: true Lint/UnusedBlockArgument: - Enabled: True + Enabled: true Lint/UnusedMethodArgument: - Enabled: True + Enabled: true Lint/UselessAccessModifier: - Enabled: True + Enabled: true Lint/UselessAssignment: - Enabled: True + Enabled: true Lint/Void: - Enabled: True + Enabled: true Layout/AccessModifierIndentation: - Enabled: True + Enabled: true Naming/AccessorMethodName: - Enabled: True + Enabled: true Style/Alias: - Enabled: True + Enabled: true -Layout/AlignArray: - Enabled: True +Layout/ArrayAlignment: + Enabled: true -Layout/AlignHash: - Enabled: True +Layout/HashAlignment: + Enabled: true -Layout/AlignParameters: - Enabled: True +Layout/ParameterAlignment: + Enabled: true Metrics/BlockNesting: - Enabled: True + Enabled: true Style/AsciiComments: - Enabled: True + Enabled: true Style/Attr: - Enabled: True + Enabled: true -Style/BracesAroundHashParameters: - Enabled: True +# Style/BracesAroundHashParameters: +# Enabled: true Style/CaseEquality: - Enabled: True + Enabled: true Layout/CaseIndentation: - Enabled: True + Enabled: true Style/CharacterLiteral: - Enabled: True + Enabled: true Naming/ClassAndModuleCamelCase: - Enabled: True + Enabled: true Style/ClassAndModuleChildren: - Enabled: False + Enabled: false Style/ClassCheck: - Enabled: True + Enabled: true # Class length is not necessarily an indicator of code quality Metrics/ClassLength: - Enabled: False + Enabled: false Style/ClassMethods: - Enabled: True + Enabled: true Style/ClassVars: - Enabled: True + Enabled: true Style/WhenThen: - Enabled: True + Enabled: true Style/WordArray: - Enabled: True + Enabled: true -Style/UnneededPercentQ: - Enabled: True +Style/RedundantPercentQ: + Enabled: true -Layout/Tab: - Enabled: True +Layout/IndentationStyle: + Enabled: true Layout/SpaceBeforeSemicolon: - Enabled: True + Enabled: true -Layout/TrailingBlankLines: - Enabled: True +Layout/TrailingEmptyLines: + Enabled: true Layout/SpaceInsideBlockBraces: - Enabled: True + Enabled: true Layout/SpaceInsideHashLiteralBraces: - Enabled: True + Enabled: true Layout/SpaceInsideParens: - Enabled: True + Enabled: true Layout/LeadingCommentSpace: - Enabled: True + Enabled: true Layout/SpaceBeforeFirstArg: - Enabled: True + Enabled: true Layout/SpaceAfterColon: - Enabled: True + Enabled: true Layout/SpaceAfterComma: - Enabled: True + Enabled: true Layout/SpaceAfterMethodName: - Enabled: True + Enabled: true Layout/SpaceAfterNot: - Enabled: True + Enabled: true Layout/SpaceAfterSemicolon: - Enabled: True + Enabled: true Layout/SpaceAroundEqualsInParameterDefault: - Enabled: True + Enabled: true Layout/SpaceAroundOperators: - Enabled: True + Enabled: true Layout/SpaceBeforeBlockBraces: - Enabled: True + Enabled: true Layout/SpaceBeforeComma: - Enabled: True + Enabled: true Style/CollectionMethods: - Enabled: True + Enabled: true Layout/CommentIndentation: - Enabled: True + Enabled: true Style/ColonMethodCall: - Enabled: True + Enabled: true Style/CommentAnnotation: - Enabled: True + Enabled: true # 'Complexity' is very relative Metrics/CyclomaticComplexity: - Enabled: False + Enabled: false Naming/ConstantName: - Enabled: True + Enabled: true Style/Documentation: - Enabled: False + Enabled: false Style/DefWithParentheses: - Enabled: True + Enabled: true Style/PreferredHashMethods: - Enabled: True + Enabled: true Layout/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: - Enabled: True + Enabled: true Style/EachWithObject: - Enabled: True + Enabled: true Layout/EmptyLineBetweenDefs: - Enabled: True + Enabled: true -Layout/IndentArray: - Enabled: True +Layout/FirstArrayElementIndentation: + Enabled: true -Layout/IndentHash: - Enabled: True +Layout/FirstHashElementIndentation: + Enabled: true Layout/IndentationConsistency: - Enabled: True + Enabled: true Layout/IndentationWidth: - Enabled: True + Enabled: true Layout/EmptyLines: - Enabled: True + Enabled: true Layout/EmptyLinesAroundAccessModifier: - Enabled: True + Enabled: true Style/EmptyLiteral: - Enabled: True + Enabled: true # Configuration parameters: AllowURI, URISchemes. Layout/TrailingWhitespace: - Enabled: True + Enabled: true -Metrics/LineLength: - Enabled: False +Layout/LineLength: + Enabled: false Naming/BinaryOperatorParameterName: - Enabled: True + Enabled: true Style/CommandLiteral: EnforcedStyle: percent_x - Enabled: True + Enabled: true Style/MethodCallWithoutArgsParentheses: - Enabled: True + Enabled: true Style/MethodDefParentheses: - Enabled: True + Enabled: true Style/LineEndConcatenation: - Enabled: True + Enabled: true Style/StringLiterals: - Enabled: True + Enabled: true Style/TrailingCommaInArguments: - Enabled: True + Enabled: true Style/GlobalVars: - Enabled: True + Enabled: true Style/GuardClause: - Enabled: True + Enabled: true Style/IfUnlessModifier: - Enabled: True + Enabled: true Style/MultilineIfThen: - Enabled: True + Enabled: true Style/NegatedIf: - Enabled: True + Enabled: true Style/NegatedWhile: - Enabled: True + Enabled: true Style/Next: - Enabled: True + Enabled: true Style/SingleLineBlockParams: - Enabled: True + Enabled: true Style/SingleLineMethods: - Enabled: True + Enabled: true Style/SpecialGlobalVars: - Enabled: True + Enabled: true Style/TrivialAccessors: - Enabled: True + Enabled: true Style/UnlessElse: - Enabled: True + Enabled: true Style/VariableInterpolation: - Enabled: True + Enabled: true Naming/VariableName: - Enabled: True + Enabled: true Style/WhileUntilDo: - Enabled: True + Enabled: true Style/EvenOdd: - Enabled: True + Enabled: true Naming/FileName: - Enabled: True + Enabled: true Style/For: - Enabled: True + Enabled: true Style/Lambda: - Enabled: True + Enabled: true Naming/MethodName: - Enabled: True + Enabled: true Style/MultilineTernaryOperator: - Enabled: True + Enabled: true Style/NestedTernaryOperator: - Enabled: True + Enabled: true Style/NilComparison: - Enabled: True + Enabled: true Style/FormatString: - Enabled: True + Enabled: true Style/MultilineBlockChain: - Enabled: True + Enabled: true Style/Semicolon: - Enabled: True + Enabled: true Style/SignalException: EnforcedStyle: semantic - Enabled: True + Enabled: true Style/NonNilCheck: - Enabled: True + Enabled: true Style/Not: - Enabled: True + Enabled: true Style/NumericLiterals: - Enabled: True + Enabled: true Style/OneLineConditional: - Enabled: True + Enabled: true Style/ParenthesesAroundCondition: - Enabled: True + Enabled: true Style/PercentLiteralDelimiters: - Enabled: True + Enabled: true Style/PerlBackrefs: - Enabled: True + Enabled: true Naming/PredicateName: - Enabled: True + Enabled: true Style/RedundantException: - Enabled: True + Enabled: true Style/SelfAssignment: - Enabled: True + Enabled: true Style/Proc: - Enabled: True + Enabled: true Style/RaiseArgs: - Enabled: True + Enabled: true Style/RedundantBegin: - Enabled: True + Enabled: true Style/RescueModifier: - Enabled: True + Enabled: true # based on https://github.com/voxpupuli/modulesync_config/issues/168 Style/RegexpLiteral: EnforcedStyle: percent_r - Enabled: True + Enabled: true Lint/UnderscorePrefixedVariableName: - Enabled: True + Enabled: true Metrics/ParameterLists: - Enabled: False + Enabled: false Lint/RequireParentheses: - Enabled: True + Enabled: true Style/ModuleFunction: - Enabled: True + Enabled: true Lint/Debugger: - Enabled: True + Enabled: true Style/IfWithSemicolon: - Enabled: True + Enabled: true Style/Encoding: - Enabled: True + Enabled: true Style/BlockDelimiters: - Enabled: True + Enabled: true Layout/MultilineBlockLayout: - Enabled: True + Enabled: true # 'Complexity' is very relative Metrics/AbcSize: - Enabled: False + Enabled: false # 'Complexity' is very relative Metrics/PerceivedComplexity: - Enabled: False + Enabled: false Layout/ClosingParenthesisIndentation: - Enabled: True + Enabled: true # RSpec @@ -511,26 +515,26 @@ RSpec/BeforeAfterAll: # We don't use rspec in this way RSpec/DescribeClass: - Enabled: False + Enabled: false # Example length is not necessarily an indicator of code quality RSpec/ExampleLength: - Enabled: False + Enabled: false RSpec/NamedSubject: - Enabled: False + Enabled: false # disabled for now since they cause a lot of issues # these issues aren't easy to fix RSpec/RepeatedDescription: - Enabled: False + Enabled: false RSpec/NestedGroups: - Enabled: False + Enabled: false # this is broken on ruby1.9 -Layout/IndentHeredoc: - Enabled: False +Layout/HeredocIndentation: + Enabled: false # disable Yaml safe_load. This is needed to support ruby2.0.0 development envs Security/YAMLLoad: @@ -545,8 +549,17 @@ Style/FormatStringToken: RSpec/FilePath: Enabled: false -Naming/UncommunicativeMethodParamName: - AllowedNames: [io, id, to, by, on, in, at, ip, nw] +Naming/MethodParameterName: + AllowedNames: + - 'io' + - 'id' + - 'to' + - 'by' + - 'on' + - 'in' + - 'at' + - 'ip' + - 'nw' # SIMP-specific additions: @@ -557,3 +570,323 @@ RSpec/HookArgument: RSpec/EmptyLineAfterHook: Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: true +Gemspec/RequireMFA: + Enabled: true +Layout/LineContinuationLeadingSpace: + Enabled: true +Layout/LineContinuationSpacing: + Enabled: true +Layout/LineEndStringConcatenationIndentation: + Enabled: true +Layout/SpaceBeforeBrackets: + Enabled: true +Lint/AmbiguousAssignment: + Enabled: true +Lint/AmbiguousOperatorPrecedence: + Enabled: true +Lint/AmbiguousRange: + Enabled: true +Lint/ConstantOverwrittenInRescue: + Enabled: true +Lint/DeprecatedConstants: + Enabled: true +Lint/DuplicateBranch: + Enabled: true +Lint/DuplicateRegexpCharacterClassElement: + Enabled: true +Lint/EmptyBlock: + Enabled: true +Lint/EmptyClass: + Enabled: true +Lint/EmptyInPattern: + Enabled: true +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: true +Lint/LambdaWithoutLiteralBlock: + Enabled: true +Lint/NoReturnInBeginEndBlocks: + Enabled: true +Lint/NonAtomicFileOperation: + Enabled: true +Lint/NumberedParameterAssignment: + Enabled: true +Lint/OrAssignmentToConstant: + Enabled: true +Lint/RedundantDirGlobSort: + Enabled: true +Lint/RefinementImportMethods: + Enabled: true +Lint/RequireRangeParentheses: + Enabled: true +Lint/RequireRelativeSelfPath: + Enabled: true +Lint/SymbolConversion: + Enabled: true +Lint/ToEnumArguments: + Enabled: true +Lint/TripleQuotes: + Enabled: true +Lint/UnexpectedBlockArity: + Enabled: true +Lint/UnmodifiedReduceAccumulator: + Enabled: true +Lint/UselessRuby2Keywords: + Enabled: true +Naming/BlockForwarding: + Enabled: true +Security/CompoundHash: + Enabled: true +Security/IoMethods: + Enabled: true +Style/ArgumentsForwarding: + Enabled: true +Style/CollectionCompact: + Enabled: true +Style/DocumentDynamicEvalDefinition: + Enabled: true +Style/EmptyHeredoc: + Enabled: true +Style/EndlessMethod: + Enabled: true +Style/EnvHome: + Enabled: true +Style/FetchEnvVar: + Enabled: true +Style/FileRead: + Enabled: true +Style/FileWrite: + Enabled: true +Style/HashConversion: + Enabled: true +Style/HashExcept: + Enabled: true +Style/IfWithBooleanLiteralBranches: + Enabled: true +Style/InPatternThen: + Enabled: true +Style/MagicCommentFormat: + Enabled: true +Style/MapCompactWithConditionalBlock: + Enabled: true +Style/MapToHash: + Enabled: true +Style/MultilineInPatternThen: + Enabled: true +Style/NegatedIfElseCondition: + Enabled: true +Style/NestedFileDirname: + Enabled: true +Style/NilLambda: + Enabled: true +Style/NumberedParameters: + Enabled: true +Style/NumberedParametersLimit: + Enabled: true +Style/ObjectThen: + Enabled: true +Style/OpenStructUse: + Enabled: true +Style/QuotedSymbols: + Enabled: true +Style/RedundantArgument: + Enabled: true +Style/RedundantInitialize: + Enabled: true +Style/RedundantSelfAssignmentBranch: + Enabled: true +Style/SelectByRegexp: + Enabled: true +Style/StringChars: + Enabled: true +Style/SwapValues: + Enabled: true +Gemspec/DevelopmentDependencies: + Enabled: true +Lint/DuplicateMagicComment: + Enabled: true +Lint/DuplicateMatchPattern: + Enabled: true +Lint/MixedCaseRange: + Enabled: true +Lint/RedundantRegexpQuantifiers: + Enabled: true +Lint/UselessRescue: + Enabled: true +Metrics/CollectionLiteralLength: + Enabled: true +Style/ArrayIntersect: + Enabled: true +Style/ComparableClamp: + Enabled: true +Style/ConcatArrayLiterals: + Enabled: true +Style/DataInheritance: + Enabled: true +Style/DirEmpty: + Enabled: true +Style/ExactRegexpMatch: + Enabled: true +Style/FileEmpty: + Enabled: true +Style/MapToSet: + Enabled: true +Style/MinMaxComparison: + Enabled: true +Style/OperatorMethodCall: + Enabled: true +Style/RedundantArrayConstructor: + Enabled: true +Style/RedundantConstantBase: + Enabled: true +Style/RedundantCurrentDirectoryInPath: + Enabled: true +Style/RedundantDoubleSplatHashBraces: + Enabled: true +Style/RedundantEach: + Enabled: true +Style/RedundantFilterChain: + Enabled: true +Style/RedundantHeredocDelimiterQuotes: + Enabled: true +Style/RedundantLineContinuation: + Enabled: true +Style/RedundantRegexpArgument: + Enabled: true +Style/RedundantRegexpConstructor: + Enabled: true +Style/RedundantStringEscape: + Enabled: true +Style/ReturnNilInPredicateMethodDefinition: + Enabled: true +Style/SingleLineDoEndBlock: + Enabled: true +Style/YAMLFileRead: + Enabled: true +Capybara/ClickLinkOrButtonStyle: + Enabled: true +Capybara/MatchStyle: + Enabled: true +Capybara/NegationMatcher: + Enabled: true +Capybara/SpecificActions: + Enabled: true +Capybara/SpecificFinders: + Enabled: true +Capybara/SpecificMatcher: + Enabled: true +Capybara/RSpec/HaveSelector: + Enabled: true +Capybara/RSpec/PredicateMatcher: + Enabled: true +FactoryBot/AssociationStyle: + Enabled: true +FactoryBot/ConsistentParenthesesStyle: + Enabled: true +FactoryBot/FactoryAssociationWithStrategy: + Enabled: true +FactoryBot/FactoryNameStyle: + Enabled: true +FactoryBot/IdSequence: + Enabled: true +FactoryBot/RedundantFactoryOption: + Enabled: true +FactoryBot/SyntaxMethods: + Enabled: true +RSpec/BeEmpty: + Enabled: true +RSpec/BeEq: + Enabled: true +RSpec/BeNil: + Enabled: true +RSpec/ChangeByZero: + Enabled: true +RSpec/ContainExactly: + Enabled: true +RSpec/DuplicatedMetadata: + Enabled: true +RSpec/EmptyMetadata: + Enabled: true +RSpec/Eq: + Enabled: true +RSpec/ExcessiveDocstringSpacing: + Enabled: true +RSpec/IdenticalEqualityAssertion: + Enabled: true +RSpec/IndexedLet: + Enabled: true +RSpec/MatchArray: + Enabled: true +RSpec/MetadataStyle: + Enabled: true +RSpec/NoExpectationExample: + Enabled: true +RSpec/PendingWithoutReason: + Enabled: true +RSpec/ReceiveMessages: + Enabled: true +RSpec/RedundantAround: + Enabled: true +RSpec/SkipBlockInsideExample: + Enabled: true +RSpec/SortMetadata: + Enabled: true +RSpec/SpecFilePathFormat: + Enabled: true +RSpec/SpecFilePathSuffix: + Enabled: true +RSpec/SubjectDeclaration: + Enabled: true +RSpec/VerifiedDoubleReference: + Enabled: true +RSpec/Rails/AvoidSetupHook: + Enabled: true +RSpec/Rails/HaveHttpStatus: + Enabled: true +RSpec/Rails/InferredSpecType: + Enabled: true +RSpec/Rails/MinitestAssertions: + Enabled: true +RSpec/Rails/NegationBeValid: + Enabled: true +RSpec/Rails/TravelAround: + Enabled: true +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CollectionLiteralInLoop: + Enabled: true +Performance/ConcurrentMonotonicTime: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MapCompact: + Enabled: true +Performance/MapMethodChain: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantEqualityComparisonBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantSplitRegexpArgument: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringIdentifierArgument: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true diff --git a/Gemfile b/Gemfile index c0eccd39..d07ab8d4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ -gem_sources = ENV.fetch('GEM_SERVERS','https://rubygems.org').split(/[, ]+/) +# frozen_string_literal: true + +gem_sources = ENV.fetch('GEM_SERVERS', 'https://rubygems.org').split(%r{[, ]+}) gem_sources.each { |gem_source| source gem_source } @@ -9,12 +11,11 @@ gemspec gem 'bundler' gem 'facter' gem 'highline', :path => 'ext/gems/highline' -gem 'puppet', ENV.fetch('PUPPET_VERSION', '~>7') -gem 'rake', '>= 12.3.3' +gem 'puppet', ENV.fetch('PUPPET_VERSION', ['>= 7', '< 9']) gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['>= 5.12.1', '< 6'] +gem 'r10k', ENV.fetch('R10k_VERSION', '~> 4') gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.28.0', '< 2'] -gem 'r10k', ENV.fetch('R10k_VERSION', '~>3') group :testing do # to parse YUM repo files in `simp config` test @@ -40,6 +41,7 @@ group :development do gem 'rubocop' gem 'rubocop-performance' + gem 'rubocop-rake' gem 'rubocop-rspec' end @@ -48,10 +50,10 @@ extra_gemfiles = [ ENV['EXTRA_GEMFILE'] || '', "#{__FILE__}.project", "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), + File.join(Dir.home, '.gemfile') ] extra_gemfiles.each do |gemfile| if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) + eval(File.read(gemfile), binding) # rubocop:disable Security/Eval end end diff --git a/lib/simp/cli/commands/bootstrap.rb b/lib/simp/cli/commands/bootstrap.rb index 9bc43c1e..bff058ba 100755 --- a/lib/simp/cli/commands/bootstrap.rb +++ b/lib/simp/cli/commands/bootstrap.rb @@ -201,7 +201,7 @@ def configure_bootstrap_puppetserver ] conf_files.each do |file| - if File.exists?(file) + if File.exist?(file) backup_dir = File.join(@bootstrap_backup, File.dirname(file)) FileUtils.mkdir_p(backup_dir) FileUtils.cp(file, backup_dir) @@ -212,7 +212,7 @@ def configure_bootstrap_puppetserver # /etc/puppetlabs/puppet/auth.conf is installed by some versions of puppet-agent. # SIMP manages auth.conf in /etc/puppetlabs/puppetserver/conf.d. Back up and # remove existing /etc/puppetlabs/puppet/auth.conf file. - if File.exists?('/etc/puppetlabs/puppet/auth.conf') + if File.exist?('/etc/puppetlabs/puppet/auth.conf') FileUtils.rm('/etc/puppetlabs/puppet/auth.conf') info("Removed /etc/puppetlabs/puppet/auth.conf", 'green') end @@ -325,7 +325,7 @@ def ensure_puppet_agent_stopped FileUtils.rm_f(agent_run_lockfile) info("Successfully removed agent lock file #{agent_run_lockfile}", 'green') else - run_locked = File.exists?(agent_run_lockfile) + run_locked = File.exist?(agent_run_lockfile) # TODO: make the following spinner a function; it's used in ensure_puppetserver_running as well. if run_locked info("Detected puppet agent run lockfile #{agent_run_lockfile}", 'magenta') @@ -335,7 +335,7 @@ def ensure_puppet_agent_stopped stages = ["\\",'|','/','-'] rest = 0.1 while run_locked do - run_locked = File.exists?(agent_run_lockfile) + run_locked = File.exist?(agent_run_lockfile) stages.each{ |x| $stdout.flush print "> #{x}\r" @@ -365,7 +365,7 @@ def ensure_puppet_processes_stopped confdir = Simp::Cli::Utils.puppet_info[:config]['confdir'] routes_yaml = File.join(confdir, 'routes.yaml') - if File.exists?(routes_yaml) + if File.exist?(routes_yaml) backup_dir = File.join(@bootstrap_backup, confdir) FileUtils.mkdir_p(backup_dir) backup_routes_yaml = File.join(backup_dir, 'routes.yaml') @@ -677,7 +677,7 @@ def print_intro def set_up_logger # Open log file logfilepath = File.dirname(File.expand_path(@bootstrap_log)) - FileUtils.mkpath(logfilepath) unless File.exists?(logfilepath) + FileUtils.mkpath(logfilepath) unless File.exist?(logfilepath) @logfile = File.open(@bootstrap_log, 'w') end diff --git a/lib/simp/cli/commands/doc.rb b/lib/simp/cli/commands/doc.rb index 507b73fe..0473ce7e 100644 --- a/lib/simp/cli/commands/doc.rb +++ b/lib/simp/cli/commands/doc.rb @@ -28,7 +28,7 @@ def run(args) main_page = %x{rpm -ql simp-doc | grep html/index.html$ | head -1}.strip.chomp - unless File.exists?(main_page) + unless File.exist?(main_page) err_msg = "Could not find the SIMP documentation. Please ensure that you can access '#{main_page}'." raise Simp::Cli::ProcessingError.new(err_msg) end diff --git a/lib/simp/cli/config/items/action/create_simp_server_fqdn_yaml_action.rb b/lib/simp/cli/config/items/action/create_simp_server_fqdn_yaml_action.rb index fea3fd6e..efb23cc7 100644 --- a/lib/simp/cli/config/items/action/create_simp_server_fqdn_yaml_action.rb +++ b/lib/simp/cli/config/items/action/create_simp_server_fqdn_yaml_action.rb @@ -40,7 +40,7 @@ def apply @host_yaml = File.join( File.dirname( @template_file ), "#{fqdn}.yaml" ) @applied_status = :failed - if !File.exists?(@template_file) && !File.exists?(@host_yaml) && File.exists?(@alt_file) + if !File.exist?(@template_file) && !File.exist?(@host_yaml) && File.exist?(@alt_file) # Can get here if # (1) RPM/ISO install (so /usr/share/simp exists) # (2) Operator runs simp config more than once but with different hostnames @@ -55,8 +55,8 @@ def apply end info( "Creating #{File.basename(@host_yaml)} from #{File.basename(@template_file)} template" ) - if File.exists?(@template_file) - if File.exists?( @host_yaml ) + if File.exist?(@template_file) + if File.exist?( @host_yaml ) diff = `diff #{@host_yaml} #{@template_file}` if diff.empty? @applied_status = :succeeded @@ -91,7 +91,7 @@ def apply end end else - if File.exists?(@host_yaml) + if File.exist?(@host_yaml) @applied_status = :unnecessary @applied_status_detail = "Template already moved to #{File.basename(@host_yaml)}" message = "#{File.basename(@host_yaml)} creation not required:\n" + diff --git a/lib/simp/cli/config/items/action/set_site_scenario_action.rb b/lib/simp/cli/config/items/action/set_site_scenario_action.rb index 414bfef4..cca28797 100644 --- a/lib/simp/cli/config/items/action/set_site_scenario_action.rb +++ b/lib/simp/cli/config/items/action/set_site_scenario_action.rb @@ -19,7 +19,7 @@ def apply simp_scenario = get_item('cli::simp::scenario').value site_pp = File.join(@puppet_env_info[:puppet_env_dir], 'manifests', 'site.pp') - if File.exists?(site_pp) + if File.exist?(site_pp) backup_file = "#{site_pp}.#{@start_time.strftime('%Y%m%dT%H%M%S')}" info( "Backing up #{site_pp} to #{backup_file}" ) FileUtils.cp(site_pp, backup_file) diff --git a/lib/simp/cli/config/items/data/simp_options_ldap_master.rb b/lib/simp/cli/config/items/data/simp_options_ldap_master.rb index 1fc71a8d..b5b68f09 100644 --- a/lib/simp/cli/config/items/data/simp_options_ldap_master.rb +++ b/lib/simp/cli/config/items/data/simp_options_ldap_master.rb @@ -25,6 +25,8 @@ def get_recommended_value end def validate item + return false unless item.class == String + result = false if ( ( item =~ %r{^ldap[s]*://.+} ) ? true : false ) i = item.sub( %r{^ldap[s]*://}, '' ) diff --git a/lib/simp/cli/config/items/data/simp_options_ldap_uri.rb b/lib/simp/cli/config/items/data/simp_options_ldap_uri.rb index 4d286573..ccc1bc2e 100644 --- a/lib/simp/cli/config/items/data/simp_options_ldap_uri.rb +++ b/lib/simp/cli/config/items/data/simp_options_ldap_uri.rb @@ -27,6 +27,7 @@ def get_recommended_value def validate_item item + return false unless item.class == String result = false if ( ( item =~ %r{^ldap[s]*://.+} ) ? true : false ) i = item.sub( %r{^ldap[s]*://}, '' ) diff --git a/lib/simp/cli/config/items/data/simp_options_ntp_servers.rb b/lib/simp/cli/config/items/data/simp_options_ntp_servers.rb index d5f6af63..f684181d 100644 --- a/lib/simp/cli/config/items/data/simp_options_ntp_servers.rb +++ b/lib/simp/cli/config/items/data/simp_options_ntp_servers.rb @@ -36,7 +36,7 @@ def get_os_value( chronydfile = '/etc/chrony.conf', ntpdfile = '/etc/ntp.conf' ) file = chronydfile elsif Simp::Cli::Utils.systemctl_running?('ntpd') file = ntpdfile - elsif File.exists?(chronydfile) + elsif File.exist?(chronydfile) file = chronydfile else file = ntpdfile diff --git a/lib/simp/cli/config/items/yes_no_item.rb b/lib/simp/cli/config/items/yes_no_item.rb index e105c430..86664d2b 100644 --- a/lib/simp/cli/config/items/yes_no_item.rb +++ b/lib/simp/cli/config/items/yes_no_item.rb @@ -26,8 +26,9 @@ def validate( v ) # REJECTED: Override #query_ask using Highline's #agree? *** no, can't bool def highline_question_type lambda do |str| - return true if ( str =~ /^(y(es)?|true)$/i ? true : false || str.class == TrueClass ) - return false if ( str =~ /^(n(o)?|false)$/i ? true : false || str.class == FalseClass ) + return str if str.class == TrueClass || str.class == FalseClass + return true if str.to_s =~ /^(y(es)?|true)$/i + return false if str.to_s =~ /^(n(o)?|false)$/i nil end end diff --git a/lib/simp/cli/config/utils.rb b/lib/simp/cli/config/utils.rb index 531d73ae..91b6d5a9 100644 --- a/lib/simp/cli/config/utils.rb +++ b/lib/simp/cli/config/utils.rb @@ -40,6 +40,7 @@ def validate_fqdn fqdn def validate_ip ip + return false unless ip.respond_to?(:=~) # using the native 'resolv' class in order to minimize non-EL rubygems # snarfed from: # http://stackoverflow.com/questions/3634998/how-do-i-check-whether-a-value-in-a-string-is-an-ip-address @@ -49,6 +50,7 @@ def validate_ip ip def validate_hostname hostname + return false unless hostname.respond_to?(:=~) # based on: # http://stackoverflow.com/questions/2532053/validate-a-hostname-string # @@ -62,6 +64,7 @@ def validate_hostname hostname def validate_netmask( x ) + return false unless x.respond_to?(:=~) # a brute-force regexp that validates all possible valid netmasks nums = '(128|192|224|240|248|252|254)' znums = '(0|128|192|224|240|248|252|254)' diff --git a/lib/simp/cli/environment/puppet_dir_env.rb b/lib/simp/cli/environment/puppet_dir_env.rb index ca350283..a530f071 100644 --- a/lib/simp/cli/environment/puppet_dir_env.rb +++ b/lib/simp/cli/environment/puppet_dir_env.rb @@ -159,7 +159,7 @@ def puppetfile_generate f.puts puppetfile_modules.to_puppetfile end - if File.exists? @puppetfile_path + if File.exist? @puppetfile_path info "Skipping generation of Puppetfile (to include Puppetfile.simp) in '#{File.dirname(@puppetfile_path)}'".cyan info '>> File already exists'.cyan else diff --git a/simp-cli.gemspec b/simp-cli.gemspec index 168a1660..a11e09aa 100644 --- a/simp-cli.gemspec +++ b/simp-cli.gemspec @@ -43,11 +43,8 @@ Gem::Specification.new do |s| ### When the environment variable $SIMP_RPM_BUILD is set, the following ### dependencies will not be included in the .gemspec dependencies: #### ------------ - unless ( - ENV.fetch( 'SIMP_RPM_BUILD', false ) || \ - ENV.fetch( 'SIMP_CLI_GEMSPEC_NO_PUPPET_VERSION', false ) =~ /yes|true/ - ) - s.add_runtime_dependency 'puppet', '>= 6.22', '< 8' + unless ['yes', 'true'].include?(ENV['SIMP_RPM_BUILD']) || ['yes', 'true'].include?(ENV['SIMP_CLI_GEMSPEC_NO_PUPPET_VERSION']) + s.add_runtime_dependency 'puppet', '>= 7', '< 9' end #### ------------ @@ -60,9 +57,9 @@ Gem::Specification.new do |s| s.add_development_dependency 'guard-shell', '~> 0' s.add_development_dependency 'guard-rspec', '~> 4' s.add_development_dependency 'pry', '~> 0' - s.add_development_dependency 'pry-doc', '~> 0' - s.add_development_dependency 'dotenv', '~> 1' - s.add_development_dependency 'rubocop', '~> 0.49' + s.add_development_dependency 'pry-doc', '~> 1' + s.add_development_dependency 'dotenv', '~> 2' + s.add_development_dependency 'rubocop', '~> 1' # simple text description of external requirements (for humans to read) s.requirements << 'SIMP OS installation' diff --git a/spec/bin/simp_spec.rb b/spec/bin/simp_spec.rb index dbff3112..1adb5ce1 100644 --- a/spec/bin/simp_spec.rb +++ b/spec/bin/simp_spec.rb @@ -17,8 +17,8 @@ def execute(command, input_file = nil) # in case we have screwed up our test Timeout::timeout(30) { Process.wait(pid) } exitstatus = $?.nil? ? nil : $?.exitstatus - stdout = IO.read(stdout_file) if File.exists?(stdout_file) - stderr = IO.read(stderr_file) if File.exists?(stderr_file) + stdout = IO.read(stdout_file) if File.exist?(stdout_file) + stderr = IO.read(stderr_file) if File.exist?(stderr_file) { :exitstatus => exitstatus, :stdout => stdout, :stderr => stderr } ensure FileUtils.remove_entry_secure(log_tmp_dir) if log_tmp_dir @@ -43,8 +43,8 @@ def execute_and_signal(command, signal_type) Process.kill(signal_type, pid) Timeout::timeout(10) { Process.wait(pid) } exitstatus = $?.nil? ? nil : $?.exitstatus - stdout = IO.read(stdout_file) if File.exists?(stdout_file) - stderr = IO.read(stderr_file) if File.exists?(stderr_file) + stdout = IO.read(stdout_file) if File.exist?(stdout_file) + stderr = IO.read(stderr_file) if File.exist?(stderr_file) pipe_w.close { :exitstatus => exitstatus, :stdout => stdout, :stderr => stderr } ensure diff --git a/spec/lib/simp/cli/commands/config_read_answers_file_spec.rb b/spec/lib/simp/cli/commands/config_read_answers_file_spec.rb index f5523baa..c37fa2cf 100644 --- a/spec/lib/simp/cli/commands/config_read_answers_file_spec.rb +++ b/spec/lib/simp/cli/commands/config_read_answers_file_spec.rb @@ -14,7 +14,7 @@ end after :each do - FileUtils.chmod 0777, @yaml_file if File.exists?(@yaml_file) + FileUtils.chmod 0777, @yaml_file if File.exist?(@yaml_file) FileUtils.remove_entry_secure @tmp_dir end diff --git a/spec/lib/simp/cli/config/items/action/answers_yaml_file_writer_spec.rb b/spec/lib/simp/cli/config/items/action/answers_yaml_file_writer_spec.rb index fbf46b16..eecf1a59 100644 --- a/spec/lib/simp/cli/config/items/action/answers_yaml_file_writer_spec.rb +++ b/spec/lib/simp/cli/config/items/action/answers_yaml_file_writer_spec.rb @@ -89,7 +89,7 @@ it 'writes a file' do @ci.apply - expect( File.exists?( @tmp_file ) ).to be true + expect( File.exist?( @tmp_file ) ).to be true expect( @ci.applied_status ).to eq :succeeded end diff --git a/spec/lib/simp/cli/config/items/action/generate_certificates_action_spec.rb b/spec/lib/simp/cli/config/items/action/generate_certificates_action_spec.rb index ec5ff416..a115eee8 100644 --- a/spec/lib/simp/cli/config/items/action/generate_certificates_action_spec.rb +++ b/spec/lib/simp/cli/config/items/action/generate_certificates_action_spec.rb @@ -47,7 +47,7 @@ @ci.apply expect( @ci.applied_status ).to eq :succeeded dir = File.join( @tmp_dirs[:keydist], @fqdn ) - expect( File.exists? dir ).to be true + expect( File.exist? dir ).to be true end it 'reports :failed status on failure' do @@ -61,7 +61,7 @@ it 'reports :unnecessary status' do @ci.generate_certificates(@fqdn) dir = File.join( @tmp_dirs[:keydist], @fqdn ) - expect( File.exists? dir ).to be true + expect( File.exist? dir ).to be true @ci.apply expect( @ci.applied_status ).to eq :unnecessary expect(@ci.apply_summary).to match /Interim certificate generation for 'puppet.testing.fqdn' unnecessary:\n Certificates already exist/m @@ -108,7 +108,7 @@ end dir = File.join( @tmp_dirs[:keydist], @fqdn ) - expect( File.exists? dir ).to be true + expect( File.exist? dir ).to be true end end end diff --git a/spec/lib/simp/cli/config/yaml_utils_spec.rb b/spec/lib/simp/cli/config/yaml_utils_spec.rb index abe254d3..7de8960a 100644 --- a/spec/lib/simp/cli/config/yaml_utils_spec.rb +++ b/spec/lib/simp/cli/config/yaml_utils_spec.rb @@ -66,7 +66,7 @@ class YamlUtilsTester describe '#pair_to_yaml_tag' do { - 'nil' => { :value => nil, :exp => "key: \n" }, + 'nil' => { :value => nil, :exp => %r{\Akey:[[:blank:]]?\n\z} }, # Newer libyaml does not add a space when the value is nil 'boolean' => { :value => true, :exp => "key: true\n" }, 'integer' => { :value => 1, :exp => "key: 1\n" }, 'float' => { :value => 1.5, :exp => "key: 1.5\n" }, @@ -89,7 +89,11 @@ class YamlUtilsTester } }.each do |type, attr| it "returns a valid YAML tag for a #{type} value" do - expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to eq(attr[:exp]) + if attr[:exp].is_a?(Regexp) + expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to match(attr[:exp]) + else + expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to eq(attr[:exp]) + end end end end @@ -326,7 +330,8 @@ class YamlUtilsTester result = @tester.merge_or_replace_yaml_tag('pam::access::users', nil, file_info) expect( result ).to eq :replace expected = File.join(@files_dir, 'base_nil_replace.yaml') - expect( IO.read(@test_file) ).to eq IO.read(expected) + expect( IO.read(@test_file) ).to eq(IO.read(expected)) + .or eq(IO.read(expected).gsub(%r{:[[:blank:]]+$}, ':')) # Newer libyaml does not add a space when the value is nil YAML.load(IO.read(@test_file)) # verifies modified file is still valid YAML end