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

Commit

Permalink
Clean up configuration file options
Browse files Browse the repository at this point in the history
App and Server default configuration files are set to look at the
app root for pathing rather than a relative "../" location.

The logfile setting is defaulted to /var/log/puppet-webhook/access.log
  • Loading branch information
David Hollinger committed Nov 10, 2017
1 parent bc3c155 commit 72a8694
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions bin/puppet_webhook
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ require 'webrick'
require 'webrick/https'
require 'puppet_webhook'

confdir = File.join(__dir__, '..', 'config', 'server.yml')

if File.exist?('/etc/puppet-webhook/server.yml')
config_file '/etc/puppet-webhook/server.yml'
elsif File.exist?('../config/server.yml')
config_file '../config/server.yml'
elsif File.exist?(confdir)
config_file confdir
else
raise 'Can\'t find server.yml. No such file or directory'
raise "Can't find server.yml. No such file or directory\n"
end

PIDFILE = settings.pidfile
Expand Down
2 changes: 1 addition & 1 deletion config/server.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server_type: simple
logfile: '../logs/access.log'
logfile: /var/log/puppet-webhook/access.log
pidfile: /var/run/puppet-webhook/webhook.pid
lockfile: /var/run/puppet-webhook/webhook.lock
approot: './'
Expand Down
10 changes: 7 additions & 3 deletions lib/puppet_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
require 'parsers/webhook_json_parser'

class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
set :root, File.dirname(__FILE__)
use Rack::Parser,
parsers: { 'application/json' => Sinatra::Parsers::WebhookJsonParser.new },
handlers: { 'application/json' => proc { |e, type| [400, { 'Content-Type' => type }, [{ error: e.to_s }.to_json]] } }
register Sinatra::ConfigFile

app_conf = File.join(__dir__, '..', 'config', 'app.yml')
if File.exist?('/etc/puppet-webhook/app.yml')
config_file '/etc/puppet-webhook/app.yml'
elsif File.exist?('../config/app.yml')
config_file '../config/app.yml'
elsif File.exist?(app_conf)
config_file app_conf
else
raise 'Can\'t load app.yml: No such file or directory'
raise "Can't load app.yml: No such file or directory\n"
end

set :static, false
set :lock, true if settings.enable_mutex_lock

require 'helpers/init'

Expand Down

0 comments on commit 72a8694

Please sign in to comment.