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

Clean up configuration code #18

Merged
merged 2 commits into from Nov 10, 2017
Merged

Conversation

dhollinger
Copy link
Member

Goal is to separate out the config into a server.yml and an app.yml and provide code that will look for default config in a common system location (/etc/puppet-webhook/<config_file>.yml) and if that is not found, then fall back to provided default config files.

@@ -6,7 +6,13 @@ require 'webrick'
require 'webrick/https'
require 'puppet_webhook'

config_file '../config.yml'
if File.exist?('/etc/puppet-webhook/server.yml')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like a command line argument which you can use to point it at.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add it as part of this PR or another one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR is fine.

@@ -9,10 +9,15 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
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
config_file '../config.yml'
if File.exist?('/etc/puppet-webhook/app.yml')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a CONFIG_DIR setting somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it provide us with anything useful?

Seems like it would just be another config option just to support the config files. Seems a bit redundant. Unless you mean to set it to one of [ static value, CLI passed arg ]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running from a git checkout might be easier, or as non-root user. FreeBSD has /usr/local/etc instead. There are some odd setups :)

verify_ssl: false
public_key_path: ''
private_key_path: ''
command_prefix: 'umask 0022;'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like line endings at the end of files

@dhollinger dhollinger changed the title WIP: Clean up configuration code Clean up configuration code Nov 10, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 32.959% when pulling 72a8694 on dhollinger:config_cleanup into 6d0943c on voxpupuli:master.

@@ -6,12 +6,14 @@ require 'webrick'
require 'webrick/https'
require 'puppet_webhook'

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confdir that's actually a file is a bit confusing.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 32.959% when pulling b2437ec on dhollinger:config_cleanup into 6d0943c on voxpupuli:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 32.959% when pulling 606242c on dhollinger:config_cleanup into 6d0943c on voxpupuli:master.

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
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 32.959% when pulling 4b5bdf4 on dhollinger:config_cleanup into 6d0943c on voxpupuli:master.

Copy link
Member

@binford2k binford2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except for one suggestion.

config_file '../config.yml'
server_conf = File.join(__dir__, '..', 'config', 'server.yml')

if File.exist?('/etc/puppet-webhook/server.yml')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with a conditional like this is it's all or nothing. To override a single setting, you have to override all. My preferred solution is to load the defaults first, then load & merge the custom config if it exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you on that. I'll have to look into and see if Sinatra::ConfigFile allows for merging of config from multiple files. Not sure it does.

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
config_file '../config.yml'

app_conf = File.join(__dir__, '..', 'config', 'app.yml')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, I'd prefer to load defaults, then merge overrides.

The config_file method from Sinatra::ConfigFile can take multiple
path parameters. With this in mind the default configuration path
is now the first parameter and the user defined configuration path
is the second argument. When loaded, if the second file contains a
key that was already in the first file, that key will be overwritten
with the value of the key from the second file. If the second file
does not exist, then only the first file will be loaded into the
settings.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 32.443% when pulling b94ea29 on dhollinger:config_cleanup into 6d0943c on voxpupuli:master.

@binford2k binford2k merged commit cfe06b0 into voxpupuli:master Nov 10, 2017
@dhollinger dhollinger deleted the config_cleanup branch November 10, 2017 22:11
@dhollinger dhollinger mentioned this pull request Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants