From eaae7b187fc7ee61ae49053264e0b157f9a853e4 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 17 Dec 2020 20:04:04 +0000 Subject: [PATCH 1/5] Update to pdk-templates and puppet-module-gems 1.0.0 --- .rubocop.yml | 420 +++++++++++++++++++++++++++++++++++++++++++++++--- .sync.yml | 12 +- Gemfile | 19 ++- appveyor.yml | 2 +- metadata.json | 4 +- 5 files changed, 410 insertions(+), 47 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3485379a..3aaa6965 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,12 @@ --- require: +- rubocop-performance - rubocop-rspec -- rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.4' Include: - - "./**/*.rb" + - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" @@ -18,17 +18,9 @@ AllCops: - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -inherit_from: ".rubocop_todo.yml" -Metrics/LineLength: +Layout/LineLength: Description: People have wide screens, use them. - Max: 300 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false + Max: 200 RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. @@ -41,10 +33,6 @@ Style/BlockDelimiters: Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining -Style/BracesAroundHashParameters: - Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0. - See https://github.com/rubocop-hq/rubocop/pull/7643 - Enabled: false Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact @@ -73,7 +61,7 @@ Style/TrailingCommaInArguments: Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma @@ -88,26 +76,170 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true -GetText/DecorateFunctionMessage: +Bundler/InsecureProtocolSource: + Enabled: false +Gemspec/DuplicatedAssignment: + Enabled: false +Gemspec/OrderedDependencies: + Enabled: false +Gemspec/RequiredRubyVersion: + Enabled: false +Gemspec/RubyVersionGlobalsUsage: + Enabled: false +Layout/ArgumentAlignment: + Enabled: false +Layout/BeginEndAlignment: + Enabled: false +Layout/ClosingHeredocIndentation: Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: +Layout/EmptyComment: Enabled: false -GetText/DecorateStringFormattingUsingPercent: +Layout/EmptyLineAfterGuardClause: + Enabled: false +Layout/EmptyLinesAroundArguments: + Enabled: false +Layout/EmptyLinesAroundAttributeAccessor: Enabled: false Layout/EndOfLine: Enabled: false -Layout/IndentHeredoc: +Layout/FirstArgumentIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Layout/LeadingEmptyLines: + Enabled: false +Layout/SpaceAroundMethodCallOperator: + Enabled: false +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: false +Layout/SpaceInsideReferenceBrackets: + Enabled: false +Lint/BigDecimalNew: + Enabled: false +Lint/BooleanSymbol: + Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false +Lint/DeprecatedOpenSSLConstant: + Enabled: false +Lint/DisjunctiveAssignmentInConstructor: + Enabled: false +Lint/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + Enabled: false +Lint/EmptyConditionalBody: + Enabled: false +Lint/EmptyFile: + Enabled: false +Lint/ErbNewArguments: + Enabled: false +Lint/FloatComparison: + Enabled: false +Lint/HashCompareByIdentity: + Enabled: false +Lint/IdentityComparison: + Enabled: false +Lint/InterpolationCheck: + Enabled: false +Lint/MissingCopEnableDirective: + Enabled: false +Lint/MixedRegexpCaptureTypes: + Enabled: false +Lint/NestedPercentLiteral: + Enabled: false +Lint/NonDeterministicRequireOrder: + Enabled: false +Lint/OrderedMagicComments: + Enabled: false +Lint/OutOfRangeRegexpRef: + Enabled: false +Lint/RaiseException: + Enabled: false +Lint/RedundantCopEnableDirective: + Enabled: false +Lint/RedundantRequireStatement: + Enabled: false +Lint/RedundantSafeNavigation: + Enabled: false +Lint/RedundantWithIndex: + Enabled: false +Lint/RedundantWithObject: + Enabled: false +Lint/RegexpAsCondition: + Enabled: false +Lint/ReturnInVoidContext: + Enabled: false +Lint/SafeNavigationConsistency: + Enabled: false +Lint/SafeNavigationWithEmpty: + Enabled: false +Lint/SelfAssignment: + Enabled: false +Lint/SendWithMixinArgument: + Enabled: false +Lint/ShadowedArgument: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Lint/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + Enabled: false +Lint/UnreachableLoop: + Enabled: false +Lint/UriEscapeUnescape: + Enabled: false +Lint/UriRegexp: + Enabled: false +Lint/UselessMethodDefinition: + Enabled: false +Lint/UselessTimes: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false +Metrics/BlockNesting: + Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: @@ -120,19 +252,261 @@ Metrics/ParameterLists: Enabled: false Metrics/PerceivedComplexity: Enabled: false +Migration/DepartmentName: + Enabled: false +Naming/AccessorMethodName: + Enabled: false +Naming/BlockParameterName: + Enabled: false +Naming/HeredocDelimiterCase: + Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false +Naming/MemoizedInstanceVariableName: + Enabled: false +Naming/MethodParameterName: + Enabled: false +Naming/RescuedExceptionsVariableName: + Enabled: false +Performance/BindCall: + Enabled: false +Performance/DeletePrefix: + Enabled: false +Performance/DeleteSuffix: + Enabled: false +Performance/InefficientHashSearch: + Enabled: false +Performance/UnfreezeString: + Enabled: false +Performance/UriDefaultParser: + Enabled: false +RSpec/Be: + Enabled: false +RSpec/Capybara/CurrentPathExpectation: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/Capybara/VisibilityMatcher: + Enabled: false +RSpec/ContextMethod: + Enabled: false +RSpec/ContextWording: + Enabled: false RSpec/DescribeClass: Enabled: false +RSpec/EmptyHook: + Enabled: false +RSpec/EmptyLineAfterExample: + Enabled: false +RSpec/EmptyLineAfterExampleGroup: + Enabled: false +RSpec/EmptyLineAfterHook: + Enabled: false RSpec/ExampleLength: Enabled: false -RSpec/MessageExpectation: +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: false +RSpec/FactoryBot/CreateList: + Enabled: false +RSpec/FactoryBot/FactoryClassName: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false RSpec/NestedGroups: Enabled: false +RSpec/PredicateMatcher: + Enabled: false +RSpec/ReceiveCounts: + Enabled: false +RSpec/ReceiveNever: + Enabled: false +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/RepeatedExampleGroupDescription: + Enabled: false +RSpec/RepeatedIncludeExample: + Enabled: false +RSpec/ReturnFromStub: + Enabled: false +RSpec/SharedExamples: + Enabled: false +RSpec/StubbedMock: + Enabled: false +RSpec/UnspecifiedException: + Enabled: false +RSpec/VariableDefinition: + Enabled: false +RSpec/VoidExpect: + Enabled: false +RSpec/Yield: + Enabled: false +Security/Open: + Enabled: false +Style/AccessModifierDeclarations: + Enabled: false +Style/AccessorGrouping: + Enabled: false Style/AsciiComments: Enabled: false +Style/BisectedAttrAccessor: + Enabled: false +Style/CaseLikeIf: + Enabled: false +Style/ClassEqualityComparison: + Enabled: false +Style/ColonMethodDefinition: + Enabled: false +Style/CombinableLoops: + Enabled: false +Style/CommentedKeyword: + Enabled: false +Style/Dir: + Enabled: false +Style/DoubleCopDisableDirective: + Enabled: false +Style/EmptyBlockParameter: + Enabled: false +Style/EmptyLambdaParameter: + Enabled: false +Style/Encoding: + Enabled: false +Style/EvalWithLocation: + Enabled: false +Style/ExpandPathArguments: + Enabled: false +Style/ExplicitBlockArgument: + Enabled: false +Style/ExponentialNotation: + Enabled: false +Style/FloatDivision: + Enabled: false +Style/GlobalStdStream: + Enabled: false +Style/HashAsLastArrayItem: + Enabled: false +Style/HashLikeCase: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: false Style/IfUnlessModifier: Enabled: false +Style/KeywordParametersOrder: + Enabled: false +Style/MinMax: + Enabled: false +Style/MixinUsage: + Enabled: false +Style/MultilineWhenThen: + Enabled: false +Style/NegatedUnless: + Enabled: false +Style/NumericPredicate: + Enabled: false +Style/OptionalBooleanParameter: + Enabled: false +Style/OrAssignment: + Enabled: false +Style/RandomWithOffset: + Enabled: false +Style/RedundantAssignment: + Enabled: false +Style/RedundantCondition: + Enabled: false +Style/RedundantConditional: + Enabled: false +Style/RedundantFetchBlock: + Enabled: false +Style/RedundantFileExtensionInRequire: + Enabled: false +Style/RedundantRegexpCharacterClass: + Enabled: false +Style/RedundantRegexpEscape: + Enabled: false +Style/RedundantSelfAssignment: + Enabled: false +Style/RedundantSort: + Enabled: false +Style/RescueStandardError: + Enabled: false +Style/SingleArgumentDig: + Enabled: false +Style/SlicingWithRange: + Enabled: false +Style/SoleNestedConditional: + Enabled: false +Style/StderrPuts: + Enabled: false +Style/StringConcatenation: + Enabled: false +Style/Strip: + Enabled: false Style/SymbolProc: Enabled: false +Style/TrailingBodyOnClass: + Enabled: false +Style/TrailingBodyOnMethodDefinition: + Enabled: false +Style/TrailingBodyOnModule: + Enabled: false +Style/TrailingCommaInHashLiteral: + Enabled: false +Style/TrailingMethodEndStatement: + Enabled: false +Style/UnpackFirst: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NilLambda: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/.sync.yml b/.sync.yml index 2a7aac6f..612e3b3c 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,15 +1,8 @@ --- ".gitlab-ci.yml": delete: true -".rubocop.yml": - include_todos: true - profiles: - strict: - configs: - Metrics/LineLength: - Max: 300 ".travis.yml": - global_env: + global_env: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" deploy_to_forge: enabled: false @@ -35,9 +28,6 @@ Gemfile: ":development": - gem: ruby-pwsh - gem: github_changelog_generator - git: https://github.com/skywinder/github-changelog-generator - ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') spec/spec_helper.rb: mock_with: ":rspec" coverage_report: true diff --git a/Gemfile b/Gemfile index 1202a551..122328df 100644 --- a/Gemfile +++ b/Gemfile @@ -17,20 +17,19 @@ ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false - gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') + gem "github_changelog_generator", require: false +end +group :system_tests do + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/appveyor.yml b/appveyor.yml index 61aefda1..7659feea 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,7 +19,7 @@ environment: SIMPLECOV: yes matrix: - - RUBY_VERSION: 24-x64 + RUBY_VERSION: 25-x64 CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - PUPPET_GEM_VERSION: ~> 5.0 diff --git a/metadata.json b/metadata.json index 72a5da85..85ea1c40 100644 --- a/metadata.json +++ b/metadata.json @@ -48,6 +48,6 @@ "database" ], "pdk-version": "1.18.1", - "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "heads/main-0-g874030e" + "template-url": "/home/david/git/pdk-templates/#master", + "template-ref": "heads/main-0-g28e5206" } From a72d36b54d7276868ebfb6046d175d31cb6b0b26 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 17 Dec 2020 20:04:30 +0000 Subject: [PATCH 2/5] Add the FrozenStrings magic comment --- lib/facter/sqlserver_features.rb | 2 ++ lib/facter/sqlserver_instances.rb | 2 ++ .../parser/functions/sqlserver_is_domain_or_local_user.rb | 2 ++ lib/puppet/parser/functions/sqlserver_upcase.rb | 2 ++ .../parser/functions/sqlserver_validate_hash_uniq_values.rb | 2 ++ .../parser/functions/sqlserver_validate_instance_name.rb | 2 ++ lib/puppet/parser/functions/sqlserver_validate_range.rb | 2 ++ lib/puppet/parser/functions/sqlserver_validate_size.rb | 2 ++ lib/puppet/property/sqlserver_login.rb | 2 ++ lib/puppet/property/sqlserver_tsql.rb | 2 ++ lib/puppet/provider/sqlserver.rb | 2 ++ lib/puppet/provider/sqlserver_features/mssql.rb | 2 ++ lib/puppet/provider/sqlserver_instance/mssql.rb | 2 ++ lib/puppet/provider/sqlserver_tsql/mssql.rb | 4 +++- lib/puppet/type/sqlserver_features.rb | 2 ++ lib/puppet/type/sqlserver_instance.rb | 2 ++ lib/puppet/type/sqlserver_tsql.rb | 2 ++ lib/puppet_x/sqlserver/features.rb | 2 ++ lib/puppet_x/sqlserver/server_helper.rb | 6 ++++-- lib/puppet_x/sqlserver/sql_connection.rb | 4 +++- spec/acceptance/sqlserver_config_spec.rb | 2 ++ spec/acceptance/sqlserver_database_spec.rb | 2 ++ spec/acceptance/sqlserver_instance_spec.rb | 2 ++ spec/acceptance/sqlserver_login_spec.rb | 2 ++ spec/acceptance/sqlserver_role_spec.rb | 2 ++ spec/acceptance/sqlserver_tsql_spec.rb | 2 ++ spec/acceptance/sqlserver_user_spec.rb | 2 ++ spec/acceptance/z_last_sqlserver_features_spec.rb | 2 ++ spec/defines/config_spec.rb | 2 ++ spec/defines/database_spec.rb | 2 ++ spec/defines/login/permissions_spec.rb | 2 ++ spec/defines/login_spec.rb | 2 ++ spec/defines/manifest_shared_examples.rb | 2 ++ spec/defines/role/permissions_spec.rb | 2 ++ spec/defines/role_spec.rb | 2 ++ spec/defines/sp_configure_spec.rb | 2 ++ spec/defines/user/permissions_spec.rb | 2 ++ spec/defines/user_spec.rb | 2 ++ spec/functions/functions_shared_examples.rb | 2 ++ spec/functions/sqlserver_is_domain_user_spec.rb | 2 ++ spec/functions/sqlserver_upcase_spec.rb | 2 ++ spec/functions/sqlserver_validate_hash_uniq_values_spec.rb | 2 ++ spec/functions/sqlserver_validate_instance_name_spec.rb | 2 ++ spec/functions/sqlserver_validate_size_spec.rb | 2 ++ spec/spec_helper_acceptance_local.rb | 2 ++ spec/sql_testing_helpers.rb | 1 + spec/unit/puppet/property/tsql_spec.rb | 2 ++ spec/unit/puppet/provider/sqlserver_features_spec.rb | 2 ++ spec/unit/puppet/provider/sqlserver_instance_spec.rb | 2 ++ spec/unit/puppet/provider/sqlserver_tsql_spec.rb | 2 ++ spec/unit/puppet/sqlserver_install_context.rb | 2 ++ spec/unit/puppet/sqlserver_spec_helper.rb | 2 ++ spec/unit/puppet/type/sqlserver_features_spec.rb | 2 ++ spec/unit/puppet/type/sqlserver_instance_spec.rb | 2 ++ spec/unit/puppet_x/server_helper_spec.rb | 2 ++ spec/unit/puppet_x/sql_connection_spec.rb | 2 ++ 56 files changed, 115 insertions(+), 4 deletions(-) diff --git a/lib/facter/sqlserver_features.rb b/lib/facter/sqlserver_features.rb index fa07cae1..5e66a9dd 100644 --- a/lib/facter/sqlserver_features.rb +++ b/lib/facter/sqlserver_features.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'puppet_x/sqlserver/features')) Facter.add(:sqlserver_features) do diff --git a/lib/facter/sqlserver_instances.rb b/lib/facter/sqlserver_instances.rb index 09670597..37ccea86 100644 --- a/lib/facter/sqlserver_instances.rb +++ b/lib/facter/sqlserver_instances.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'puppet_x/sqlserver/features')) Facter.add(:sqlserver_instances) do diff --git a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb index a4748760..dd78a1ed 100644 --- a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb +++ b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib/puppet_x/sqlserver/server_helper')) module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/sqlserver_upcase.rb b/lib/puppet/parser/functions/sqlserver_upcase.rb index 7dde5faa..cc372bb3 100644 --- a/lib/puppet/parser/functions/sqlserver_upcase.rb +++ b/lib/puppet/parser/functions/sqlserver_upcase.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Puppet::Parser::Functions newfunction(:sqlserver_upcase, type: :rvalue, arity: 1, doc: '@return Upcase values') do |arguments| if arguments.size != 1 diff --git a/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb b/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb index eaa1d7fc..2d87e53d 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # === Defined Parser Function: sqlserver_validate_hash_uniq_values # # @param args* A hash, that contains string or string[] for values diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index 2db47985..c2ae5fc6 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # === Defined Parser Function: mssql_validate_instance_name # # Validates an instance name for SQL Server against the documenation of diff --git a/lib/puppet/parser/functions/sqlserver_validate_range.rb b/lib/puppet/parser/functions/sqlserver_validate_range.rb index f939562f..1d3f9832 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_range.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_range.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Puppet::Parser::Functions newfunction(:sqlserver_validate_range, doc: '@return Error if value is not between range') do |args| if (args.length < 3) || (args.length > 4) diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index c6181d79..41330f48 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Puppet::Parser::Functions newfunction(:sqlserver_validate_size, doc: '@return Error if not a valid size value') do |args| if args.length != 1 diff --git a/lib/puppet/property/sqlserver_login.rb b/lib/puppet/property/sqlserver_login.rb index 08df5068..75fbd8bf 100644 --- a/lib/puppet/property/sqlserver_login.rb +++ b/lib/puppet/property/sqlserver_login.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/property' class Puppet::Property::SqlserverLogin < Puppet::Property # rubocop:disable Style/Documentation diff --git a/lib/puppet/property/sqlserver_tsql.rb b/lib/puppet/property/sqlserver_tsql.rb index 8063af18..1bd7586a 100644 --- a/lib/puppet/property/sqlserver_tsql.rb +++ b/lib/puppet/property/sqlserver_tsql.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/property' class Puppet::Property::SqlserverTsql < Puppet::Property # rubocop:disable Style/Documentation diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index ff830096..0cd5cfd1 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib/puppet_x/sqlserver/server_helper')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib/puppet_x/sqlserver/features')) require File.expand_path(File.join(File.dirname(__FILE__), 'sqlserver')) diff --git a/lib/puppet/provider/sqlserver_features/mssql.rb b/lib/puppet/provider/sqlserver_features/mssql.rb index a350ea1a..c421abfb 100644 --- a/lib/puppet/provider/sqlserver_features/mssql.rb +++ b/lib/puppet/provider/sqlserver_features/mssql.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/server_helper')) diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 1fa971de..72cd5311 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/server_helper')) diff --git a/lib/puppet/provider/sqlserver_tsql/mssql.rb b/lib/puppet/provider/sqlserver_tsql/mssql.rb index 1b690e2d..abf1c9d2 100644 --- a/lib/puppet/provider/sqlserver_tsql/mssql.rb +++ b/lib/puppet/provider/sqlserver_tsql/mssql.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/sql_connection')) @@ -11,7 +13,7 @@ def run(query) sqlconn.open_and_run_command(query, config) end - def get_config # rubocop:disable Style/AccessorMethodName + def get_config # rubocop:disable Naming/AccessorMethodName instance = resource[:instance] config_resc = resource.catalog.resources.find do |resc| resc.title =~ %r{Sqlserver::Config} && diff --git a/lib/puppet/type/sqlserver_features.rb b/lib/puppet/type/sqlserver_features.rb index eb3a7a07..080c71d4 100644 --- a/lib/puppet/type/sqlserver_features.rb +++ b/lib/puppet/type/sqlserver_features.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'property/sqlserver_login')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/sqlserver/server_helper')) diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index 97410067..5850c2fd 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'property/sqlserver_login')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/sqlserver/server_helper')) diff --git a/lib/puppet/type/sqlserver_tsql.rb b/lib/puppet/type/sqlserver_tsql.rb index 70a1a7b6..67703209 100644 --- a/lib/puppet/type/sqlserver_tsql.rb +++ b/lib/puppet/type/sqlserver_tsql.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'property/sqlserver_tsql')) diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 508ecd99..347c0de5 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/windows' SQL_2012 ||= 'SQL_2012'.freeze diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index b4a45c4d..b9f0838e 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetX # rubocop:disable Style/ClassAndModuleChildren module Sqlserver # rubocop:disable Style/ClassAndModuleChildren class ServerHelper # rubocop:disable Style/Documentation @@ -10,11 +12,11 @@ def self.get_sub_features(super_feature) @super_feature_hash[super_feature.to_sym] end - def self.is_super_feature(feature) # rubocop:disable Style/PredicateName + def self.is_super_feature(feature) # rubocop:disable Naming/PredicateName @super_feature_hash.key?(feature.to_sym) end - def self.is_domain_or_local_user?(user, hostname) # rubocop:disable Style/PredicateName + def self.is_domain_or_local_user?(user, hostname) # rubocop:disable Naming/PredicateName if user =~ %r{(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$}i false else diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index 9e5059fe..cfdeafba 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetX # rubocop:disable Style/ClassAndModuleChildren module Sqlserver CONNECTION_CLOSED = 0 @@ -104,7 +106,7 @@ def extract_messages(connection) ((0..error_count).map { |i| connection.Errors(i).Description.to_s }).join("\n") end - def has_errors # rubocop:disable Style/PredicateName + def has_errors # rubocop:disable Naming/PredicateName @exitstatus != 0 end end diff --git a/spec/acceptance/sqlserver_config_spec.rb b/spec/acceptance/sqlserver_config_spec.rb index 586fcbf0..9e9b848a 100644 --- a/spec/acceptance/sqlserver_config_spec.rb +++ b/spec/acceptance/sqlserver_config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' require 'erb' diff --git a/spec/acceptance/sqlserver_database_spec.rb b/spec/acceptance/sqlserver_database_spec.rb index 394e818e..5e6242af 100644 --- a/spec/acceptance/sqlserver_database_spec.rb +++ b/spec/acceptance/sqlserver_database_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index 6ea98a0c..ed59d2d2 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' require 'erb' diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index b7fb3628..e03ca7cc 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' diff --git a/spec/acceptance/sqlserver_role_spec.rb b/spec/acceptance/sqlserver_role_spec.rb index d8d0cc44..7fc672d3 100644 --- a/spec/acceptance/sqlserver_role_spec.rb +++ b/spec/acceptance/sqlserver_role_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' require 'erb' diff --git a/spec/acceptance/sqlserver_tsql_spec.rb b/spec/acceptance/sqlserver_tsql_spec.rb index 9f0ebc5c..14967388 100644 --- a/spec/acceptance/sqlserver_tsql_spec.rb +++ b/spec/acceptance/sqlserver_tsql_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' require 'erb' diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index 8614bbdc..97d91cc4 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'securerandom' require 'erb' diff --git a/spec/acceptance/z_last_sqlserver_features_spec.rb b/spec/acceptance/z_last_sqlserver_features_spec.rb index c5f5a57c..a7fa8cd9 100644 --- a/spec/acceptance/z_last_sqlserver_features_spec.rb +++ b/spec/acceptance/z_last_sqlserver_features_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'erb' require 'json' diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb index d2b4b433..cde3065d 100644 --- a/spec/defines/config_spec.rb +++ b/spec/defines/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index 3ff3fe1f..d0192722 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/defines/login/permissions_spec.rb b/spec/defines/login/permissions_spec.rb index 40df6afb..419cfc73 100644 --- a/spec/defines/login/permissions_spec.rb +++ b/spec/defines/login/permissions_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'manifest_shared_examples.rb')) diff --git a/spec/defines/login_spec.rb b/spec/defines/login_spec.rb index b1d9c264..0559ee61 100644 --- a/spec/defines/login_spec.rb +++ b/spec/defines/login_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/defines/manifest_shared_examples.rb b/spec/defines/manifest_shared_examples.rb index 9c25ec5b..9e4f7b6a 100644 --- a/spec/defines/manifest_shared_examples.rb +++ b/spec/defines/manifest_shared_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_context 'manifests' do let(:title) { 'simple title' } let(:sqlserver_tsql_title) {} diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index 5612e2cf..5af26897 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.join(File.dirname(__FILE__), '..'), 'manifest_shared_examples.rb')) diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index 8fca392b..40a333f9 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/defines/sp_configure_spec.rb b/spec/defines/sp_configure_spec.rb index cd0082e4..0b15e941 100644 --- a/spec/defines/sp_configure_spec.rb +++ b/spec/defines/sp_configure_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index b39300cc..817b850c 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'manifest_shared_examples.rb')) diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 218e2c26..96a595fe 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), 'manifest_shared_examples.rb')) diff --git a/spec/functions/functions_shared_examples.rb b/spec/functions/functions_shared_examples.rb index e4f5d1b8..c907b9da 100644 --- a/spec/functions/functions_shared_examples.rb +++ b/spec/functions/functions_shared_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'rspec' diff --git a/spec/functions/sqlserver_is_domain_user_spec.rb b/spec/functions/sqlserver_is_domain_user_spec.rb index 8cd46209..1cf40d14 100644 --- a/spec/functions/sqlserver_is_domain_user_spec.rb +++ b/spec/functions/sqlserver_is_domain_user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib/puppet_x/sqlserver/server_helper')) diff --git a/spec/functions/sqlserver_upcase_spec.rb b/spec/functions/sqlserver_upcase_spec.rb index e4cfad20..884809b3 100644 --- a/spec/functions/sqlserver_upcase_spec.rb +++ b/spec/functions/sqlserver_upcase_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'the sqlserver_upcase function' do diff --git a/spec/functions/sqlserver_validate_hash_uniq_values_spec.rb b/spec/functions/sqlserver_validate_hash_uniq_values_spec.rb index 7f42b505..aa1acbdb 100644 --- a/spec/functions/sqlserver_validate_hash_uniq_values_spec.rb +++ b/spec/functions/sqlserver_validate_hash_uniq_values_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'the sqlserver_validate_hash_uniq_values' do diff --git a/spec/functions/sqlserver_validate_instance_name_spec.rb b/spec/functions/sqlserver_validate_instance_name_spec.rb index a6b81868..87697b0c 100644 --- a/spec/functions/sqlserver_validate_instance_name_spec.rb +++ b/spec/functions/sqlserver_validate_instance_name_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'sqlserver_validate_instance_name function' do diff --git a/spec/functions/sqlserver_validate_size_spec.rb b/spec/functions/sqlserver_validate_size_spec.rb index 749e946c..1eea650c 100644 --- a/spec/functions/sqlserver_validate_size_spec.rb +++ b/spec/functions/sqlserver_validate_size_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet/error' diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 33a225d7..16b3800c 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet_litmus' require 'singleton' diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index e5c4cc2c..179ecd4b 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true def mount_iso(host, opts = {}) folder = opts[:folder] diff --git a/spec/unit/puppet/property/tsql_spec.rb b/spec/unit/puppet/property/tsql_spec.rb index fbd80921..c7cbf49f 100644 --- a/spec/unit/puppet/property/tsql_spec.rb +++ b/spec/unit/puppet/property/tsql_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'tsql' do diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index 8fe97bd6..f0af0856 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'rspec' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver_spec_helper.rb')) diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index 9df53fec..1ffcb38c 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'mocha' diff --git a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb index f760fcbc..d82448fb 100644 --- a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'mocha' diff --git a/spec/unit/puppet/sqlserver_install_context.rb b/spec/unit/puppet/sqlserver_install_context.rb index 64a8a97c..dcfc3424 100644 --- a/spec/unit/puppet/sqlserver_install_context.rb +++ b/spec/unit/puppet/sqlserver_install_context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def basic_args { source: 'C:\myinstallexecs', diff --git a/spec/unit/puppet/sqlserver_spec_helper.rb b/spec/unit/puppet/sqlserver_spec_helper.rb index f54f06ff..37186fdd 100644 --- a/spec/unit/puppet/sqlserver_spec_helper.rb +++ b/spec/unit/puppet/sqlserver_spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def stub_source_which_call(source) allow(Puppet::Util).to receive(:which).with("#{source}/setup.exe").and_return("#{source}/setup.exe") end diff --git a/spec/unit/puppet/type/sqlserver_features_spec.rb b/spec/unit/puppet/type/sqlserver_features_spec.rb index 5dc5de99..0cebe82f 100644 --- a/spec/unit/puppet/type/sqlserver_features_spec.rb +++ b/spec/unit/puppet/type/sqlserver_features_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver_install_context.rb')) diff --git a/spec/unit/puppet/type/sqlserver_instance_spec.rb b/spec/unit/puppet/type/sqlserver_instance_spec.rb index 21c18f16..292b93bb 100644 --- a/spec/unit/puppet/type/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/type/sqlserver_instance_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver_install_context.rb')) diff --git a/spec/unit/puppet_x/server_helper_spec.rb b/spec/unit/puppet_x/server_helper_spec.rb index be99255b..4a427a8f 100644 --- a/spec/unit/puppet_x/server_helper_spec.rb +++ b/spec/unit/puppet_x/server_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec' require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib/puppet_x/sqlserver/server_helper')) diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index bfdb132a..1f13fd1b 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec' require 'spec_helper' require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib/puppet_x/sqlserver/sql_connection')) From 2a93cda1cf8ed39857983926b6116c25b112aa33 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 17 Dec 2020 20:05:36 +0000 Subject: [PATCH 3/5] Add all safe auto corrects --- .../sqlserver_validate_instance_name.rb | 4 +-- .../functions/sqlserver_validate_range.rb | 2 +- .../functions/sqlserver_validate_size.rb | 2 +- lib/puppet/property/sqlserver_login.rb | 4 +-- .../provider/sqlserver_instance/mssql.rb | 2 +- lib/puppet/provider/sqlserver_tsql/mssql.rb | 3 +-- lib/puppet/type/sqlserver_instance.rb | 8 +++--- lib/puppet/type/sqlserver_tsql.rb | 12 ++++----- lib/puppet_x/sqlserver/features.rb | 22 +++++++-------- lib/puppet_x/sqlserver/server_helper.rb | 2 +- lib/puppet_x/sqlserver/sql_connection.rb | 2 +- spec/acceptance/sqlserver_login_spec.rb | 8 +++--- spec/defines/database_spec.rb | 4 +-- spec/defines/role/permissions_spec.rb | 27 +++++++++---------- spec/defines/role_spec.rb | 16 +++++------ spec/spec_helper_acceptance_local.rb | 24 ++++++++--------- spec/sql_testing_helpers.rb | 4 +-- .../puppet/type/sqlserver_features_spec.rb | 2 +- .../puppet/type/sqlserver_instance_spec.rb | 2 +- 19 files changed, 74 insertions(+), 76 deletions(-) diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index c2ae5fc6..5dacf04d 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -27,10 +27,10 @@ module Puppet::Parser::Functions if value.length > 16 errors << "Instance name can not be larger than 16 characters, you provided #{value}" end - if value =~ %r{\\|\:|;|\,|\@|\'|\s|\&} + if %r{\\|\:|;|\,|\@|\'|\s|\&}.match?(value) errors << "Instance name can not contain whitespaces, backslashes(\\), commas(,), colons(:), semi-colons(;), at symbols (@), single quotes(') or ampersand(&) sybmols, you provided '#{value}'" end - if value =~ %r{^_|_$} + if %r{^_|_$}.match?(value) errors << "Instance name can not start or end with underscore (_), you provided #{value}" end raise Puppet::ParseError, errors.join("\n") unless errors.empty? diff --git a/lib/puppet/parser/functions/sqlserver_validate_range.rb b/lib/puppet/parser/functions/sqlserver_validate_range.rb index 1d3f9832..f9d79429 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_range.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_range.rb @@ -12,7 +12,7 @@ module Puppet::Parser::Functions values.each do |value| msg ||= "validate_range(): #{args[0].inspect} is not between #{args[1].inspect} and #{args[2].inspect}" if value.is_a? Numeric - elsif value =~ %r{^\d+(|\.\d+)$} + elsif %r{^\d+(|\.\d+)$}.match?(value) raise(Puppet::ParseError, msg) unless Float(value).between?(Float(lower), Float(upper)) else value.strip! diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index 41330f48..8dc8929b 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -13,7 +13,7 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") end end - if value =~ %r{\.} + if %r{\.}.match?(value) raise(Puppet::ParseError, "Number must be an integer, you provided #{value}") end end diff --git a/lib/puppet/property/sqlserver_login.rb b/lib/puppet/property/sqlserver_login.rb index 75fbd8bf..a3bb692e 100644 --- a/lib/puppet/property/sqlserver_login.rb +++ b/lib/puppet/property/sqlserver_login.rb @@ -9,10 +9,10 @@ class Puppet::Property::SqlserverLogin < Puppet::Property # rubocop:disable Styl # value.length > 1 # does not contain two back slashes, contains no forward slashes # Determine what characters are valid for SQLLogin vs Domain Logins - if value =~ %r{\\.*\\} + if %r{\\.*\\}.match?(value) raise 'More than one \ found, maximum of one for users is allowed' end - if value =~ %r{@} + if %r{@}.match?(value) raise ArgumentError, _('@ sybmol is not allowed in the username, please follow the pattern of domain\login if you are attempting to add domain user') end diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 72cd5311..538ced82 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -151,7 +151,7 @@ def build_cmd_args(features, action = 'install') RESOURCEKEY_TO_CMDARG.keys.sort.map do |key| next unless not_nil_and_not_empty? @resource[key] cmd_args << "/#{RESOURCEKEY_TO_CMDARG[key]}=\"#{@resource[key.to_sym]}\"" - if key.to_s =~ %r{(_pwd|_password)$}i + if %r{(_pwd|_password)$}i.match?(key.to_s) obfuscated_strings.push(@resource[key]) end end diff --git a/lib/puppet/provider/sqlserver_tsql/mssql.rb b/lib/puppet/provider/sqlserver_tsql/mssql.rb index abf1c9d2..be7968de 100644 --- a/lib/puppet/provider/sqlserver_tsql/mssql.rb +++ b/lib/puppet/provider/sqlserver_tsql/mssql.rb @@ -13,8 +13,7 @@ def run(query) sqlconn.open_and_run_command(query, config) end - def get_config # rubocop:disable Naming/AccessorMethodName - instance = resource[:instance] + def get_config(instance = resource[:instance]) config_resc = resource.catalog.resources.find do |resc| resc.title =~ %r{Sqlserver::Config} && resc.original_parameters[:instance_name] =~ %r{#{instance}}i diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index 5850c2fd..9c2510bc 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -157,10 +157,10 @@ def strong_password?(key) message_start = "Password for #{key} is not strong" failures = [] failures << 'must be at least 8 characters long' unless password.length >= 8 - failures << 'must contain lowercase letters' unless password =~ %r{[a-z]} - failures << 'must contain uppercase letters' unless password =~ %r{[A-Z]} - failures << 'must contain numbers' unless password =~ %r{\d} - failures << 'must contain a special character' unless password =~ %r{} + failures << 'must contain lowercase letters' unless %r{[a-z]}.match?(password) + failures << 'must contain uppercase letters' unless %r{[A-Z]}.match?(password) + failures << 'must contain numbers' unless %r{\d}.match?(password) + failures << 'must contain a special character' unless %r{}.match?(password) fail("#{message_start}:\n#{failures.join("\n")}") if failures.count > 0 # rubocop:disable Style/SignalException true end diff --git a/lib/puppet/type/sqlserver_tsql.rb b/lib/puppet/type/sqlserver_tsql.rb index 67703209..fe153cd7 100644 --- a/lib/puppet/type/sqlserver_tsql.rb +++ b/lib/puppet/type/sqlserver_tsql.rb @@ -35,7 +35,7 @@ def self.checks desc 'initial database to connect to during query execution' defaultto 'master' validate do |value| - raise("Invalid database name #{value}") unless value =~ %r{^[[:word:]|#|@]+} + raise("Invalid database name #{value}") unless %r{^[[:word:]|#|@]+}.match?(value) end end @@ -107,12 +107,12 @@ def retrieve # Actually execute the command. def sync event = :executed_command - begin - @output = provider.run(resource[:command]) - if @output.has_errors - raise("Unable to apply changes, failed with error message #{@output.error_message}") - end + + @output = provider.run(resource[:command]) + if @output.has_errors + raise("Unable to apply changes, failed with error message #{@output.error_message}") end + unless @output.exitstatus.to_s == '0' raise("#{resource[:command]} returned #{@output.exitstatus} instead of one of [#{should.join(',')}]") end diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 347c0de5..532957e3 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -2,11 +2,11 @@ require 'puppet/util/windows' -SQL_2012 ||= 'SQL_2012'.freeze -SQL_2014 ||= 'SQL_2014'.freeze -SQL_2016 ||= 'SQL_2016'.freeze -SQL_2017 ||= 'SQL_2017'.freeze -SQL_2019 ||= 'SQL_2019'.freeze +SQL_2012 ||= 'SQL_2012' +SQL_2014 ||= 'SQL_2014' +SQL_2016 ||= 'SQL_2016' +SQL_2017 ||= 'SQL_2017' +SQL_2019 ||= 'SQL_2019' ALL_SQL_VERSIONS ||= [SQL_2012, SQL_2014, SQL_2016, SQL_2017, SQL_2019].freeze @@ -41,8 +41,8 @@ class Features # rubocop:disable Style/Documentation }, }.freeze - SQL_REG_ROOT ||= 'Software\Microsoft\Microsoft SQL Server'.freeze - HKLM ||= 'HKEY_LOCAL_MACHINE'.freeze + SQL_REG_ROOT ||= 'Software\Microsoft\Microsoft SQL Server' + HKLM ||= 'HKEY_LOCAL_MACHINE' def self.get_parent_path(key_path) # should be the same as SQL_REG_ROOT @@ -57,9 +57,9 @@ def self.get_reg_key_val(win32_reg_key, val_name, reg_type) def self.key_exists?(path) open(HKLM, path, KEY_READ | KEY64) {} - return true + true rescue - return false + false end def self.get_sql_reg_val_features(key_name, reg_val_feat_hash) @@ -70,7 +70,7 @@ def self.get_sql_reg_val_features(key_name, reg_val_feat_hash) .select { |val_name, _| get_reg_key_val(key, val_name, Win32::Registry::REG_DWORD).to_i == 1 } .map { |_, feat_name| feat_name } end - rescue Puppet::Util::Windows::Error # subkey doesn't exist #rubocop:disable Lint/HandleExceptions + rescue Puppet::Util::Windows::Error end vals @@ -107,7 +107,7 @@ def self.get_sql_reg_key_features(key_name, reg_key_feat_hash, instance_name) open(HKLM, "#{key_name}\\#{subkey}", KEY_READ | KEY64) do |feat_key| get_reg_key_val(feat_key, instance_name, Win32::Registry::REG_SZ) end - rescue Puppet::Util::Windows::Error # subkey doesn't exist #rubocop:disable Lint/HandleExceptions + rescue Puppet::Util::Windows::Error end end diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index b9f0838e..e2733d39 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -17,7 +17,7 @@ def self.is_super_feature(feature) # rubocop:disable Naming/PredicateName end def self.is_domain_or_local_user?(user, hostname) # rubocop:disable Naming/PredicateName - if user =~ %r{(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$}i + if %r{(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$}i.match?(user) false else true diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index cfdeafba..98ba18ff 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -63,7 +63,7 @@ def get_connection_string(config) def close connection.Close unless connection_closed? - rescue win32_exception # rubocop:disable Lint/HandleExceptions + rescue win32_exception end def connection_closed? diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index e03ca7cc..e91fe32f 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -248,7 +248,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) describe "Modify a #{testcase} login" do before(:all) { remove_test_logins(host) } - it "should create an initial #{testcase}" do + it "creates an initial #{testcase}" do options = { 'svrroles' => '{\'sysadmin\' => 1}' } pp = create_login_manifest(testcase, @login_under_test, @login_passwd, options) apply_manifest(pp, catch_failures: true) @@ -259,7 +259,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) run_sql_query(run_sql_query_opts_as_sa(query, 1)) end - it "should modify a #{testcase} login" do + it "modifies a #{testcase} login" do options = { 'disabled' => true, 'default_database' => db_name.to_s, 'default_language' => 'Spanish', @@ -331,7 +331,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) describe "Delete #{testcase} login" do before(:all) { remove_test_logins(host) } - it "should create an initial #{testcase}" do + it "creates an initial #{testcase}" do pp = create_login_manifest(testcase, @login_under_test, @login_passwd) apply_manifest(pp, catch_failures: true) end @@ -341,7 +341,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) run_sql_query(run_sql_query_opts_as_sa(query, 1)) end - it "should remove a #{testcase} on ensure => absent idempotently" do + it "removes a #{testcase} on ensure => absent idempotently" do options = { 'ensure' => 'absent' } pp = create_login_manifest(testcase, @login_under_test, @login_passwd, options) idempotent_apply(pp) diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index d0192722..fde8594e 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -60,9 +60,9 @@ let(:should_contain_command) do [ %r{NAME = N'myCre-Cre'}, - /FILENAME = N'c\:\/test\/test\.mdf'/, + %r{FILENAME = N'c\:/test/test\.mdf'}, %r{NAME = N'myCrazy_Log'}, - /FILENAME = N'c\:\/test\/logfile\.ldf'/, + %r{FILENAME = N'c\:/test/logfile\.ldf'}, ] end end diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index 5af26897..67d4a3d1 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -16,7 +16,6 @@ end context 'sql variables' do - # rubocop:disable Layout/AlignArray : Will not conform SQL test data to Rubocop declare_variables = [ "DECLARE @perm_state varchar(250), @@ -25,9 +24,9 @@ @princ_name varchar(50), @princ_type varchar(50), @state_desc varchar(50);", - "SET @princ_type = 'SERVER_ROLE';", - "SET @princ_name = 'myCustomRole';", - "SET @state_desc = 'GRANT';", + "SET @princ_type = 'SERVER_ROLE';", + "SET @princ_name = 'myCustomRole';", + "SET @state_desc = 'GRANT';", ] let(:should_contain_command) { declare_variables } let(:should_contain_onlyif) { declare_variables } @@ -44,23 +43,23 @@ context 'type =>' do shared_examples 'GRANT Permissions' do |type| base_commands = [ - "SET @princ_type = '#{type.upcase}_ROLE';", - "ISNULL( + "SET @princ_type = '#{type.upcase}_ROLE';", + "ISNULL( (SELECT state_desc FROM sys.#{type.downcase}_permissions prem JOIN sys.#{type.downcase}_principals r ON r.principal_id = prem.grantee_principal_id WHERE r.name = @princ_name AND r.type_desc = @princ_type AND prem.permission_name = @permission), 'REVOKE')", - "SET @permission = 'INSERT';", - "SET @permission = 'UPDATE';", - "SET @permission = 'DELETE';", - "SET @permission = 'SELECT';", + "SET @permission = 'INSERT';", + "SET @permission = 'UPDATE';", + "SET @permission = 'DELETE';", + "SET @permission = 'SELECT';", ] should_commands = [ - 'GRANT INSERT TO [myCustomRole];', - 'GRANT UPDATE TO [myCustomRole];', - 'GRANT DELETE TO [myCustomRole];', - 'GRANT SELECT TO [myCustomRole];', + 'GRANT INSERT TO [myCustomRole];', + 'GRANT UPDATE TO [myCustomRole];', + 'GRANT DELETE TO [myCustomRole];', + 'GRANT SELECT TO [myCustomRole];', ] # rubocop:enable Layout/IndentArray let(:should_contain_command) { base_commands + should_commands } diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index 40a333f9..e19f4343 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -190,7 +190,7 @@ end let(:should_contain_command) do [ - "WHILE(@row <= @row_count) + "WHILE(@row <= @row_count) BEGIN SET @sql = 'ALTER SERVER ROLE [myCustomRole] DROP MEMBER [' + (SELECT member FROM @purge_members WHERE ID = @row) + '];' EXEC(@sql) @@ -200,7 +200,7 @@ end let(:should_contain_onlyif) do [ -"SELECT m.name FROM sys.server_role_members rm + "SELECT m.name FROM sys.server_role_members rm JOIN sys.server_principals r ON rm.role_principal_id = r.principal_id JOIN sys.server_principals m ON rm.member_principal_id = m.principal_id WHERE r.name = 'myCustomRole'", @@ -220,7 +220,7 @@ end let(:should_contain_command) do [ - "WHILE(@row <= @row_count) + "WHILE(@row <= @row_count) BEGIN SET @sql = 'ALTER ROLE [myCustomRole] DROP MEMBER [' + (SELECT member FROM @purge_members WHERE ID = @row) + '];' EXEC(@sql) @@ -230,7 +230,7 @@ end let(:should_contain_onlyif) do [ -"SELECT m.name FROM sys.database_role_members rm + "SELECT m.name FROM sys.database_role_members rm JOIN sys.database_principals r ON rm.role_principal_id = r.principal_id JOIN sys.database_principals m ON rm.member_principal_id = m.principal_id WHERE r.name = 'myCustomRole'", @@ -250,14 +250,14 @@ end let(:should_contain_command) do [ - %r{WHERE r\.name = 'myCustomRole'\n\s+AND m\.name NOT IN \(}, - "NOT IN ('test','these','users')", + %r{WHERE r\.name = 'myCustomRole'\n\s+AND m\.name NOT IN \(}, + "NOT IN ('test','these','users')", ] end let(:should_contain_onlyif) do [ - %r{WHERE r\.name = 'myCustomRole'\n\s+AND m\.name NOT IN \(}, - "NOT IN ('test','these','users')", + %r{WHERE r\.name = 'myCustomRole'\n\s+AND m\.name NOT IN \(}, + "NOT IN ('test','these','users')", ] end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 16b3800c..ab0aa62d 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -8,16 +8,16 @@ class Helper include PuppetLitmus end -WIN_ISO_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/windows'.freeze -WIN_2012R2_ISO = 'en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso'.freeze -QA_RESOURCE_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/SQLServer'.freeze -SQL_2019_ISO = 'SQLServer2019CTP2.4-x64-ENU.iso'.freeze -SQL_2017_ISO = 'SQLServer2017-x64-ENU.iso'.freeze -SQL_2016_ISO = 'en_sql_server_2016_enterprise_with_service_pack_1_x64_dvd_9542382.iso'.freeze -SQL_2014_ISO = 'SQLServer2014SP3-FullSlipstream-x64-ENU.iso'.freeze -SQL_2012_ISO = 'SQLServer2012SP1-FullSlipstream-ENU-x64.iso'.freeze -SQL_ADMIN_USER = 'sa'.freeze -SQL_ADMIN_PASS = 'Pupp3t1@'.freeze +WIN_ISO_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/windows' +WIN_2012R2_ISO = 'en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso' +QA_RESOURCE_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/SQLServer' +SQL_2019_ISO = 'SQLServer2019CTP2.4-x64-ENU.iso' +SQL_2017_ISO = 'SQLServer2017-x64-ENU.iso' +SQL_2016_ISO = 'en_sql_server_2016_enterprise_with_service_pack_1_x64_dvd_9542382.iso' +SQL_2014_ISO = 'SQLServer2014SP3-FullSlipstream-x64-ENU.iso' +SQL_2012_ISO = 'SQLServer2012SP1-FullSlipstream-ENU-x64.iso' +SQL_ADMIN_USER = 'sa' +SQL_ADMIN_PASS = 'Pupp3t1@' RSpec.configure do |c| c.before(:suite) do @@ -178,7 +178,7 @@ def run_sql_query(opts = {}, &block) error_message = "Expected #{opts[:expected_row_count]} rows but observed #{rows_observed}" raise error_message unless opts[:expected_row_count] == rows_observed.to_i end - return unless block_given? + return unless block case block.arity when 0 yield self @@ -197,7 +197,7 @@ def validate_sql_install(opts = {}, &block) cmd = "type \"#{bootstrap_dir}\\Log\\Summary.txt\"" result = Helper.instance. run_shell("cmd.exe /c '#{cmd}'") - return unless block_given? + return unless block case block.arity when 0 yield self diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 179ecd4b..0a0b0db3 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -77,7 +77,7 @@ def run_sql_query(host, opts = {}, &block) error_message = "Expected #{opts[:expected_row_count]} rows but observed #{rows_observed}" raise error_message unless opts[:expected_row_count] == rows_observed.to_i end - return unless block_given? + return unless block case block.arity when 0 yield self @@ -136,7 +136,7 @@ def validate_sql_install(host, opts = {}, &block) cmd = "type \\\"#{bootstrap_dir}\\Log\\Summary.txt\\\"" result = on(host, "cmd.exe /c \"#{cmd}\"") - return unless block_given? + return unless block case block.arity when 0 yield self diff --git a/spec/unit/puppet/type/sqlserver_features_spec.rb b/spec/unit/puppet/type/sqlserver_features_spec.rb index 0cebe82f..a09e18ad 100644 --- a/spec/unit/puppet/type/sqlserver_features_spec.rb +++ b/spec/unit/puppet/type/sqlserver_features_spec.rb @@ -8,7 +8,7 @@ describe 'features' do ['Tools'].each do |feature_name| - it "should raise deprecation warning with super feature #{feature_name}" do + it "raises deprecation warning with super feature #{feature_name}" do args = { name: 'Generic Features', ensure: 'present', diff --git a/spec/unit/puppet/type/sqlserver_instance_spec.rb b/spec/unit/puppet/type/sqlserver_instance_spec.rb index 292b93bb..9a9a4b92 100644 --- a/spec/unit/puppet/type/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/type/sqlserver_instance_spec.rb @@ -35,7 +35,7 @@ describe 'features' do ['SQL'].each do |feature_name| - it "should raise deprecation warning with super feature #{feature_name}" do + it "raises deprecation warning with super feature #{feature_name}" do args = { name: 'MSSQLSERVER', ensure: 'present', From 8defc437f08e78725ab1c0d1f04b67fe2de2b240 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 17 Dec 2020 20:24:12 +0000 Subject: [PATCH 4/5] Apply remaining rubocop fixes --- .rubocop.yml | 3 + .rubocop_todo.yml | 57 +++++++------------ .sync.yml | 2 + .../sqlserver_validate_instance_name.rb | 2 +- lib/puppet/provider/sqlserver.rb | 8 ++- .../provider/sqlserver_features/mssql.rb | 2 +- .../provider/sqlserver_instance/mssql.rb | 4 +- spec/defines/user_spec.rb | 2 +- 8 files changed, 37 insertions(+), 43 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3aaa6965..6a240fe7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,6 +18,7 @@ AllCops: - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" +inherit_from: ".rubocop_todo.yml" Layout/LineLength: Description: People have wide screens, use them. Max: 200 @@ -268,6 +269,8 @@ Naming/MethodParameterName: Enabled: false Naming/RescuedExceptionsVariableName: Enabled: false +Naming/VariableNumber: + Enabled: false Performance/BindCall: Enabled: false Performance/DeletePrefix: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b3e4e063..5b57cce5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,43 +1,34 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-12-02 11:06:27 +0000 using RuboCop version 0.49.1. +# on 2020-12-17 20:22:52 UTC using RuboCop version 1.6.1. # 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 # versions of RuboCop, may require this file to be generated again. -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/IndentArray: - Exclude: - - 'spec/defines/role/permissions_spec.rb' - - 'spec/defines/role_spec.rb' - # Offense count: 3 -Lint/IneffectiveAccessModifier: +# Configuration parameters: AllowComments. +Lint/SuppressedException: Exclude: - - 'lib/puppet/provider/sqlserver.rb' + - 'lib/puppet_x/sqlserver/features.rb' + - 'lib/puppet_x/sqlserver/sql_connection.rb' # Offense count: 1 -Lint/UselessAssignment: - Exclude: - - 'spec/spec_helper_acceptance.rb' - -# Offense count: 2 -RSpec/ExpectInHook: +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/StringInclude: Exclude: - - 'spec/acceptance/sqlserver_role_spec.rb' + - 'lib/puppet/provider/sqlserver_tsql/mssql.rb' # Offense count: 2 -# Configuration parameters: CustomTransform, IgnoreMethods. +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* RSpec/FilePath: Exclude: - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 296 +# Offense count: 301 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: @@ -55,32 +46,28 @@ RSpec/InstanceVariable: - 'spec/unit/puppet/type/sqlserver_instance_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 1 -RSpec/LetBeforeExamples: - Exclude: - - 'spec/unit/puppet/type/sqlserver_instance_spec.rb' - -# Offense count: 19 +# Offense count: 17 +# Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: Exclude: - - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 2 -RSpec/RepeatedExample: +# Offense count: 6 +RSpec/SubjectStub: Exclude: - - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/unit/puppet_x/server_helper_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' # Offense count: 2 -# Configuration parameters: IgnoreSymbolicNames. +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: - - 'spec/defines/database_spec.rb' + - 'spec/defines/user_spec.rb' diff --git a/.sync.yml b/.sync.yml index 612e3b3c..5ddc3083 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,6 +1,8 @@ --- ".gitlab-ci.yml": delete: true +".rubocop.yml": + include_todos: true ".travis.yml": global_env: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index 5dacf04d..ebb1341b 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -21,7 +21,7 @@ module Puppet::Parser::Functions end value = args[0] errors = [] - if value.empty? || value.empty? + if value.empty? errors << 'Instance name must be between 1 to 16 characters' end if value.length > 16 diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 0cd5cfd1..199e75c8 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -25,7 +25,7 @@ def try_execute(command, msg = nil, obfuscate_strings = nil, acceptable_exit_cod msg = "Failure occured when trying to install SQL Server #{@resource[:name]}" if msg.nil? msg += " \n Execution of '#{command}' returned #{res.exitstatus}: #{res.strip}" - obfuscate_strings.each { |str| msg.gsub!(str, '**HIDDEN VALUE**') } unless obfuscate_strings.nil? + obfuscate_strings&.each { |str| msg.gsub!(str, '**HIDDEN VALUE**') } raise Puppet::Error, msg end @@ -33,20 +33,22 @@ def try_execute(command, msg = nil, obfuscate_strings = nil, acceptable_exit_cod res end - private - + # @api private def self.native_path(path) path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) end + # @api private def self.template_path File.expand_path(File.join(File.dirname(__FILE__), '../templates')) end + # @api private def not_nil_and_not_empty?(obj) !obj.nil? && !obj.empty? end + # @api private def self.run_install_dot_net(source_location = nil) unless source_location.nil? warn("The specified windows_source_location directory for sqlserver of \"#{source_location}\" does not exist") unless Puppet::FileSystem.directory?(source_location) diff --git a/lib/puppet/provider/sqlserver_features/mssql.rb b/lib/puppet/provider/sqlserver_features/mssql.rb index c421abfb..7abd4155 100644 --- a/lib/puppet/provider/sqlserver_features/mssql.rb +++ b/lib/puppet/provider/sqlserver_features/mssql.rb @@ -41,7 +41,7 @@ def self.instances def self.prefetch(resources) features = instances - resources.keys.each do |name| + resources.each_key do |name| if (provider = features.find { |feature| feature.name == name }) resources[name].provider = provider end diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 538ced82..06324771 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -33,7 +33,7 @@ def self.instances result = Facter.value(:sqlserver_instances) debug "Parsing result #{result}" result = result.values.inject(:merge) - result.keys.each do |instance_name| + result.each_key do |instance_name| existing_instance = { name: instance_name, ensure: :present, features: result[instance_name]['features'].sort } @@ -45,7 +45,7 @@ def self.instances def self.prefetch(resources) my_instances = instances - resources.keys.each do |name| + resources.each_key do |name| if (provider = my_instances.find { |inst| inst.name == name }) resources[name].provider = provider end diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 96a595fe..858016fe 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -116,7 +116,7 @@ let(:should_contain_command) do [ 'USE [myDatabase]', - /CREATE USER \[myMachineName\/myUser\]\n\s+FROM LOGIN \[myMachineName\/myUser\]/, # rubocop:disable Style/RegexpLiteral : Will not conform SQL test data to Rubocop + /CREATE USER \[myMachineName\/myUser\]\n\s+FROM LOGIN \[myMachineName\/myUser\]/, ] end From 27d5fc1011fb7f52d88642f2f384f71bf3f6fb9a Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 4 Jan 2021 15:22:00 +0000 Subject: [PATCH 5/5] Fix frozen string errors --- spec/defines/login/permissions_spec.rb | 3 ++- spec/defines/user/permissions_spec.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/defines/login/permissions_spec.rb b/spec/defines/login/permissions_spec.rb index 419cfc73..8d3be4f3 100644 --- a/spec/defines/login/permissions_spec.rb +++ b/spec/defines/login/permissions_spec.rb @@ -104,7 +104,8 @@ it_behaves_like 'sqlserver_tsql command' end - state.capitalize! + + state = state.capitalize describe "capitalized #{state}" do let(:additional_params) { { state: state } } diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index 817b850c..0c1f5def 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -128,7 +128,8 @@ it_behaves_like 'sqlserver_tsql command' end - state.capitalize! + + state = state.capitalize describe "capitalized #{state}" do let(:additional_params) { { state: state } }