Skip to content

Commit

Permalink
add new webhook params and classes
Browse files Browse the repository at this point in the history
* Updated params to for the new webhook classes
* Created `r10k::webhook` class. This class contains all other classes
  and parameters.
* Added initial tests for os tests.
  • Loading branch information
dhollinger committed May 24, 2023
1 parent cb9b97a commit 48889b4
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 119 deletions.
127 changes: 25 additions & 102 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -70,106 +70,29 @@
$is_pe_server = false
}

if fact('pe_server_version') {
# PE 4 or greater specific settings
# r10k configuration

$pe_module_path = '/opt/puppetlabs/puppet/modules'

# Mcollective configuration dynamic
$mc_service_name = 'mcollective'
$plugins_dir = '/opt/puppetlabs/mcollective/plugins/mcollective'
$modulepath = "${r10k_basedir}/\$environment/modules:${pe_module_path}"

# webhook
$webhook_user = 'peadmin'
$webhook_pass = 'peadmin'
$webhook_group = 'peadmin'
$webhook_public_key_path = '/var/lib/peadmin/.mcollective.d/peadmin-cert.pem'
$webhook_private_key_path = '/var/lib/peadmin/.mcollective.d/peadmin-private.pem'
$webhook_certname = 'peadmin'
$webhook_certpath = '/var/lib/peadmin/.mcollective.d'
$root_user = 'root'
$root_group = 'root'
}
elsif versioncmp($facts['puppetversion'], '4.0.0') >= 0 {
#FOSS 4 or greater specific settings
# r10k configuration

$modulepath = "${r10k_basedir}/\$environment/modules"

# webhook
$webhook_user = 'puppet'
$webhook_pass = 'puppet'
$webhook_group = 'puppet'
$webhook_public_key_path = undef
$webhook_private_key_path = undef
$webhook_certname = undef
$webhook_certpath = undef
$root_user = 'root'
$root_group = 'root'
}
else {
fail("Puppet version ${facts['puppetversion']} is no longer supported. Please use an earlier version of puppet/r10k.")
}

# prerun_command in puppet.conf
$pre_postrun_command = "${r10k_binary} deploy environment -p"

# Webhook configuration information
$webhook_bind_address = '*'
$webhook_port = '8088'
$webhook_client_cfg = '/var/lib/peadmin/.mcollective'
$webhook_default_branch = 'production'
$webhook_use_mco_ruby = false
$webhook_protected = true
$webhook_github_secret = undef
$webhook_gitlab_token = undef
$webhook_bitbucket_secret = undef
$webhook_discovery_timeout = 10
$webhook_client_timeout = 120
$webhook_prefix = false # ':repo' | ':user' | ':command' (or true for backwards compatibility) | 'string' | false
$webhook_prefix_command = '/bin/echo example'
$webhook_server_software = 'WebHook'
$webhook_enable_ssl = true
$webhook_use_mcollective = true
$webhook_r10k_deploy_arguments = '-pv'
$webhook_bin_template = 'r10k/webhook.bin.erb'
$webhook_yaml_template = 'r10k/webhook.yaml.erb'
$webhook_r10k_command_prefix = 'umask 0022;' # 'sudo' is the canonical example for this
$webhook_repository_events = undef
$webhook_enable_mutex_lock = false
$webhook_allow_uppercase = true # for backwards compatibility. Default to off on a major semver update.
$webhook_slack_webhook = undef
$webhook_slack_channel = undef
$webhook_slack_username = undef
$webhook_slack_proxy_url = undef
$webhook_slack_icon = undef
$webhook_rocketchat_webhook = undef
$webhook_rocketchat_channel = undef
$webhook_rocketchat_username = undef
$webhook_configfile_owner = 'root'
$webhook_configfile_group = $root_group
$webhook_configfile_mode = '0644'
$webhook_ignore_environments = []
$webhook_mco_arguments = undef
if $facts['pe_server_version'] == '2016.4.2' {
$webhook_sinatra_version = '~> 1.0'
} elsif versioncmp(fact('ruby.version'), '2.6.0') < 0 {
$webhook_sinatra_version = '~> 2.0'
} else {
$webhook_sinatra_version = 'installed'
}
$webhook_webrick_version = 'installed'
$webhook_generate_types = false

if $facts['os']['family'] == 'Gentoo' {
$webhook_service_file = '/etc/init.d/webhook'
$webhook_service_file_mode = '0755'
$webhook_background = true
} else {
$webhook_service_file = '/etc/systemd/system/webhook.service'
$webhook_service_file_mode = '0644'
$webhook_background = false
}
# Webhook Go parameters
$webhook_protected = true
$webhook_version = '2.0.1'
$webhook_user = 'puppet'
$webhook_password = 'puppet'
$webhook_port = 4000
$webhook_tls_enabled = false
$webhook_tls_cert = ''
$webhook_tls_key = ''
$webhook_chatops_enabled = false
$webhook_chatops_service = ''
$webhook_chatops_channel = ''
$webhook_chatops_user = ''
$webhook_chatops_token = ''
$webhook_chatops_uri = ''
$webhook_r10k_command_path = "/opt/puppetlabs/puppet/bin/${r10k_binary}"
$webhook_r10k_config_path = $r10k_config_file
$webhook_r10k_default_branch = 'production'
$webhook_r10k_branch_prefix = ''
$webhook_r10k_allow_uppercase = false
$webhook_r10k_verbose = true
$webhook_r10k_deploy_modules = true
$webhook_r10k_generate_types = true
$webhook_service_ensure = 'running'
$webhook_service_enabled = true
}
51 changes: 47 additions & 4 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,52 @@
#
#
class r10k::webhook (
Boolean $ensure = true,
String $user = $r10k::params::webhook_user,
String $password = $r10k::params::webhook_password,
Boolean $ensure = $r10k::params::webhook_ensure,
String $version = $r10k::params::webhook_version,
Variant[
Enum['running', 'stopped'],
Boolean
] $service_ensure = $r10k::params::webhook_service_ensure,
Boolean $service_enabled = $r10k::params::webhook_service_enabled,
String $config_ensure = 'file',
String $config_path = '/etc/voxpupuli/webhook.yml',
R10k::Webhook::Config::ChatOps $chatops = {
enabled => $r10k::params::webhook_chatops_enabled,
service => $r10k::params::webhook_chatops_service,
channel => $r10k::params::webhook_chatops_channel,
user => $r10k::params::webhook_chatops_user,
auth_token => $r10k::params::webhook_chatops_token,
server_uri => $r10k::params::webhook_chatops_uri,
},
R10k::Webhook::Config::Server::Tls $tls = {
enabled => $r10k::params::webhook_tls_enabled,
certificate => $r10k::params::webhook_tls_cert_path,
key => $r10k::params::webhook_tls_key_path,
},
R10k::Webhook::Config::Server $server = {
protected => $r10k::params::webhook_protected,
user => $r10k::params::webhook_user,
password => $r10k::params::webhook_password,
port => $r10k::params::webhook_port,
tls => $tls,
},
R10k::Webhook::Config::R10k $r10k_settings = {
command_path => $r10k::params::webhook_r10k_command_path,
config_path => $r10k::params::webhook_r10k_config_path,
default_branch => $r10k::params::webhook_r10k_default_branch,
prefix => $r10k::params::webhook_r10k_branch_prefix,
allow_uppercase => $r10k::params::webhook_r10k_allow_uppercase,
verbose => $r10k::params::webhook_r10k_verbose,
deploy_modules => $r10k::params::webhook_r10k_deploy_modules,
generate_types => $r10k::params::webhook_r10k_generate_types,
},
R10k::Webhook::Config $config = {
server => $server,
chatops => $chatops,
r10k => $r10k_settings,
},
) {
# resources
contain r10k::webhook::package
contain r10k::webhook::config
contain r10k::webhook::service
}
8 changes: 6 additions & 2 deletions manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#
#
class r10k::webhook::config (
R10k::Webhook::Config $config
) {
# resources
file { 'webhook.yml':
ensure => $r10k::webhook::config_ensure,
path => $r10k::webhook::config_path,
content => to_yaml($r10k::webhook::config),
notify => Service['webhook'],
}
}
14 changes: 6 additions & 8 deletions manifests/webhook/package.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Class: r10k::webhook::package
#
#
class r10k::webhook::package (
String $version = '2.0.1',
) {
case $facts['os']['name'] {
'RedHat', 'CentOS': {
class r10k::webhook::package () {
case $facts['os']['family'] {
'RedHat': {
$provider = 'rpm'
$package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${version}/webhook-go_${version}_linux_amd64.rpm"
$package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.rpm"
}
'Debian', 'Ubuntu': {
$provider = 'dpkg'
$package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${version}/webhook-go_${version}_linux_amd64.deb"
$package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.deb"
}
default: {
fail("Operating system ${facts['os']['name']} not supported for packages")
Expand All @@ -21,6 +19,6 @@
package { 'webhook-go':
ensure => 'present',
source => $package_url,
proviser => $provider,
provider => $provider,
}
}
5 changes: 3 additions & 2 deletions manifests/webhook/service.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Class: r10k::webhook::service
#
#
class r10k::webhook::service {
class r10k::webhook::service () {
service { 'webhook':
ensure => 'running',
ensure => $r10k::webhook::service_ensure,
enable => $r10k::webhook::service_enabled,
}
}
50 changes: 50 additions & 0 deletions spec/classes/webhook_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'r10k::webhook' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

let :params do
{
ensure: true,
version: '1.0.0',
service_ensure: 'running',
service_enabled: true,
config_ensure: 'file',
config_path: '/etc/voxpupuli/webhook.yml',
chatops: {
enabled: false,
},
tls: {
enabled: false,
},
server: {
protected: true,
user: 'puppet',
password: 'puppet',
port: 4000,
},
r10k_settings: {
command_path: '/opt/puppetlabs/puppet/bin/r10k',
config_path: '/etc/puppetlabs/r10k/r10k.yaml',
default_branch: 'production',
allow_uppercase: false,
verbose: true,
deploy_modules: true,
generate_types: true,
}
}
end
if os == 'archlinux-rolling-x86_64' || os == 'gentoo-2-x86_64'
it { is_expected.not_to compile }
else
it { is_expected.to compile }
end
end
end
end
2 changes: 1 addition & 1 deletion types/webhook/config/chatops.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type R10k::Webhook::Config::Chatops = Struct[{
enabled => Boolean,
service => Enum['slack', 'rocketchat'],
service => Optional[Enum['slack', 'rocketchat']],
channel => Optional[String[1]],
user => Optional[String[1]],
auth_token => Optional[String[1]],
Expand Down

0 comments on commit 48889b4

Please sign in to comment.