From 0491263b29a4d89ae942e598d6c29a80347cc384 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Mon, 2 Nov 2020 14:44:55 +0100 Subject: [PATCH] release 1.0.0 --- .fixtures.yml | 10 +++ .gitattributes | 5 ++ .gitignore | 27 ++++++++ .gitlab-ci.yml | 44 +++++++++++++ .pdkignore | 42 ++++++++++++ .puppet-lint.rc | 1 + .rspec | 2 + .rubocop.yml | 137 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 49 ++++++++++++++ .vscode/extensions.json | 6 ++ .yardopts | 1 + CHANGELOG.md | 11 ++++ Gemfile | 72 ++++++++++++++++++++ README.md | 84 +++++++++++++++++++++++- REFERENCE.md | 90 +++++++++++++++++++++++++ Rakefile | 87 +++++++++++++++++++++++++ appveyor.yml | 56 ++++++++++++++++ data/FreeBSD.yaml | 4 ++ data/Linux.yaml | 3 + data/common.yaml | 8 +++ hiera.yaml | 31 +++++++++ manifests/init.pp | 41 ++++++++++++ manifests/install.pp | 77 ++++++++++++++++++++++ metadata.json | 68 +++++++++++++++++++ spec/classes/lam_spec.rb | 108 ++++++++++++++++++++++++++++++ spec/default_facts.yml | 8 +++ spec/spec_helper.rb | 57 ++++++++++++++++ 27 files changed, 1128 insertions(+), 1 deletion(-) create mode 100644 .fixtures.yml create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .puppet-lint.rc create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .travis.yml create mode 100644 .vscode/extensions.json create mode 100644 .yardopts create mode 100644 CHANGELOG.md create mode 100644 Gemfile create mode 100644 REFERENCE.md create mode 100644 Rakefile create mode 100644 appveyor.yml create mode 100644 data/FreeBSD.yaml create mode 100644 data/Linux.yaml create mode 100644 data/common.yaml create mode 100644 hiera.yaml create mode 100644 manifests/init.pp create mode 100644 manifests/install.pp create mode 100644 metadata.json create mode 100644 spec/classes/lam_spec.rb create mode 100644 spec/default_facts.yml create mode 100644 spec/spec_helper.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..e3c0d43 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,10 @@ +# This file can be used to install module dependencies for unit testing +# See https://github.com/puppetlabs/puppetlabs_spec_helper#using-fixtures for details +--- +fixtures: + repositories: + "archive": "https://github.com/voxpupuli/puppet-archive.git" + "facts": "https://github.com/puppetlabs/puppetlabs-facts.git" + "provision": "https://github.com/puppetlabs/provision.git" + "puppet_agent": "https://github.com/puppetlabs/puppetlabs-puppet_agent.git" + "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" 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 new file mode 100644 index 0000000..2767022 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +.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 +.project +.envrc +/inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4868bf7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,44 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# Set `rubygems_version` in the .sync.yml to set a value" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6: + stage: syntax + image: ruby:2.5.7 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.5.7-Puppet ~> 6: + stage: unit + image: ruby:2.5.7 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.4.5-Puppet ~> 5: + stage: unit + image: ruby:2.4.5 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..e6215cd --- /dev/null +++ b/.pdkignore @@ -0,0 +1,42 @@ +.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 +.project +.envrc +/inventory.yaml +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/rakelib/ +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ +/.vscode/ 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 new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5307849 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,137 @@ +--- +require: +- rubocop-rspec +- rubocop-i18n +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/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. + 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/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 +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 +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +GetText/DecorateFunctionMessage: + Enabled: false +GetText/DecorateStringFormattingUsingInterpolation: + Enabled: false +GetText/DecorateStringFormattingUsingPercent: + Enabled: false +Layout/EndOfLine: + Enabled: false +Layout/IndentHeredoc: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false +RSpec/DescribeClass: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/NestedGroups: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..68d3e96 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,49 @@ +--- +os: linux +dist: xenial +language: ruby +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.7 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy +jobs: + fast_finish: true + include: + - + env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + stage: static + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.5 + stage: spec + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.7 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy +branches: + only: + - master + - /^v\d/ +notifications: + email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..29c933b --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..342f6b1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All 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/spec/v2.0.0.html). + +## v1.0.0 +Initial release + +[Unreleased]: https://github.com/markt-de/puppet-lam/compare/v1.0.0...HEAD diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8007ad0 --- /dev/null +++ b/Gemfile @@ -0,0 +1,72 @@ +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 "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] +end + +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/README.md b/README.md index 992a840..29d3c38 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,84 @@ # puppet-lam -A Puppet module to manage LDAP Account Manager (LAM) + +[![Build Status](https://travis-ci.org/markt-de/puppet-lam.png?branch=master)](https://travis-ci.org/markt-de/puppet-lam) +[![Puppet Forge](https://img.shields.io/puppetforge/v/fraenki/lam.svg)](https://forge.puppetlabs.com/fraenki/lam) +[![Puppet Forge](https://img.shields.io/puppetforge/f/fraenki/lam.svg)](https://forge.puppetlabs.com/fraenki/lam) + +#### Table of Contents + +1. [Overview](#overview) +1. [Requirements](#requirements) +1. [Usage](#usage) + - [Basic usage](#basic-usage) +1. [Reference](#reference) +1. [Development](#development) + - [Contributing](#contributing) + +## Overview + +A puppet module to install and configure [LDAP Account Manager (LAM)](https://github.com/LDAPAccountManager/lam), a webfrontend for managing entries stored in an LDAP directory. + +## Requirements + +A working PHP installation as well as a properly configured webserver are required. + +Both [puppet-php](https://github.com/voxpupuli/puppet-php/) as well as [puppetlabs-apache](https://github.com/puppetlabs/puppetlabs-apache/) are highly recommended to setup a functional environment. This task is beyond the scope of this module. + +## Usage + +### Basic usage + +The minimum configuration should at least specify the desired version: + +```puppet +class { 'lam': + version => '7.3', +} +``` + +This will install and configure LAM. You should use the symlink target (which defaults to `/opt/lam`) as the document root when setting up the webserver. + +LAM needs write access to several directories, so if your webserver runs with a different user account, you should specify: + +```puppet +class { 'lam': + group => 'wwwgroup', + user => 'wwwuser', + version => '7.3', +} +``` + +The module maintains a dedicated data directory for LAM, so configuration and runtime data is not lost when upgrading. The location of this directory can be customized: + +```puppet +class { 'lam': + datadir => '/path/to/lam-data', + version => '7.3', +} +``` + +### Pro edition + +In theory the Pro edition of LAM is supported by the `$edition` parameter. You need to download it from the customer portal and place the archive on a local mirror, which should later be specified by using the `$mirror` parameter. + +However, due to the lack of a test license this feature is untested. + +```puppet +class { 'lam': + edition => 'pro', + mirror => 'http://company.example.com/path/to/archive/%s', + version => '7.3', +} +``` + +## Reference + +Classes and parameters are documented in [REFERENCE.md](REFERENCE.md). + +## Development + +### Contributing + +Please use the GitHub issues functionality to report any bugs or requests for new features. Feel free to fork and submit pull requests for potential contributions. + +Contributions must pass all existing tests, new features should provide additional unit/acceptance tests. diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..eb89447 --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,90 @@ +# Reference + + + +## Table of Contents + +### Classes + +#### Public Classes + +* [`lam`](#lam): Setup LDAP Account Manager (LAM) + +#### Private Classes + +* `lam::install`: Download and extract the distribution archive + +## Classes + +### `lam` + +Setup LDAP Account Manager (LAM) + +#### Parameters + +The following parameters are available in the `lam` class. + +##### `datadir` + +Data type: `Stdlib::Compat::Absolute_path` + +Specifies the directory where LAM should store its configuration +and other persistent data. A symlink is created in `$installroot` +that points to this directory. It should exist outside of `$installroot`. + +##### `edition` + +Data type: `Enum['oss', 'pro']` + +The edition of LAM that should be installed. + +##### `group` + +Data type: `String` + +The name of the group that is used by the webserver process. + +##### `installroot` + +Data type: `Stdlib::Compat::Absolute_path` + +Specifies the base directory where LAM should be installed. A new +subdirectory for each version will be created. + +##### `mirror` + +Data type: `Variant[Stdlib::HTTPUrl,Stdlib::HTTPSUrl]` + +Specifies the base URL where the distribution archive can be downloaded. +Useful when providing a local mirror for the Pro edition. + +##### `user` + +Data type: `String` + +The name of the user that is used by the webserver process. + +##### `version` + +Data type: `String` + +Specifies the version of LAM that should be installed. + +##### `manage_symlink` + +Data type: `Boolean` + + + +##### `path` + +Data type: `String` + + + +##### `symlink_name` + +Data type: `String` + + + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..0a5093b --- /dev/null +++ b/Rakefile @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +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? + +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 + +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + + returnVal = nil + returnVal ||= begin + metadata_source = JSON.load(File.read('metadata.json'))['source'] + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) + + metadata_source_match && metadata_source_match[1] + end + + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? + + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal +end + +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = "v%s" % 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 + +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; LABEL THEM ON GITHUB" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["enhancement", "feature"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bug", "documentation", "bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise < 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" +EOM + end +end + diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ec38949 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,56 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master + - release +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/data/FreeBSD.yaml b/data/FreeBSD.yaml new file mode 100644 index 0000000..e9ea2cf --- /dev/null +++ b/data/FreeBSD.yaml @@ -0,0 +1,4 @@ +--- +lam::group: 'www' +lam::installroot: '/usr/local/www' +lam::user: 'www' diff --git a/data/Linux.yaml b/data/Linux.yaml new file mode 100644 index 0000000..9d83888 --- /dev/null +++ b/data/Linux.yaml @@ -0,0 +1,3 @@ +--- +lam::group: 'apache' +lam::user: 'apache' diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..1b747f8 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,8 @@ +--- +lam::edition: 'oss' +lam::datadir: "%{lookup('lam::installroot')}/lam-data" +lam::installroot: '/opt' +lam::manage_symlink: true +lam::mirror: 'http://prdownloads.sourceforge.net/lam/%s?download' +lam::path: '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin' +lam::symlink_name: 'lam' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..18680e4 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,31 @@ +--- +version: 5 + +defaults: + datadir: data + data_hash: yaml_data + +hierarchy: + - name: 'Set important hiera options' + path: "hiera_options.yaml" + + - name: 'Distribution Full Version' + path: '%{facts.os.name}-%{facts.os.release.full}.yaml' + + - name: 'Distribution Major Version' + path: '%{facts.os.name}-%{facts.os.release.major}.yaml' + + - name: 'Distribution Name' + path: '%{facts.os.name}.yaml' + + - name: 'OS Family Major Version' + path: '%{facts.os.family}-%{facts.os.release.major}-family.yaml' + + - name: 'OS Family' + path: '%{facts.os.family}-family.yaml' + + - name: 'OS Kernel' + path: '%{facts.kernel}.yaml' + + - name: 'common' + path: 'common.yaml' diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..134bbdf --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,41 @@ +# @summary Setup LDAP Account Manager (LAM) +# +# @param datadir +# Specifies the directory where LAM should store its configuration +# and other persistent data. A symlink is created in `$installroot` +# that points to this directory. It should exist outside of `$installroot`. +# +# @param edition +# The edition of LAM that should be installed. +# +# @param group +# The name of the group that is used by the webserver process. +# +# @param installroot +# Specifies the base directory where LAM should be installed. A new +# subdirectory for each version will be created. +# +# @param mirror +# Specifies the base URL where the distribution archive can be downloaded. +# Useful when providing a local mirror for the Pro edition. +# +# @param user +# The name of the user that is used by the webserver process. +# +# @param version +# Specifies the version of LAM that should be installed. +# +class lam ( + Stdlib::Compat::Absolute_path $datadir, + Enum['oss', 'pro'] $edition, + String $group, + Stdlib::Compat::Absolute_path $installroot, + Boolean $manage_symlink, + Variant[Stdlib::HTTPUrl,Stdlib::HTTPSUrl] $mirror, + String $path, + String $symlink_name, + String $user, + String $version, +) { + class { 'lam::install': } +} diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..ffd6523 --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,77 @@ +# @summary Download and extract the distribution archive +# @api private +class lam::install { + assert_private() + + include 'archive' + + $distribution_dir = "ldap-account-manager-${lam::version}" + $archive_name = "${distribution_dir}.tar.bz2" + $download_url = sprintf($lam::mirror, $archive_name) + $install_dir = "${lam::installroot}/${distribution_dir}" + + archive { "${lam::installroot}/${archive_name}": + source => $download_url, + extract => true, + extract_path => $lam::installroot, + creates => $install_dir, + cleanup => false, + } + + # Create LAM data directory. + file { $lam::datadir: + ensure => directory, + group => $lam::group, + owner => $lam::user, + } + + # Initialize the data directory by copying the default configs. + -> exec { "Initialize LAM data directory ${lam::datadir}": + command => "mv ${install_dir}/config ${lam::datadir}/ && ln -s ${lam::datadir}/config ${install_dir}/", + path => $lam::path, + onlyif => "test ! -d ${lam::datadir}/config", + } + + # Install default configuration if no configuration can be found. + -> exec { 'Setup initial LAM configuration': + command => "cp ${lam::datadir}/config/config.cfg.sample ${lam::datadir}/config/config.cfg", + path => $lam::path, + onlyif => "test ! -f ${lam::datadir}/config/config.cfg", + } + + # Restore LAM data by replacing the default config directory + # with a symlink to the actual data directory. The default directory + # is preserved for safekeeping. + -> exec { "Activate LAM data directory for version ${lam::version}": + command => "mv ${install_dir}/config ${install_dir}/config.dist && ln -s ${lam::datadir}/config ${install_dir}/", + path => $lam::path, + onlyif => "test -d ${lam::datadir}/config && test ! -L ${install_dir}/config", + refreshonly => true, + subscribe => [ + Archive["${lam::installroot}/${archive_name}"], + ], + } + + # LAM requires that several files and folders are writable. + -> exec { 'Fix permissions of LAM installation': + command => "chown -R ${lam::user}:${lam::group} ${lam::datadir}/config ${install_dir}/sess ${install_dir}/tmp", + path => $lam::path, + refreshonly => true, + subscribe => [ + Archive["${lam::installroot}/${archive_name}"], + ], + } + + # Maintain a symlink that points to the current version. + if ($lam::manage_symlink) { + file { "${lam::installroot}/${lam::symlink_name}": + ensure => link, + target => $install_dir, + require => [ + Archive["${lam::installroot}/${archive_name}"], + Exec["Initialize LAM data directory ${lam::datadir}"], + Exec["Activate LAM data directory for version ${lam::version}"], + ], + } + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..b1cb6e4 --- /dev/null +++ b/metadata.json @@ -0,0 +1,68 @@ +{ + "name": "fraenki-lam", + "version": "1.0.0", + "author": "markt.de", + "summary": "Setup LDAP Account Manager (LAM)", + "license": "BSD-2-Clause", + "source": "https://github.com/markt-de/puppet-lam", + "project_page": "https://github.com/markt-de/puppet-lam", + "issues_url": "https://github.com/markt-de/puppet-lam/issues", + "tags": [ + "lam", + "ldap", + "account", + "manager" + ], + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 6.0.0 < 7.0.0" + }, + { + "name": "puppet/archive", + "version_requirement": ">= 4.0.0 < 5.0.0" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "7", + "8" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7", + "8" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "9", + "10" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "18.04", + "20.04" + ] + }, + { + "operatingsystem": "FreeBSD" + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 5.0.0 < 7.0.0" + } + ], + "pdk-version": "1.18.1", + "template-url": "pdk-default#1.18.1", + "template-ref": "tags/1.18.1-0-g3d2e75c" +} diff --git a/spec/classes/lam_spec.rb b/spec/classes/lam_spec.rb new file mode 100644 index 0000000..f8a9135 --- /dev/null +++ b/spec/classes/lam_spec.rb @@ -0,0 +1,108 @@ +require 'spec_helper' + +describe 'lam' do + on_supported_os(facterversion: '2.4').each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + let(:archive_name) { 'ldap-account-manager-7.3.tar.bz2' } + let(:data_dir) { '/opt/lam-data' } + let(:data_dir_alt) { '/data/lam-data' } + let(:dist_dir) { 'ldap-account-manager-7.3' } + let(:install_root) { '/opt' } + let(:install_root_alt) { '/mnt' } + let(:lam_group) { 'apache' } + let(:lam_user) { 'apache' } + let(:lam_version) { '7.3' } + let(:symlink_name) { '/opt/lam' } + + context 'with only required parameters' do + let(:params) do + { + version: lam_version, + } + end + + it { is_expected.to compile } + it { is_expected.to contain_class('lam::install') } + + it { + is_expected.to contain_archive("#{install_root}/#{archive_name}").with( + source: "http://prdownloads.sourceforge.net/lam/#{archive_name}?download", + extract: true, + extract_path: install_root, + creates: "#{install_root}/#{dist_dir}", + cleanup: false, + ) + } + + it { + is_expected.to contain_exec("Initialize LAM data directory #{data_dir}").with( + command: "mv #{install_root}/#{dist_dir}/config #{data_dir}/ && ln -s #{data_dir}/config #{install_root}/#{dist_dir}/", + onlyif: "test ! -d #{data_dir}/config", + ) + } + + it { + is_expected.to contain_exec('Setup initial LAM configuration').with( + command: "cp #{data_dir}/config/config.cfg.sample #{data_dir}/config/config.cfg", + onlyif: "test ! -f #{data_dir}/config/config.cfg", + ) + } + + it { + is_expected.to contain_exec("Activate LAM data directory for version #{lam_version}").with( + command: "mv #{install_root}/#{dist_dir}/config #{install_root}/#{dist_dir}/config.dist && ln -s #{data_dir}/config #{install_root}/#{dist_dir}/", + onlyif: "test -d #{data_dir}/config && test ! -L #{install_root}/#{dist_dir}/config", + refreshonly: true, + ).that_subscribes_to("Archive[#{install_root}/#{archive_name}]") + } + + it { + is_expected.to contain_exec('Fix permissions of LAM installation').with( + command: "chown -R #{lam_user}:#{lam_group} #{data_dir}/config #{install_root}/#{dist_dir}/sess #{install_root}/#{dist_dir}/tmp", + refreshonly: true, + ).that_subscribes_to("Archive[#{install_root}/#{archive_name}]") + } + + it { + is_expected.to contain_file(symlink_name).with( + ensure: 'link', + target: "#{install_root}/#{dist_dir}", + ).that_requires("Archive[#{install_root}/#{archive_name}]") + } + end + + context 'with custom parameters' do + let(:params) do + { + datadir: '/data/lam-data', + installroot: '/mnt', + manage_symlink: false, + version: lam_version, + } + end + + it { is_expected.to compile } + + it { + is_expected.to contain_archive("#{install_root_alt}/#{archive_name}").with( + extract_path: install_root_alt, + creates: "#{install_root_alt}/#{dist_dir}", + ) + } + + it { + is_expected.to contain_exec('Fix permissions of LAM installation').with( + command: "chown -R #{lam_user}:#{lam_group} #{data_dir_alt}/config #{install_root_alt}/#{dist_dir}/sess #{install_root_alt}/#{dist_dir}/tmp", + ) + } + + it { + is_expected.not_to contain_file(symlink_name).with( + ensure: 'link', + ) + } + end + end + end +end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..f777abf --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,8 @@ +# 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" +ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d3778ca --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +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 + +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), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end + +RSpec.configure do |c| + 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 + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end +end + +# Ensures that a module is defined +# @param module_name Name of the module +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