Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from alphagov/add-options-related-to-for-upgrade
Browse files Browse the repository at this point in the history
Add options to Gor
  • Loading branch information
surminus authored Jul 15, 2016
2 parents dcc3d2e + 9368ef6 commit aae0025
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2016-07-15 Release 0.3.1
- Support ability to pass in environment variables
- Support explicitly setting binary path

2016-07-12 Release 0.3.0
- Support command-line options which don't have values
- Support Puppet 3.8
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ exclude_paths = [
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths

task :default => [:test]

desc "Run syntax, lint, and spec tests."
task :test => [
:syntax,
Expand Down
2 changes: 2 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
class gor::config {
$args = $::gor::args
$envvars = $::gor::envvars
$binary_path = $::gor::binary_path

file { '/etc/init/gor.conf':
content => template('gor/etc/init/gor.conf.erb'),
Expand Down
11 changes: 11 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@
# Ensure parameter to pass to the service.
# Default: running
#
# [*envvars*]
# Environment variables to be passed into the upstart config. This could
# be used to turn on debugging options.
#
# [*binary_path*]
# Specify the location of the Gor binary.
#
class gor (
$args,
$package_ensure = present,
$service_ensure = running,
$envvars = {},
$binary_path = '/usr/bin/gor',
) {
validate_hash($args)
if empty($args) {
fail("${title}: args param is empty")
}

validate_hash($envvars)

anchor { 'gor::begin': } ->
class { 'gor::package': } ->
class { 'gor::config': } ~>
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gdsoperations-gor",
"version": "0.3.0",
"version": "0.3.1",
"author": "Government Digital Service",
"license": "MIT",
"summary": "Module to manage gor",
Expand Down
34 changes: 34 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,38 @@
end
end
end

describe '#envvars' do
context 'valid hash' do
let(:params) {{
:envvars => {
'GODEBUG' => 'netdns=go',
'FOO' => 'bar',
},
:args => {
'-output-http-header' => 'User-Agent: gor',
'-output-http' => 'http://staging',
'-input-raw' => ':80',
},
}}

it 'should configure gor with correct environment variables in place' do
is_expected.to contain_file(upstart_file).with_content(/^env GODEBUG=\'netdns=go\'\nenv FOO=\'bar\'$/)
end
end
context 'empty hash' do
let(:params) {{
:envvars => {},
:args => {
'-output-http-header' => 'User-Agent: gor',
'-output-http' => 'http://staging',
'-input-raw' => ':80',
},
}}

it 'should configure gor without setting environment variables' do
is_expected.not_to contain_file(upstart_file).with_content(/^env GODEBUG=\'netdns=go\'\nenv FOO=\'bar\'$/)
end
end
end
end
6 changes: 5 additions & 1 deletion templates/etc/init/gor.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ stop on runlevel [!2345]
respawn
respawn limit 5 20

exec /usr/bin/gor \
<% @envvars.each do |k, v| %>
<%= "env #{k}='#{v}'" -%>
<% end %>

exec <%= @binary_path %> \
<%=
@args.sort.map { |k,v|
[v].flatten.map { |i|
Expand Down

0 comments on commit aae0025

Please sign in to comment.