From f73013318ba7b0ba3c124173c3ccdeb3d53a5d19 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 15 Dec 2021 20:30:05 +0100 Subject: [PATCH 1/2] modulesync 5.2.0 --- .github/CONTRIBUTING.md | 7 ++--- .github/workflows/ci.yml | 58 +++-------------------------------- .github/workflows/release.yml | 32 ++++++------------- .msync.yml | 2 +- .puppet-lint.rc | 3 ++ Dockerfile | 2 +- Gemfile | 8 ++--- Rakefile | 2 +- spec/spec_helper.rb | 10 +++--- 9 files changed, 32 insertions(+), 92 deletions(-) create mode 100644 .puppet-lint.rc diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b5..8b466cf 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,17 +232,16 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_setfile=debian11-64 bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: -* ubuntu1604 * ubuntu1804 * ubuntu2004 -* debian9 * debian10 +* debian11 * centos7 * centos8 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5dad05..49981e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,60 +7,10 @@ name: CI on: pull_request concurrency: - group: ${{ github.head_ref }} + group: ${{ github.ref_name }} cancel-in-progress: true jobs: - setup_matrix: - name: 'Setup Test Matrix' - runs-on: ubuntu-latest - timeout-minutes: 40 - outputs: - puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} - github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} - env: - BUNDLE_WITHOUT: development:system_tests:release - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run static validations - run: bundle exec rake validate lint check - - name: Run rake rubocop - run: bundle exec rake rubocop - - name: Setup Test Matrix - id: get-outputs - run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false - - unit: - needs: setup_matrix - runs-on: ubuntu-latest - timeout-minutes: 40 - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} - env: - BUNDLE_WITHOUT: development:system_tests:release - PUPPET_VERSION: "~> ${{ matrix.puppet }}.0" - name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run tests - run: bundle exec rake parallel_spec - - tests: - needs: - - unit - runs-on: ubuntu-latest - name: Test suite - steps: - - run: echo Test suite completed + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/basic.yml@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba69..15f1721 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - 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 + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.msync.yml b/.msync.yml index 43966c2..968a936 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '5.2.0' diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..dd8272c --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/Dockerfile b/Dockerfile index e3cf307..8dd82d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /opt/puppet # https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 RUN mkdir -p /etc/sv -ARG PUPPET_VERSION="~> 6.0" +ARG PUPPET_GEM_VERSION="~> 6.0" ARG PARALLEL_TEST_PROCESSORS=4 # Cache gems diff --git a/Gemfile b/Gemfile index 92f05e5..476e0c9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 5.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'puppet_metadata', '~> 1.0', :require => false @@ -21,7 +21,7 @@ end group :release do gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false + gem 'voxpupuli-release', '>= 1.2.0', :require => false gem 'puppet-strings', '>= 2.2', :require => false end @@ -37,7 +37,7 @@ end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 80b799d..f92f051 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb5f0cb..4d617f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end From d3d643b1b2aa4165ffcf942afae762e11464509f Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 11 Mar 2022 23:21:17 +0100 Subject: [PATCH 2/2] rubocop: autofix --- lib/puppet/parser/functions/ldapquery.rb | 9 ++++----- lib/puppet_x/ldapquery.rb | 23 ++++++++++++----------- spec/unit/ldapquery_spec.rb | 5 ++++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/puppet/parser/functions/ldapquery.rb b/lib/puppet/parser/functions/ldapquery.rb index 4ecb2cc..7c4b6f9 100644 --- a/lib/puppet/parser/functions/ldapquery.rb +++ b/lib/puppet/parser/functions/ldapquery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Provides a query interface to an LDAP server # # @example simple query @@ -10,16 +12,13 @@ require_relative '../../../puppet_x/ldapquery' begin require 'net/ldap' -rescue +rescue StandardError Puppet.warn('Missing net/ldap gem required for ldapquery() function') end Puppet::Parser::Functions.newfunction(:ldapquery, type: :rvalue) do |args| - - if args.size > 3 - raise Puppet::ParseError, 'Too many arguments received in ldapquery()' - end + raise Puppet::ParseError, 'Too many arguments received in ldapquery()' if args.size > 3 filter, attributes, opts = args diff --git a/lib/puppet_x/ldapquery.rb b/lib/puppet_x/ldapquery.rb index c7f6993..41f8056 100644 --- a/lib/puppet_x/ldapquery.rb +++ b/lib/puppet_x/ldapquery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Class: PuppetX::LDAPquery # @@ -19,11 +21,12 @@ module PuppetX return unless scope - if scope == 'sub' + case scope + when 'sub' @scope = Net::LDAP::SearchScope_WholeSubtree - elsif scope == 'base' + when 'base' @scope = Net::LDAP::SearchScope_BaseObject - elsif scope == 'single' + when 'single' @scope = Net::LDAP::SearchScope_SingleLevel else raise Puppet::ParseError, 'Received param "scope" not one of ["sub","base","single"]' @@ -32,15 +35,13 @@ module PuppetX def ldap_config # Load the configuration variables from Puppet - required_vars = [ - :ldapserver, - :ldapport + required_vars = %i[ + ldapserver + ldapport ] required_vars.each do |r| - unless Puppet[r] - raise Puppet::ParseError, "Missing required setting '#{r}' in puppet.conf" - end + raise Puppet::ParseError, "Missing required setting '#{r}' in puppet.conf" unless Puppet[r] end port = Puppet[:ldapport] @@ -112,11 +113,11 @@ module PuppetX time_delta = format('%.3f', end_time - start_time) Puppet.debug("ldapquery(): Searching #{@base} for #{@attributes} using #{@filter} took #{time_delta} seconds and returned #{entries.length} results") - return entries + entries rescue Net::LDAP::LdapError => e Puppet.debug("There was an error searching LDAP #{e.message}") Puppet.debug('Returning false') - return false + false end end diff --git a/spec/unit/ldapquery_spec.rb b/spec/unit/ldapquery_spec.rb index 3d00e92..6b66600 100644 --- a/spec/unit/ldapquery_spec.rb +++ b/spec/unit/ldapquery_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet_x/ldapquery' require 'net/ldap' @@ -20,7 +22,7 @@ describe 'PuppetX::LDAPquery' do it 'fails with no filter' do filter = '' attributes = ['uid'] - expect { PuppetX::LDAPquery.new(filter, attributes).results }.to raise_error + expect { PuppetX::LDAPquery.new(filter, attributes).results }.to raise_error # rubocop:disable RSpec/UnspecifiedException end it 'does not fail when using defaults in puppet.conf' do @@ -56,6 +58,7 @@ describe 'PuppetX::LDAPquery' do allow(l).to receive(:entries).and_return(entries) expect(l.results).to eq(wanted) end + it 'returns the attributes without new lines' do filter = '(uid=zach)' attributes = ['sshPublicKey']