Skip to content

Commit 4ecbc4a

Browse files
committed
webhook: make blocked_branches options configureable
1 parent 5c81edb commit 4ecbc4a

File tree

5 files changed

+74
-36
lines changed

5 files changed

+74
-36
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ class { 'r10k::webhook':
586586
### Ignore deploying some environments
587587

588588
Since [2.10.0](https://github.com/voxpupuli/webhook-go/releases/tag/v2.10.0) the webhook has support for ignoring certain branches.
589-
This is not yet configureable via the puppet module.
589+
When a deployment is triggered for that branch, it will return am HTTP 403 error code.
590+
You can configure an array of branches via `r10k::webhook::blocked_branches`.
590591

591592
### configuring the webservice/deploy user
592593

REFERENCE.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ The following parameters are available in the `r10k::webhook` class:
533533
* [`service_enabled`](#-r10k--webhook--service_enabled)
534534
* [`config_ensure`](#-r10k--webhook--config_ensure)
535535
* [`config_path`](#-r10k--webhook--config_path)
536+
* [`blocked_branches`](#-r10k--webhook--blocked_branches)
536537
* [`chatops`](#-r10k--webhook--chatops)
537538
* [`tls`](#-r10k--webhook--tls)
538539
* [`queue`](#-r10k--webhook--queue)
@@ -611,6 +612,14 @@ Data type: `String`
611612

612613
Default value: `'/etc/voxpupuli/webhook.yml'`
613614

615+
##### <a name="-r10k--webhook--blocked_branches"></a>`blocked_branches`
616+
617+
Data type: `Array[String[1]]`
618+
619+
array of branches that the webhook will not deploy
620+
621+
Default value: `[]`
622+
614623
##### <a name="-r10k--webhook--chatops"></a>`chatops`
615624

616625
Data type: `R10k::Webhook::Config::ChatOps`
@@ -691,14 +700,15 @@ Default value:
691700

692701
```puppet
693702
{
694-
command_path => '/opt/puppetlabs/puppet/bin/r10k',
695-
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
696-
default_branch => 'production',
697-
prefix => undef,
698-
allow_uppercase => false,
699-
verbose => true,
700-
deploy_modules => true,
701-
generate_types => true,
703+
command_path => '/opt/puppetlabs/puppet/bin/r10k',
704+
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
705+
default_branch => 'production',
706+
prefix => undef,
707+
allow_uppercase => false,
708+
verbose => true,
709+
deploy_modules => true,
710+
generate_types => true,
711+
blocked_branches => $blocked_branches,
702712
}
703713
```
704714

@@ -771,14 +781,15 @@ Alias of
771781

772782
```puppet
773783
Struct[{
774-
command_path => Optional[Stdlib::Absolutepath],
775-
config_path => Optional[Stdlib::Absolutepath],
776-
default_branch => Optional[String[1]],
777-
prefix => Optional[String[1]],
778-
allow_uppercase => Optional[Boolean],
779-
verbose => Optional[Boolean],
780-
deploy_modules => Optional[Boolean],
781-
generate_types => Optional[Boolean],
784+
command_path => Optional[Stdlib::Absolutepath],
785+
config_path => Optional[Stdlib::Absolutepath],
786+
default_branch => Optional[String[1]],
787+
prefix => Optional[String[1]],
788+
allow_uppercase => Optional[Boolean],
789+
verbose => Optional[Boolean],
790+
deploy_modules => Optional[Boolean],
791+
generate_types => Optional[Boolean],
792+
blocked_branches => Optional[Array[String[1]]],
782793
}]
783794
```
784795

manifests/webhook.pp

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# @param service_enabled
1010
# @param config_ensure
1111
# @param config_path
12+
# @param blocked_branches array of branches that the webhook will not deploy
1213
# @param chatops
1314
# @param tls
1415
# @param queue
@@ -28,6 +29,7 @@
2829
Boolean $service_enabled = true,
2930
String $config_ensure = 'file',
3031
String $config_path = '/etc/voxpupuli/webhook.yml',
32+
Array[String[1]] $blocked_branches = [],
3133
R10k::Webhook::Config::ChatOps $chatops = {
3234
enabled => false,
3335
service => undef,
@@ -55,14 +57,15 @@
5557
queue => $queue,
5658
},
5759
R10k::Webhook::Config::R10k $r10k = {
58-
command_path => '/opt/puppetlabs/puppet/bin/r10k',
59-
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
60-
default_branch => 'production',
61-
prefix => undef,
62-
allow_uppercase => false,
63-
verbose => true,
64-
deploy_modules => true,
65-
generate_types => true,
60+
command_path => '/opt/puppetlabs/puppet/bin/r10k',
61+
config_path => '/etc/puppetlabs/r10k/r10k.yaml',
62+
default_branch => 'production',
63+
prefix => undef,
64+
allow_uppercase => false,
65+
verbose => true,
66+
deploy_modules => true,
67+
generate_types => true,
68+
blocked_branches => $blocked_branches,
6669
},
6770
R10k::Webhook::Config $config = {
6871
server => $server,

spec/acceptance/r10k_webhook_spec.rb

+25-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class { 'r10k': }
5454
end
5555
end
5656

57-
describe package('webhook-go') do
58-
it { is_expected.to be_installed }
57+
describe command('systemctl cat webhook-go') do
58+
its(:stdout) { is_expected.to match(%r{User=puppet}) }
5959
end
6060

6161
describe file('/etc/voxpupuli/webhook.yml') do
@@ -65,14 +65,36 @@ class { 'r10k': }
6565
expect(subject).to be_grouped_into 'root'
6666
end
6767
end
68+
end
69+
70+
context 'with blocked_branches' do
71+
it_behaves_like 'an idempotent resource' do
72+
let(:manifest) do
73+
<<-PUPPET
74+
class { 'r10k': }
75+
-> class { 'r10k::webhook':
76+
blocked_branches => ['production'],
77+
}
78+
PUPPET
79+
end
80+
end
6881

6982
describe service('webhook-go') do
7083
it { is_expected.to be_enabled }
7184
it { is_expected.to be_running }
7285
end
7386

7487
describe command('systemctl cat webhook-go') do
75-
its(:stdout) { is_expected.to match(%r{User=puppet}) }
88+
its(:stdout) { is_expected.not_to match(%r{User=puppet}) }
89+
end
90+
91+
describe file('/etc/voxpupuli/webhook.yml') do
92+
it 'exists and has content' do
93+
expect(subject).to exist
94+
expect(subject).to be_owned_by 'root'
95+
expect(subject).to be_grouped_into 'root'
96+
expect(subject).to contain "---\nserver:\n protected: true\n user: puppet\n password: puppet\n blocked_branches: ['production']\n"
97+
end
7698
end
7799
end
78100
end

types/webhook/config/r10k.pp

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# @summary webhook config r10k type
22
type R10k::Webhook::Config::R10k = Struct[{
3-
command_path => Optional[Stdlib::Absolutepath],
4-
config_path => Optional[Stdlib::Absolutepath],
5-
default_branch => Optional[String[1]],
6-
prefix => Optional[String[1]],
7-
allow_uppercase => Optional[Boolean],
8-
verbose => Optional[Boolean],
9-
deploy_modules => Optional[Boolean],
10-
generate_types => Optional[Boolean],
3+
command_path => Optional[Stdlib::Absolutepath],
4+
config_path => Optional[Stdlib::Absolutepath],
5+
default_branch => Optional[String[1]],
6+
prefix => Optional[String[1]],
7+
allow_uppercase => Optional[Boolean],
8+
verbose => Optional[Boolean],
9+
deploy_modules => Optional[Boolean],
10+
generate_types => Optional[Boolean],
11+
blocked_branches => Optional[Array[String[1]]],
1112
}]

0 commit comments

Comments
 (0)