From f61b177203548ca5d05dcbbc2097be23b613e016 Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Mon, 6 Sep 2021 14:44:04 +0200 Subject: [PATCH 1/6] Added pipelines for tests on PRs and releases on tags Signed-off-by: Evgeny Soynov --- .github/workflows/ci.yaml | 112 +++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 29 +++++++++ Gemfile | 40 ++++++------ 3 files changed, 162 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0197000 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,112 @@ +name: CI + +on: pull_request + +jobs: + setup_matrix: + name: "Setup Test Matrix" + runs-on: ubuntu-20.04 + outputs: + matrix: ${{ steps.get-outputs.outputs.matrix }} + spec_matrix: ${{ steps.get-outputs.outputs.spec_matrix }} + env: + BUNDLE_WITHOUT: development:test:release + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: "2.7" + bundler-cache: true + - name: Run rake validate + run: bundle exec rake validate + + - name: Setup Test Matrix + id: get-outputs + run: bundle exec matrix_from_metadata_v2 + + unit: + needs: setup_matrix + runs-on: ubuntu-20.04 + if: ${{ needs.setup_matrix.outputs.spec_matrix != '{}' }} + + strategy: + fail-fast: false + matrix: ${{fromJson(needs.setup_matrix.outputs.spec_matrix)}} + + env: + PUPPET_GEM_VERSION: ${{ matrix.puppet_version }} + FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' + + name: "Spec: puppet ${{ matrix.puppet_version }} (ruby ${{ matrix.ruby_version }})" + steps: + - uses: actions/checkout@v2 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + + - name: Print bundle environment + run: | + bundle env + + - name: Run Static & Syntax Tests + run: | + bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + + - name: Run parallel_spec tests + run: | + bundle exec rake parallel_spec + + acceptance: + needs: setup_matrix + runs-on: ubuntu-20.04 + if: ${{ needs.setup_matrix.outputs.matrix != '{}' }} + + strategy: + fail-fast: false + matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} + + name: "Acceptance: ${{matrix.platforms.label}}, ${{matrix.collection}}" + steps: + - uses: actions/checkout@v2 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + + - name: Print bundle environment + run: | + bundle env + + - name: Provision test environment + run: | + bundle exec rake 'litmus:provision[docker,${{ matrix.platforms.image }}]' + + - name: Install agent + run: | + bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' + + - name: Install module + run: | + bundle exec rake 'litmus:install_module' + + # - name: Display sysctl settings + # run: | + # bundle exec bolt command run 'sysctl -a' --targets localhost:2222 -i spec/fixtures/litmus_inventory.yaml + + - name: Run acceptance tests + run: | + bundle exec rake 'litmus:acceptance:parallel' + + - name: Remove test environment + if: ${{ always() }} + continue-on-error: true + run: | + if [[ -f inventory.yaml || -f spec/fixtures/litmus_inventory.yaml ]]; then + bundle exec rake 'litmus:tear_down' + fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ff7667f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + tags: + - "*" + +env: + BUNDLE_WITHOUT: development:test:system_tests + +jobs: + deploy: + name: "deploy to forge" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: "2.7" + bundler-cache: true + - name: Build and Deploy + env: + # Configure secrets here: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets + BLACKSMITH_FORGE_USERNAME: "${{ secrets.PUPPET_FORGE_USERNAME }}" + BLACKSMITH_FORGE_API_KEY: "${{ secrets.PUPPET_FORGE_API_KEY }}" + run: bundle exec rake module:push diff --git a/Gemfile b/Gemfile index 8007ad0..8e01e4e 100644 --- a/Gemfile +++ b/Gemfile @@ -17,19 +17,31 @@ 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 "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 "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 "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 "puppet-resource_api", require: false + gem 'puppet_litmus', git: 'https://github.com/puppetlabs/puppet_litmus.git', ref: 'main' +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 + +group :release do + gem 'github_changelog_generator', '>= 1.16.1', :require => false + gem 'puppet-blacksmith', :require => false + gem 'voxpupuli-release', :require => false + gem 'puppet-strings', '>= 2.2', :require => false end +gem 'puppetlabs_spec_helper', '~> 2.0', :require => false +gem 'rake', :require => false + puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] @@ -44,16 +56,6 @@ gems['puppet'] = location_for(puppet_version) gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - gems.each do |gem_name, gem_params| gem gem_name, *gem_params end From 487fdca5d15c7f1ba74affd12026f375fd3bdd35 Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Tue, 7 Sep 2021 11:20:38 +0200 Subject: [PATCH 2/6] Fixed minio_client_alias failing with legacy settings Signed-off-by: Evgeny Soynov --- .rubocop.yml | 424 +++++++++++++++++- .../minio_client_alias/minio_client_alias.rb | 13 +- lib/puppet/type/minio_client_alias.rb | 6 +- 3 files changed, 418 insertions(+), 25 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5307849..8f782e7 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,16 +18,9 @@ AllCops: - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -Metrics/LineLength: +Layout/LineLength: Description: People have wide screens, use them. Max: 200 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. @@ -36,14 +29,13 @@ RSpec/BeforeAfterAll: RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb 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: true Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact @@ -72,7 +64,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 @@ -87,26 +79,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: @@ -119,19 +255,265 @@ 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 +Naming/VariableNumber: + 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/FrozenStringLiteralComment: + 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/lib/puppet/provider/minio_client_alias/minio_client_alias.rb b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb index c0c1cce..7455cc6 100644 --- a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb +++ b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb @@ -4,6 +4,12 @@ require 'puppet/resource_api/simple_provider' require 'puppet_x/minio/client' +legacy_path_support_map = { + '': 'auto', + dns: 'off', + path: 'on', +} + # Implementation for the minio_client_alias type using the Resource API. class Puppet::Provider::MinioClientAlias::MinioClientAlias < Puppet::ResourceApi::SimpleProvider def get(context) @@ -58,6 +64,11 @@ def to_client_params(name, should) end def to_puppet_alias(json) + path_lookup_support = json['path'] + if legacy_path_support_map.key?(json['path']) + path_lookup_support = legacy_path_support_map[json['path']] + end + { name: json['alias'], ensure: 'present', @@ -65,7 +76,7 @@ def to_puppet_alias(json) access_key: json['accessKey'], secret_key: Puppet::Pops::Types::PSensitiveType::Sensitive.new(json['secretKey']), api_signature: json['api'], - path_lookup_support: json['path'], + path_lookup_support: path_lookup_support, } end diff --git a/lib/puppet/type/minio_client_alias.rb b/lib/puppet/type/minio_client_alias.rb index dca6da0..916a4b0 100644 --- a/lib/puppet/type/minio_client_alias.rb +++ b/lib/puppet/type/minio_client_alias.rb @@ -44,15 +44,15 @@ desc: 'The API endpoint url', }, access_key: { - type: 'String[1]', + type: 'Optional[String]', desc: 'The API access key', }, secret_key: { - type: 'Variant[Sensitive[String[1]], String[1]]', + type: 'Optional[Variant[Sensitive[String], String]]', desc: 'The API access secret', }, api_signature: { - type: 'Optional[String[1]]', + type: "Optional[Enum['S3v4', 'S3v2']]", desc: 'The API signature', }, path_lookup_support: { From baee283bef6055890ff1ab16e55f195c3f48c1ca Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Tue, 7 Sep 2021 12:02:32 +0200 Subject: [PATCH 3/6] Fixed rubocop warnings, added test for legacy paths Signed-off-by: Evgeny Soynov --- .../minio_client_alias/minio_client_alias.rb | 11 ++++++----- lib/puppet_x/minio/client.rb | 8 ++++---- .../minio_client_alias_spec.rb | 17 ++++++++++++++++- spec/unit/puppet_x/minio/client_spec.rb | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb index 7455cc6..2f4a33c 100644 --- a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb +++ b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb @@ -4,11 +4,11 @@ require 'puppet/resource_api/simple_provider' require 'puppet_x/minio/client' -legacy_path_support_map = { +LEGACY_PATH_SUPPORT_MAP = { '': 'auto', dns: 'off', path: 'on', -} +}.freeze # Implementation for the minio_client_alias type using the Resource API. class Puppet::Provider::MinioClientAlias::MinioClientAlias < Puppet::ResourceApi::SimpleProvider @@ -46,7 +46,7 @@ def insync?(context, _name, property_name, is_hash, should_hash) when :secret_key is = unwrap_maybe_sensitive(is_hash[property_name]) should = unwrap_maybe_sensitive(should_hash[property_name]) - return is == should + is == should end end @@ -65,8 +65,9 @@ def to_client_params(name, should) def to_puppet_alias(json) path_lookup_support = json['path'] - if legacy_path_support_map.key?(json['path']) - path_lookup_support = legacy_path_support_map[json['path']] + + if LEGACY_PATH_SUPPORT_MAP.key?(json['path'].to_sym) + path_lookup_support = LEGACY_PATH_SUPPORT_MAP[json['path'].to_sym] end { diff --git a/lib/puppet_x/minio/client.rb b/lib/puppet_x/minio/client.rb index d95cb69..2ea163d 100644 --- a/lib/puppet_x/minio/client.rb +++ b/lib/puppet_x/minio/client.rb @@ -5,9 +5,9 @@ module PuppetX # rubocop:disable Style/ClassAndModuleChildren module Minio # rubocop:disable Style/ClassAndModuleChildren class Client # rubocop:disable Style/Documentation - CLIENT_LOCATION = '/root/.minioclient'.freeze + CLIENT_LOCATION = '/root/.minioclient' - class_variable_set(:@@client_ensured, false) + @client_ensured = false def self.execute(args, **execute_args) ensure_client_installed @@ -20,7 +20,7 @@ def self.execute(args, **execute_args) end def self.ensure_client_installed - return if class_variable_get(:@@client_ensured) + return if @client_ensured unless installed? errormsg = [ @@ -30,7 +30,7 @@ def self.ensure_client_installed raise Puppet::ExecutionFailure, errormsg.join end - class_variable_set(:@@client_ensured, true) + @client_ensured = true end def self.installed? diff --git a/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb b/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb index ed8b67d..14d040b 100644 --- a/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb +++ b/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb @@ -57,6 +57,21 @@ end end + it 'processes legacy paths' do + Puppet::Util::ExecutionStub.set do |_command, _options| + <<-JSONSTRINGS + {"status":"success","alias":"test1","URL":"http://example.com","accessKey":"admin","secretKey":"password","api":"S3v4","path":""} + {"status":"success","alias":"test2","URL":"http://example.com","accessKey":"access","secretKey":"secret","api":"S3v2","path":"dns"} + {"status":"success","alias":"test3","URL":"http://example.com","accessKey":"access","secretKey":"secret","api":"S3v2","path":"path"} + JSONSTRINGS + end + + alisases = provider.get(context) + expect(alisases).to include(a_hash_including(name: 'test1', path_lookup_support: 'auto')) + expect(alisases).to include(a_hash_including(name: 'test2', path_lookup_support: 'off')) + expect(alisases).to include(a_hash_including(name: 'test3', path_lookup_support: 'on')) + end + describe 'create(context, name, should)' do it 'creates the resource' do Puppet::Util::ExecutionStub.set do |command, _options| @@ -142,7 +157,7 @@ end end - describe 'insync?(context, name, property_name, is_hash, should_hash)' do + describe 'insync?(context, name, property_name, is_hash, should_hash)' do # rubocop:disable RSpec/EmptyExampleGroup def self.test_insync_of_secret_key(desc, is, should, expected) it desc do is_hash = { secret_key: is } diff --git a/spec/unit/puppet_x/minio/client_spec.rb b/spec/unit/puppet_x/minio/client_spec.rb index 12e1f19..aac2094 100644 --- a/spec/unit/puppet_x/minio/client_spec.rb +++ b/spec/unit/puppet_x/minio/client_spec.rb @@ -6,7 +6,7 @@ RSpec.describe PuppetX::Minio::Client do before :each do - described_class.class_variable_set(:@@client_ensured, false) + described_class.instance_variable_set(:@client_ensured, false) end describe 'execute' do From 82bafa46ffe8594074d4e349f745a8b2743e94a5 Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Tue, 7 Sep 2021 12:12:44 +0200 Subject: [PATCH 4/6] Fixed issue with null value when no secret key set Signed-off-by: Evgeny Soynov --- .../minio_client_alias/minio_client_alias.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb index 2f4a33c..b907824 100644 --- a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb +++ b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb @@ -4,14 +4,14 @@ require 'puppet/resource_api/simple_provider' require 'puppet_x/minio/client' -LEGACY_PATH_SUPPORT_MAP = { - '': 'auto', - dns: 'off', - path: 'on', -}.freeze - # Implementation for the minio_client_alias type using the Resource API. class Puppet::Provider::MinioClientAlias::MinioClientAlias < Puppet::ResourceApi::SimpleProvider + LEGACY_PATH_SUPPORT_MAP = { + '': 'auto', + dns: 'off', + path: 'on', + }.freeze + def get(context) context.debug('Returning list of minio client aliases') return [] unless PuppetX::Minio::Client.installed? @@ -75,7 +75,7 @@ def to_puppet_alias(json) ensure: 'present', endpoint: json['URL'], access_key: json['accessKey'], - secret_key: Puppet::Pops::Types::PSensitiveType::Sensitive.new(json['secretKey']), + secret_key: Puppet::Pops::Types::PSensitiveType::Sensitive.new(json['secretKey'] || ''), api_signature: json['api'], path_lookup_support: path_lookup_support, } From 15978bdf53ad4126672a845e73be89819a30b337 Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Tue, 7 Sep 2021 16:51:00 +0200 Subject: [PATCH 5/6] Fixed issue with the name collision of symlink and minio settings directory Signed-off-by: Evgeny Soynov --- README.md | 3 +++ REFERENCE.md | 8 ++++---- data/common.yaml | 2 +- .../minio_client_alias/minio_client_alias.rb | 12 ++++++------ lib/puppet/type/minio_client_alias.rb | 4 ++-- lib/puppet_x/minio/client.rb | 14 +++++++------- manifests/client/install.pp | 1 - .../minio_client_alias/minio_client_alias_spec.rb | 11 ++++++----- spec/unit/puppet_x/minio/client_spec.rb | 5 +++-- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 5fffeb0..86425b3 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,9 @@ class { 'minio::client': See [metadata.json](metadata.json) for supported platforms. +* It's currently not possible to purge unmanaged client aliases in the same run + when the client is being installed. + ## Development ### Running tests diff --git a/REFERENCE.md b/REFERENCE.md index f2ef6b5..676c263 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1474,7 +1474,7 @@ Default value: `$minio::server::home` ### `minio_client_alias` **Autorequires**: -* `Class[minio::client]` +* `File[/root/.minioclient]` #### Examples @@ -1508,13 +1508,13 @@ The following properties are available in the `minio_client_alias` type. ##### `access_key` -Data type: `String[1]` +Data type: `Optional[String]` The API access key ##### `api_signature` -Data type: `Optional[String[1]]` +Data type: `Optional[Enum['S3v4', 'S3v2']]` The API signature @@ -1540,7 +1540,7 @@ Indicate whether dns or path style url requests are supported by the server. ##### `secret_key` -Data type: `Variant[Sensitive[String[1]], String[1]]` +Data type: `Optional[Variant[Sensitive[String], String]]` The API access secret diff --git a/data/common.yaml b/data/common.yaml index 5819a1e..506dab4 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -30,7 +30,7 @@ minio::client_checksum_type: 'sha256' minio::client_installation_directory: '/usr/local/bin' minio::client_binary_name: 'minio-client' minio::client_aliases: {} -minio::purge_unmanaged_client_aliases: true +minio::purge_unmanaged_client_aliases: false minio::cert_ensure: 'present' minio::cert_directory: '/etc/minio/certs' minio::default_cert_name: 'miniodefault' diff --git a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb index b907824..fef206b 100644 --- a/lib/puppet/provider/minio_client_alias/minio_client_alias.rb +++ b/lib/puppet/provider/minio_client_alias/minio_client_alias.rb @@ -4,14 +4,14 @@ require 'puppet/resource_api/simple_provider' require 'puppet_x/minio/client' +LEGACY_PATH_SUPPORT_MAP ||= { + '': 'auto', + dns: 'off', + path: 'on', +}.freeze + # Implementation for the minio_client_alias type using the Resource API. class Puppet::Provider::MinioClientAlias::MinioClientAlias < Puppet::ResourceApi::SimpleProvider - LEGACY_PATH_SUPPORT_MAP = { - '': 'auto', - dns: 'off', - path: 'on', - }.freeze - def get(context) context.debug('Returning list of minio client aliases') return [] unless PuppetX::Minio::Client.installed? diff --git a/lib/puppet/type/minio_client_alias.rb b/lib/puppet/type/minio_client_alias.rb index 916a4b0..98aa872 100644 --- a/lib/puppet/type/minio_client_alias.rb +++ b/lib/puppet/type/minio_client_alias.rb @@ -25,7 +25,7 @@ } **Autorequires**: -* `Class[minio::client]` +* `File[/root/.minioclient]` EOS features: ['custom_insync'], attributes: { @@ -61,6 +61,6 @@ }, }, autorequire: { - class: 'minio::client::install', + file: '/root/.minioclient', }, ) diff --git a/lib/puppet_x/minio/client.rb b/lib/puppet_x/minio/client.rb index 2ea163d..161c5f0 100644 --- a/lib/puppet_x/minio/client.rb +++ b/lib/puppet_x/minio/client.rb @@ -5,13 +5,13 @@ module PuppetX # rubocop:disable Style/ClassAndModuleChildren module Minio # rubocop:disable Style/ClassAndModuleChildren class Client # rubocop:disable Style/Documentation - CLIENT_LOCATION = '/root/.minioclient' + CLIENT_LINK_LOCATION = '/root/.minioclient' - @client_ensured = false + @client_location = nil def self.execute(args, **execute_args) ensure_client_installed - cmd = "#{CLIENT_LOCATION} --json #{args}" + cmd = "#{@client_location} --json #{args}" out = Puppet::Util::Execution.execute(cmd, failonfail: true, **execute_args) out.each_line.map do |line| @@ -20,21 +20,21 @@ def self.execute(args, **execute_args) end def self.ensure_client_installed - return if @client_ensured + return if @client_location unless installed? errormsg = [ - "Symlink to minio client does not exist at #{CLIENT_LOCATION}. ", + "Symlink to minio client does not exist at #{CLIENT_LINK_LOCATION}. ", 'Make sure you installed the client before managing minio resources.', ] raise Puppet::ExecutionFailure, errormsg.join end - @client_ensured = true + @client_location = File.readlink(CLIENT_LINK_LOCATION) end def self.installed? - File.exist?(CLIENT_LOCATION) + File.exist?(CLIENT_LINK_LOCATION) end end end diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 26d62ea..72b4d06 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -74,6 +74,5 @@ -> file { '/root/.minioclient': ensure => $link_ensure, target => $target, - mode => '0744' } } diff --git a/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb b/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb index 14d040b..54e87f0 100644 --- a/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb +++ b/spec/unit/puppet/provider/minio_client_alias/minio_client_alias_spec.rb @@ -14,6 +14,7 @@ allow(context).to receive(:debug) allow(context).to receive(:notice) allow(File).to receive(:exist?).and_return(true) + allow(File).to receive(:readlink).and_return('/usr/local/sbin/minio-client') Puppet::Util::ExecutionStub.set do |_command, _options| '' end @@ -75,7 +76,7 @@ describe 'create(context, name, should)' do it 'creates the resource' do Puppet::Util::ExecutionStub.set do |command, _options| - expect(command).to eq '/root/.minioclient --json alias set test http://example.com access secret --api S3v4 --path on' + expect(command).to eq '/usr/local/sbin/minio-client --json alias set test http://example.com access secret --api S3v4 --path on' '' end @@ -93,7 +94,7 @@ it 'does not add api signature when not provided in puppet resource' do Puppet::Util::ExecutionStub.set do |command, _options| - expect(command).to eq '/root/.minioclient --json alias set test http://example.com access secret --path on' + expect(command).to eq '/usr/local/sbin/minio-client --json alias set test http://example.com access secret --path on' '' end @@ -109,7 +110,7 @@ it 'does not add path when not provided in puppet resource' do Puppet::Util::ExecutionStub.set do |command, _options| - expect(command).to eq '/root/.minioclient --json alias set test http://example.com access secret --api S3v4' + expect(command).to eq '/usr/local/sbin/minio-client --json alias set test http://example.com access secret --api S3v4' '' end @@ -129,7 +130,7 @@ expect(context).to receive(:notice).with(%r{\AUpdating 'foo'}) Puppet::Util::ExecutionStub.set do |command, _options| - expect(command).to eq '/root/.minioclient --json alias set foo http://example.com access secret' + expect(command).to eq '/usr/local/sbin/minio-client --json alias set foo http://example.com access secret' '' end @@ -148,7 +149,7 @@ expect(context).to receive(:notice).with(%r{\ADeleting 'foo'}) Puppet::Util::ExecutionStub.set do |command, _options| - expect(command).to eq '/root/.minioclient --json alias remove foo' + expect(command).to eq '/usr/local/sbin/minio-client --json alias remove foo' '' end diff --git a/spec/unit/puppet_x/minio/client_spec.rb b/spec/unit/puppet_x/minio/client_spec.rb index aac2094..3d0d898 100644 --- a/spec/unit/puppet_x/minio/client_spec.rb +++ b/spec/unit/puppet_x/minio/client_spec.rb @@ -6,7 +6,7 @@ RSpec.describe PuppetX::Minio::Client do before :each do - described_class.instance_variable_set(:@client_ensured, false) + described_class.instance_variable_set(:@client_location, nil) end describe 'execute' do @@ -22,13 +22,14 @@ context 'with client installed' do before :each do allow(File).to receive(:exist?).and_return(true) + allow(File).to receive(:readlink).and_return('/usr/local/sbin/minio-client') Puppet::Util::ExecutionStub.set do |command, _options| out = <<-JSONSTRINGS {"status":"success","alias":"test1"} {"status":"success","alias":"test2"} JSONSTRINGS - out if command == '/root/.minioclient --json alias list' + out if command == '/usr/local/sbin/minio-client --json alias list' end end From 00a868592196fbab994ce0b9609c81dc0b00e4ff Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Wed, 8 Sep 2021 12:16:15 +0200 Subject: [PATCH 6/6] Changed to puppet_litmus fork with removed rhel Signed-off-by: Evgeny Soynov --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8e01e4e..971c3b5 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ group :development do 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 "puppet-resource_api", require: false - gem 'puppet_litmus', git: 'https://github.com/puppetlabs/puppet_litmus.git', ref: 'main' + gem 'puppet_litmus', git: 'https://github.com/ZloeSabo/puppet_litmus.git', ref: 'feature/remove-rhel-support' end group :system_tests do gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby]