From 82f0702593287c8d7e4d419a571c04d1092a59ac Mon Sep 17 00:00:00 2001 From: David Hollinger III Date: Thu, 8 Jun 2023 11:09:33 -0500 Subject: [PATCH] update webhook code with some basic fixes * Add `inherits r10k::params` to the `r10k::webhook` class * Add a new `File` resource that will download the package file from Github before installing. * Update unit tests --- manifests/params.pp | 5 +++-- manifests/webhook.pp | 2 +- manifests/webhook/package.pp | 10 +++++++++- spec/classes/webhook_spec.rb | 27 +++++++++++++++++++-------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index ac406a71..20e06738 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -74,14 +74,15 @@ } # Webhook Go parameters + $webhook_ensure = false $webhook_protected = true $webhook_version = '2.1.0' $webhook_user = 'puppet' $webhook_password = 'puppet' $webhook_port = 4000 $webhook_tls_enabled = false - $webhook_tls_cert = '' - $webhook_tls_key = '' + $webhook_tls_cert_path = undef + $webhook_tls_key_path = undef $webhook_chatops_enabled = false $webhook_chatops_service = '' $webhook_chatops_channel = '' diff --git a/manifests/webhook.pp b/manifests/webhook.pp index ac3b66d7..7055ebd8 100644 --- a/manifests/webhook.pp +++ b/manifests/webhook.pp @@ -46,7 +46,7 @@ chatops => $chatops, r10k => $r10k, }, -) { +) inherits r10k::params { contain r10k::webhook::package contain r10k::webhook::config contain r10k::webhook::service diff --git a/manifests/webhook/package.pp b/manifests/webhook/package.pp index 7c2a9cce..76469140 100644 --- a/manifests/webhook/package.pp +++ b/manifests/webhook/package.pp @@ -5,10 +5,12 @@ case $facts['os']['family'] { 'RedHat': { $provider = 'rpm' + $pkg_file = '/tmp/webhook-go.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' + $pkg_file = '/tmp/webhook-go.deb' $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.deb" } default: { @@ -16,9 +18,15 @@ } } + file { $pkg_file: + ensure => file, + source => $package_url, + before => Package['webhook-go'], + } + package { 'webhook-go': ensure => 'present', - source => $package_url, + source => $pkg_file, provider => $provider, } } diff --git a/spec/classes/webhook_spec.rb b/spec/classes/webhook_spec.rb index 6cb005cb..420b2073 100644 --- a/spec/classes/webhook_spec.rb +++ b/spec/classes/webhook_spec.rb @@ -18,10 +18,12 @@ config_ensure: 'file', config_path: '/etc/voxpupuli/webhook.yml', chatops: { - enabled: false, - }, - tls: { - enabled: false, + enabled: true, + service: 'slack', + channel: '#channel', + user: 'root', + auth_token: 'ABCDEF123456789', + server_uri: 'https://webhook.slack.com/endpoint', }, server: { protected: true, @@ -29,8 +31,10 @@ password: 'puppet', port: 4000, tls: { - enabled: false, - } + enabled: true, + certificate: '/path/to/cert', + key: '/path/to/key', + }, }, r10k: { command_path: '/opt/puppetlabs/puppet/bin/r10k', @@ -51,9 +55,16 @@ password: puppet port: 4000 tls: - enabled: false + enabled: true + certificate: "/path/to/cert" + key: "/path/to/key" chatops: - enabled: false + enabled: true + service: slack + channel: "#channel" + user: root + auth_token: ABCDEF123456789 + server_uri: https://webhook.slack.com/endpoint r10k: command_path: "/opt/puppetlabs/puppet/bin/r10k" config_path: "/etc/puppetlabs/r10k/r10k.yaml"