diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index 6dfe023..650022e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,24 @@ -.*.sw? -/pkg -/spec/fixtures -/.rspec_system -/.vagrant -/.bundle -/vendor -/Gemfile.lock -/junit -/log +.git/ +.*.sw[op] +.metadata .yardoc -coverage +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ea59806 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,42 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: + stage: unit + image: ruby:2.1.9 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 4.0' + RUBYGEMS_VERSION: '2.7.8' + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: + stage: syntax + image: ruby:2.4.4 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 5.5' + +parallel_spec-Ruby 2.4.4-Puppet ~> 5.5: + stage: unit + image: ruby:2.4.4 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5.5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..b713b3b --- /dev/null +++ b/.pdkignore @@ -0,0 +1,37 @@ +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..cc96ece --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.rspec b/.rspec index 4cd92bf..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ ---format documentation --color ---fail-fast +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml index e4d810a..f5a6c2a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,480 +1,122 @@ +--- +require: rubocop-rspec AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" Exclude: - # Ignore HTML related things - - '**/*.erb' - # Ignore vendored gems - - 'vendor/**/*' - # Ignore code from test fixtures - - 'spec/fixtures/**/*' - -Lint/ConditionPosition: - Enabled: true - -Lint/ElseLayout: - Enabled: true - -Lint/UnreachableCode: - Enabled: true - -Lint/UselessComparison: - Enabled: true - -Lint/EnsureReturn: - Enabled: true - -Lint/HandleExceptions: - Enabled: true - -Lint/LiteralInCondition: - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Enabled: true - -Lint/LiteralInInterpolation: - Enabled: true - -Style/RedundantReturn: - Enabled: true - -Lint/AmbiguousOperator: - Enabled: true - -Lint/AssignmentInCondition: - Enabled: true - -Style/SpaceBeforeComment: - Enabled: true - -# DISABLED - not useful -Style/HashSyntax: - Enabled: false - -# USES: as shortcut for non nil&valid checking a = x() and a.empty? -# DISABLED - not useful -Style/AndOr: - Enabled: false - -# DISABLED - not useful -Style/RedundantSelf: - Enabled: false - -# DISABLED - not useful -Metrics/MethodLength: - Enabled: false - -# DISABLED - not useful -Style/WhileUntilModifier: - Enabled: false - -# DISABLED - the offender is just haskell envy -Lint/AmbiguousRegexpLiteral: - Enabled: false - -# DISABLED -Lint/Eval: - Enabled: false - -# DISABLED -Lint/BlockAlignment: - Enabled: false - -# DISABLED -Lint/DefEndAlignment: - Enabled: false - -# DISABLED -Lint/EndAlignment: - Enabled: false - -# DISABLED -Lint/DeprecatedClassMethods: - Enabled: false - -# DISABLED -Lint/Loop: - Enabled: false - -# DISABLED -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -Lint/RescueException: - Enabled: false - -Lint/StringConversionInInterpolation: - Enabled: false - -Lint/UnusedBlockArgument: - Enabled: false - -Lint/UnusedMethodArgument: - Enabled: false - -Lint/UselessAccessModifier: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/* +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: Enabled: true - -Lint/UselessAssignment: +Style/MethodCalledOnDoEndBlock: Enabled: true - -Lint/Void: +Style/StringMethods: Enabled: true - -Style/AccessModifierIndentation: - Enabled: false - -Style/AccessorMethodName: - Enabled: false - -Style/Alias: - Enabled: false - -Style/AlignArray: - Enabled: false - -Style/AlignHash: - Enabled: false - -Style/AlignParameters: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Style/AsciiComments: - Enabled: false - -Style/Attr: - Enabled: false - -Style/BracesAroundHashParameters: - Enabled: false - -Style/CaseEquality: - Enabled: false - -Style/CaseIndentation: +Layout/EndOfLine: Enabled: false - -Style/CharacterLiteral: +Layout/IndentHeredoc: Enabled: false - -Style/ClassAndModuleCamelCase: +Metrics/AbcSize: Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/ClassCheck: +Metrics/BlockLength: Enabled: false - Metrics/ClassLength: Enabled: false - -Style/ClassMethods: - Enabled: false - -Style/ClassVars: - Enabled: false - -Style/WhenThen: - Enabled: false - -# DISABLED - not useful -Style/WordArray: - Enabled: false - -Style/UnneededPercentQ: - Enabled: false - -Style/Tab: - Enabled: false - -Style/SpaceBeforeSemicolon: - Enabled: false - -Style/TrailingBlankLines: - Enabled: false - -Style/SpaceInsideBlockBraces: - Enabled: false - -Style/SpaceInsideBrackets: - Enabled: false - -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -Style/SpaceInsideParens: - Enabled: false - -Style/LeadingCommentSpace: - Enabled: false - -Style/SingleSpaceBeforeFirstArg: - Enabled: false - -Style/SpaceAfterColon: - Enabled: false - -Style/SpaceAfterComma: - Enabled: false - -Style/SpaceAfterControlKeyword: - Enabled: false - -Style/SpaceAfterMethodName: - Enabled: false - -Style/SpaceAfterNot: - Enabled: false - -Style/SpaceAfterSemicolon: - Enabled: false - -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - -Style/SpaceAroundOperators: - Enabled: false - -Style/SpaceBeforeBlockBraces: - Enabled: false - -Style/SpaceBeforeComma: - Enabled: false - -Style/CollectionMethods: - Enabled: false - -Style/CommentIndentation: - Enabled: false - -Style/ColonMethodCall: - Enabled: false - -Style/CommentAnnotation: - Enabled: false - Metrics/CyclomaticComplexity: Enabled: false - -Style/ConstantName: - Enabled: false - -Style/Documentation: - Enabled: false - -Style/DefWithParentheses: - Enabled: false - -Style/DeprecatedHashMethods: - Enabled: false - -Style/DotPosition: - Enabled: false - -# DISABLED - used for converting to bool -Style/DoubleNegation: - Enabled: false - -Style/EachWithObject: - Enabled: false - -Style/EmptyLineBetweenDefs: - Enabled: false - -Style/IndentArray: - Enabled: false - -Style/IndentHash: - Enabled: false - -Style/IndentationConsistency: - Enabled: false - -Style/IndentationWidth: - Enabled: false - -Style/EmptyLines: - Enabled: false - -Style/EmptyLinesAroundAccessModifier: - Enabled: false - -Style/EmptyLiteral: +Metrics/MethodLength: Enabled: false - -Metrics/LineLength: +Metrics/ModuleLength: Enabled: false - -Style/MethodCallParentheses: +Metrics/ParameterLists: Enabled: false - -Style/MethodDefParentheses: +Metrics/PerceivedComplexity: Enabled: false - -Style/LineEndConcatenation: +RSpec/DescribeClass: Enabled: false - -Style/TrailingWhitespace: +RSpec/ExampleLength: Enabled: false - -Style/StringLiterals: +RSpec/MessageExpectation: Enabled: false - -Style/TrailingComma: +RSpec/MultipleExpectations: Enabled: false - -Style/GlobalVars: +RSpec/NestedGroups: Enabled: false - -Style/GuardClause: +Style/AsciiComments: Enabled: false - Style/IfUnlessModifier: Enabled: false - -Style/MultilineIfThen: - Enabled: false - -Style/NegatedIf: - Enabled: false - -Style/NegatedWhile: - Enabled: false - -Style/Next: - Enabled: false - -Style/SingleLineBlockParams: - Enabled: false - -Style/SingleLineMethods: - Enabled: false - -Style/SpecialGlobalVars: - Enabled: false - -Style/TrivialAccessors: - Enabled: false - -Style/UnlessElse: - Enabled: false - -Style/VariableInterpolation: - Enabled: false - -Style/VariableName: - Enabled: false - -Style/WhileUntilDo: - Enabled: false - -Style/EvenOdd: - Enabled: false - -Style/FileName: - Enabled: false - -Style/For: - Enabled: false - -Style/Lambda: - Enabled: false - -Style/MethodName: - Enabled: false - -Style/MultilineTernaryOperator: - Enabled: false - -Style/NestedTernaryOperator: - Enabled: false - -Style/NilComparison: - Enabled: false - -Style/FormatString: - Enabled: false - -Style/MultilineBlockChain: - Enabled: false - -Style/Semicolon: - Enabled: false - -Style/SignalException: - Enabled: false - -Style/NonNilCheck: - Enabled: false - -Style/Not: - Enabled: false - -Style/NumericLiterals: - Enabled: false - -Style/OneLineConditional: - Enabled: false - -Style/OpMethod: - Enabled: false - -Style/ParenthesesAroundCondition: - Enabled: false - -Style/PercentLiteralDelimiters: - Enabled: false - -Style/PerlBackrefs: - Enabled: false - -Style/PredicateName: - Enabled: false - -Style/RedundantException: - Enabled: false - -Style/SelfAssignment: - Enabled: false - -Style/Proc: - Enabled: false - -Style/RaiseArgs: - Enabled: false - -Style/RedundantBegin: - Enabled: false - -Style/RescueModifier: - Enabled: false - -Style/RegexpLiteral: - Enabled: false - -Lint/UnderscorePrefixedVariableName: - Enabled: false - -Metrics/ParameterLists: - Enabled: false - -Lint/RequireParentheses: - Enabled: false - -Lint/SpaceBeforeFirstArg: - Enabled: false - -Style/ModuleFunction: - Enabled: false - -Lint/Debugger: - Enabled: false - -Style/IfWithSemicolon: - Enabled: false - -Style/Encoding: +Style/SymbolProc: Enabled: false diff --git a/.travis.yml b/.travis.yml index cdb20f6..521510d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,43 @@ --- +dist: trusty language: ruby -bundler_args: --without development system_tests -before_install: rm Gemfile.lock || true +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests rvm: - - 2.0.0 - - 2.1.0 -script: bundle exec rake test + - 2.5.1 env: - - PUPPET_GEM_VERSION="~> 3.8.0" STRICT_VARIABLES=yes - - PUPPET_GEM_VERSION="~> 3.8.0" STRICT_VARIABLES=yes FUTURE_PARSER=yes + global: + - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" +matrix: + fast_finish: true + include: + - + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" + - + env: CHECK=parallel_spec + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.4 +branches: + only: + - master + - /^v\d/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index f8824ec..0000000 --- a/CHANGELOG +++ /dev/null @@ -1,17 +0,0 @@ -2015-12-18 Release 0.1.4 -- bugfix: make sure intermediate ca certificates are correctly placed in bundle -- bugfix: make sure dh parameters are created -- bugfix: notify service if pem files change - -2015-12-18 Release 0.1.3 -- bugfix: using multiple pem-files failed. Tests added. - -2015-12-18 Release 0.1.2 -- relax too-strict validation of strings containing keys and certificates - -2015-12-11 Release 0.1.1 -- fix versioned dependency on puppetlabs-stdlib in metadata -- fix documentation errors and nits - -2015-12-11 Release 0.1.0 -- initial release diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..dc0d21c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,28 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.4] - 2015-12-18 +### Fixed +- bugfix: make sure intermediate ca certificates are correctly placed in bundle +- bugfix: make sure dh parameters are created +- bugfix: notify service if pem files change + +## [0.1.3] - 2015-12-18 +### Fixed +- bugfix: using multiple pem-files failed. Tests added. + +## [0.1.2] - 2015-12-18 +### Fixed +- relax too-strict validation of strings containing keys and certificates + +## [0.1.1] - 2015-12-11 +### Fixed +- fix versioned dependency on puppetlabs-stdlib in metadata +- fix documentation errors and nits + +## [0.1.0] - 2015-12-11 +### Added +- initial release diff --git a/Gemfile b/Gemfile index ca3fd4e..cf2c387 100644 --- a/Gemfile +++ b/Gemfile @@ -1,33 +1,71 @@ -source "https://rubygems.org" - -group :test do - gem "rake" - gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 3.8.0' - gem "rspec", '< 3.2.0' - gem "rspec-puppet" - gem "puppetlabs_spec_helper" - gem "metadata-json-lint" - gem "rspec-puppet-facts" - gem 'rubocop', '0.33.0' - gem 'simplecov', '>= 0.11.0' - gem 'simplecov-console' - - gem "puppet-lint-absolute_classname-check" - gem "puppet-lint-leading_zero-check" - gem "puppet-lint-trailing_comma-check" - gem "puppet-lint-version_comparison-check" - gem "puppet-lint-classes_and_types_beginning_with_digits-check" - gem "puppet-lint-unquoted_string-check" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end end +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + group :development do - gem "travis" - gem "travis-lint" - gem "guard-rake" + 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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem "beaker" - gem "beaker-rspec" - gem "beaker-puppet_install_helper" +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +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 + +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end end +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 8ac719e..a6b14c5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,62 +1,76 @@ -require 'rubygems' -require 'bundler/setup' - require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet/version' -require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6 -require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' -require 'metadata-json-lint/rake_task' -require 'rubocop/rake_task' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -# These gems aren't always present, for instance -# on Travis with --without development -begin -rescue LoadError # rubocop:disable Lint/HandleExceptions +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator user:#{returnVal}" + returnVal end -RuboCop::RakeTask.new - -exclude_paths = [ - "bundle/**/*", - "pkg/**/*", - "vendor/**/*", - "spec/**/*", -] - -# Coverage from puppetlabs-spec-helper requires rcov which -# doesn't work in anything since 1.8.7 -Rake::Task[:coverage].clear - -Rake::Task[:lint].clear - -PuppetLint.configuration.relative = true -PuppetLint.configuration.disable_80chars -PuppetLint.configuration.disable_class_inherits_from_params_class -PuppetLint.configuration.disable_class_parameter_defaults -PuppetLint.configuration.fail_on_warnings = true - -PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = exclude_paths +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['name'] + raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal end -PuppetSyntax.exclude_paths = exclude_paths - -desc "Run acceptance tests" -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal end -desc "Populate CONTRIBUTORS file" -task :contributors do - system("git log --format='%aN' | sort -u > CONTRIBUTORS") +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? + config.user = "#{changelog_user}" + config.project = "#{changelog_project}" + config.future_release = "#{changelog_future_release}" + config.exclude_labels = ['maintenance'] + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." + config.add_pr_wo_labels = true + config.issues = false + config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end end -desc "Run syntax, lint, and spec tests." -task :test => [ - :metadata_lint, - :syntax, - :lint, - :rubocop, - :spec, -] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e10ba3b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,55 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master +skip_commits: + message: /^\(?doc\)?.*/ +clone_depth: 10 +init: + - SET + - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' +environment: + matrix: + - + RUBY_VERSION: 24-x64 + CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24-x64 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25-x64 + CHECK: parallel_spec +matrix: + fast_finish: true +install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 --without system_tests + - type Gemfile.lock +build: off +test_script: + - bundle exec puppet -V + - ruby -v + - gem -v + - bundle -v + - bundle exec rake %CHECK% +notifications: + - provider: Email + to: + - nobody@nowhere.com + on_build_success: false + on_build_failure: false + on_build_status_changed: false diff --git a/manifests/config.pp b/manifests/config.pp index 39c2553..6eecaf3 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,58 +1,58 @@ # == Class hitch::config # # This class is called from hitch for service config. # class hitch::config { validate_absolute_path($::hitch::config_root) validate_absolute_path($::hitch::config_file) validate_absolute_path($::hitch::dhparams_file) if $::hitch::dhparams_content { validate_re($::hitch::dhparams_content, 'BEGIN DH PARAMETERS') } file { $::hitch::config_root: ensure => directory, recurse => true, purge => $::hitch::purge_config_root, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0750', } concat { $::hitch::config_file: ensure => present, } if $::hitch::dhparams_content { file { $::hitch::dhparams_file: ensure => present, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0640', content => $::hitch::dhparams_content, } } else { exec { "${title} generate dhparams": path => '/usr/local/bin:/usr/bin:/bin', command => "openssl dhparam 2048 -out ${::hitch::dhparams_file}", creates => $::hitch::dhparams_file, } - -> - file { $::hitch::dhparams_file: + + -> file { $::hitch::dhparams_file: ensure => present, owner => $::hitch::file_owner, group => $::hitch::group, mode => '0640', } } concat::fragment { "${title} config": content => template('hitch/hitch.conf.erb'), target => $::hitch::config_file, } create_resources('hitch::domain', $::hitch::domains) } diff --git a/manifests/init.pp b/manifests/init.pp index bec37a2..a418d47 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,42 +1,42 @@ # Class: hitch # =========================== # # Full description of class hitch here. # # Parameters # ---------- # # * `package_name` # Package name for installing hitch # # * `service_name` # Service name for the hitch service # # * `config_file` # Configuration file. Default: /etc/hitch/hitch.conf # # * `config_root` # Configuration root directory. Default: /etc/hitch/ class hitch ( $package_name = $::hitch::params::package_name, $service_name = $::hitch::params::service_name, $file_owner = $::hitch::params::file_owner, $config_file = $::hitch::params::config_file, $dhparams_file = $::hitch::params::dhparams_file, $dhparams_content = $::hitch::params::dhparams, $config_root = $::hitch::params::config_root, $purge_config_root = $::hitch::params::purge_config_root, $frontend = $::hitch::params::frontend, $backend = $::hitch::params::backend, $write_proxy_v2 = $::hitch::params::write_proxy_v2, $ciphers = $::hitch::params::ciphers, $domains = $::hitch::params::domains, ) inherits ::hitch::params { # validate parameters here - class { '::hitch::install': } -> - class { '::hitch::config': } ~> - class { '::hitch::service': } -> - Class['::hitch'] + class { '::hitch::install': } + -> class { '::hitch::config': } + ~> class { '::hitch::service': } + -> Class['::hitch'] } diff --git a/metadata.json b/metadata.json index 2844163..eaf84e7 100644 --- a/metadata.json +++ b/metadata.json @@ -1,34 +1,43 @@ { "name": "ssm-hitch", "version": "0.1.4", "author": "ssm", "summary": "Install and configure Hitch TLS proxy", "license": "Apache-2.0", "source": "https://github.com/ssm/ssm-hitch.git", "project_page": "https://github.com/ssm/ssm-hitch", "issues_url": "https://github.com/ssm/ssm-hitch/issues", "dependencies": [ { "name": "puppetlabs-stdlib", "version_requirement": ">= 4.0.0" }, { "name": "puppetlabs-concat", "version_requirement": ">= 1.0.0 <= 2.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Debian", "operatingsystemrelease": [ "8" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ "7" ] } - ] -} + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.10.0 < 7.0.0" + } + ], + "pdk-version": "1.9.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", + "template-ref": "1.9.0-0-g7281db5" +} \ No newline at end of file diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d827344..d2fe022 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,33 +1,33 @@ require 'spec_helper_acceptance' describe 'hitch class' do context 'default parameters' do # Using puppet_apply as a helper - it 'should work idempotently with no errors' do + it 'works idempotently with no errors' do pp = <<-EOS class { 'hitch': } hitch::domain { 'example.org': key_source => '/tmp/example.org_key.pem', cert_source => '/tmp/example.org_cert.pem', } hitch::domain { 'example.com': key_source => '/tmp/example.com_key.pem', cert_source => '/tmp/example.com_cert.pem', } EOS # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end describe package('hitch') do it { is_expected.to be_installed } end describe service('hitch') do it { is_expected.to be_enabled } it { is_expected.to be_running } end end end diff --git a/spec/classes/hitch_spec.rb b/spec/classes/hitch_spec.rb index f44a949..4a7c2f7 100644 --- a/spec/classes/hitch_spec.rb +++ b/spec/classes/hitch_spec.rb @@ -1,72 +1,71 @@ require 'spec_helper' describe 'hitch' do context 'supported operating systems' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - context "hitch class without any parameters" do + context 'hitch class without any parameters' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('hitch') } it { is_expected.to contain_class('hitch::params') } it { is_expected.to contain_class('hitch::install').that_comes_before('hitch::config') } it { is_expected.to contain_class('hitch::config') } it { is_expected.to contain_class('hitch::service').that_subscribes_to('hitch::config') } it { is_expected.to contain_service('hitch') } it { is_expected.to contain_package('hitch').with_ensure('present') } it { is_expected.to contain_file('/etc/hitch') } it { is_expected.to contain_file('/etc/hitch/dhparams.pem') } it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::config config') } it { is_expected.to contain_exec('hitch::config generate dhparams') } - context "osfamily specifics" do + context 'osfamily specifics' do if facts[:osfamily] == 'RedHat' it { is_expected.to contain_package('epel-release') } else it { is_expected.not_to contain_package('epel-release') } end end end - - context "hitch class with domains" do + context 'hitch class with domains' do let(:params) do - { :domains => { - 'example.com' => { - 'key_content' => '-----BEGIN PRIVATE KEY-----', - 'cert_content' => '-----BEGIN CERTIFICATE-----', - 'cacert_content' => '-----BEGIN CERTIFICATE-----', - 'dhparams_content' => '-----BEGIN DH PARAMETERS-----' - } - } - } + { domains: { + 'example.com' => { + 'key_content' => '-----BEGIN PRIVATE KEY-----', + 'cert_content' => '-----BEGIN CERTIFICATE-----', + 'cacert_content' => '-----BEGIN CERTIFICATE-----', + 'dhparams_content' => '-----BEGIN DH PARAMETERS-----', + }, + } } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } it { is_expected.to contain_file('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end end end end context 'unsupported operating system' do describe 'hitch class without any parameters on Solaris/Nexenta' do let(:facts) do { - :osfamily => 'Solaris', - :operatingsystem => 'Nexenta', + osfamily: 'Solaris', + operatingsystem: 'Nexenta', } end - it { expect { is_expected.to contain_package('hitch') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + it { expect { is_expected.to contain_package('hitch') }.to raise_error(Puppet::Error, %r{Nexenta not supported}) } end end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..ea1e480 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,7 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/hitch__domain_spec.rb b/spec/defines/hitch__domain_spec.rb index fee257e..294c969 100644 --- a/spec/defines/hitch__domain_spec.rb +++ b/spec/defines/hitch__domain_spec.rb @@ -1,84 +1,87 @@ require 'spec_helper' describe 'hitch::domain' do context 'supported operating systems' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end let(:title) { 'example.com' } - context "with all content parameters" do + context 'with all content parameters' do let(:params) do { 'cacert_content' => '-----BEGIN CERTIFICATE-----', 'cert_content' => '-----BEGIN CERTIFICATE-----', 'dhparams_content' => '-----BEGIN DH PARAMETERS-----', 'key_content' => '-----BEGIN PRIVATE KEY-----', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end - context "with all source parameters" do + context 'with all source parameters' do let(:params) do { 'cacert_source' => '/tmp/cacert.pem', 'cert_source' => '/tmp/cert.pem', 'dhparams_source' => '/tmp/dhparams.pem', 'key_source' => '/tmp/key.pem', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end - context "mandatory parameters" do + context 'mandatory parameters' do let(:params) do { 'cert_source' => '/tmp/cert.pem', 'key_source' => '/tmp/key.pem', } end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_hitch__domain('example.com') } # for the pem file it { is_expected.to contain_concat('/etc/hitch/example.com.pem') } it { is_expected.not_to contain_concat__fragment('example.com cacert') } it { is_expected.to contain_concat__fragment('example.com cert') } it { is_expected.to contain_concat__fragment('example.com key') } it { is_expected.to contain_concat__fragment('example.com dhparams') } # for the config file it { is_expected.to contain_concat('/etc/hitch/hitch.conf') } it { is_expected.to contain_concat__fragment('hitch::domain example.com') } end end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9ef380f..0d5efc0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,20 +1,47 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + include RspecPuppetFacts -require 'simplecov' -require 'simplecov-console' +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f))) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end RSpec.configure do |c| - c.default_facts = { concat_basedir: '/tmp' } + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end end -SimpleCov.start do - add_filter '/spec' - add_filter '/vendor' - formatter SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ]) +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end end + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c5abb30..ad5da2e 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,27 +1,27 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' require 'beaker/puppet_install_helper' run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'hitch') + puppet_module_install(source: proj_root, module_name: 'hitch') hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module', 'install', 'puppetlabs-concat'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] + on host, puppet('module', 'install', 'puppetlabs-concat'), acceptable_exit_codes: [0, 1] ['example.com', 'example.org'].each do |domain| - on host, 'openssl req -newkey rsa:2048 -sha256 -keyout /tmp/%s_key.pem -nodes -x509 -days 365 -out /tmp/%s_cert.pem -subj "/CN=%s"' % [ domain, domain, domain ] + on host, 'openssl req -newkey rsa:2048 -sha256 -keyout /tmp/%s_key.pem -nodes -x509 -days 365 -out /tmp/%s_cert.pem -subj "/CN=%s"' % [domain, domain, domain] end on host, 'ls -l /tmp' end end end