This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from dhollinger/add_cli_binary
Add cli binary
- Loading branch information
Showing
7 changed files
with
128 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,97 @@ | ||
#!/usr/bin/env ruby | ||
require 'openssl' | ||
require 'sinatra' | ||
require 'sinatra/config_file' | ||
require 'optparse' | ||
require 'webrick' | ||
require 'webrick/https' | ||
require 'puppet_webhook' | ||
|
||
config_file(File.join(__dir__, '..', 'config', 'server.yml'), '/etc/puppet_webhook/server.yml') | ||
approot = File.expand_path(File.join(File.dirname(__FILE__), '..')) | ||
options = { | ||
host: '0.0.0.0', | ||
port: '8088', | ||
logfile: $stderr, | ||
loglevel: WEBrick::Log::WARN, | ||
server_type: WEBrick::SimpleServer | ||
} | ||
|
||
ssl_opts = { ssl_verify: false } | ||
|
||
optparse = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength | ||
opts.banner = 'Usage: puppet_webhook [-p <port>] [-l <logfile>] [-d] | ||
-- Starts the Puppet Webhook API service. | ||
' | ||
|
||
opts.on('-d', '--debug', 'Display or log messages.') do | ||
options[:loglevel] = WEBrick::Log::DEBUG | ||
end | ||
|
||
opts.on('-l [LOGFILE]', '--logfile [LOGFILE]', | ||
'Path to logfile. Defaults to no logging, or /var/log/puppet_webhook if no filename is passed.') do |arg| | ||
options[:logfile] = arg || '/var/log/puppet_webhook' | ||
end | ||
|
||
opts.on('-p PORT', '--port PORT', 'Port to listen on. Defaults to 8088.') do |arg| | ||
options[:port] = arg | ||
end | ||
|
||
opts.on('-D', '--daemon', 'Run the server in daemon mode. Defaults to simple if not passed') do | ||
options[:server_type] = WEBrick::Daemon | ||
end | ||
|
||
PIDFILE = settings.pidfile | ||
LOCKFILE = settings.lockfile | ||
APP_ROOT = settings.approot | ||
COMMAND_PREFIX = settings.command_prefix | ||
LOGGER = WEBrick::Log.new(settings.logfile, WEBrick::Log::DEBUG) | ||
opts.on('--pidfile FILE', 'Specify the PID file to use.') do |arg| | ||
options[:pidfile] = arg || '/var/run/puppet_webhook/webhook.pid' | ||
end | ||
|
||
case settings.server_type | ||
when 'simple' | ||
server_type = WEBrick::SimpleServer | ||
when 'daemon' | ||
server_type = WEBrick::Daemon | ||
opts.on('--ssl', 'Enable SSL Support.') do | ||
ssl_opts[:enable_ssl] = true | ||
end | ||
|
||
opts.on('--ssl-cert FILE', 'Specify the SSL cert to use. Pair with --ssl-key.') do |arg| | ||
ssl_opts[:ssl_cert] = OpenSSL::X509::Certificate.new(File.open(arg).read) | ||
end | ||
|
||
opts.on('--ssl-key FILE', 'Specify the SSL key to use. Pair with --ssl-cert.') do |arg| | ||
ssl_opts[:ssl_key] = OpenSSL::PKey::RSA.new(File.open(arg)) | ||
end | ||
|
||
opts.on('-c FILE', '--configfile FILE', 'Specifies a configuration file to use. Not functional yet.') do |arg| | ||
options[:config_file] = arg | ||
end | ||
|
||
opts.separator('') | ||
|
||
opts.on('-h', '--help') do | ||
puts | ||
puts opts | ||
puts | ||
exit | ||
end | ||
end | ||
|
||
opts = { | ||
Host: settings.bind_address, | ||
Port: settings.port, | ||
Logger: LOGGER, | ||
ServerType: server_type, | ||
ServerSoftware: settings.server_software, | ||
SSLEnable: settings.enable_ssl, | ||
StartCallBack: proc { File.open(PIDFILE, 'w') { |f| f.write Process.pid } } | ||
optparse.parse! | ||
|
||
# config_file(File.join(__dir__, '..', 'config', 'server.yml'), '/etc/puppet_webhook/server.yml', options[:config_file]) | ||
|
||
LOGGER = WEBrick::Log.new(options[:logfile], options[:loglevel]) | ||
|
||
webrick_opts = { | ||
Host: options[:host], | ||
Port: options[:port], | ||
DocumentRoot: approot, | ||
ServerType: options[:server_type], | ||
ServerSoftware: PuppetWebhook, | ||
StartCallBack: proc { File.open(options[:pidfile], 'w') { |f| f.write Process.pid } } | ||
} | ||
|
||
if settings.enable_ssl | ||
opts[:SSLVerifyClient] = settings.verify_ssl | ||
opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.open(settings.public_key_path).read) | ||
opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(File.open(settings.private_key_path).read) | ||
opts[:SSLCertName] = [['CN', WEBrick::Utils.getservername]] | ||
if ssl_opts[:enable_ssl] | ||
webrick_opts[:SSLEnable] = ssl_opts[:enable_ssl] | ||
webrick_opts[:SSLVerifyClient] = ssl_opts[:ssl_verify] | ||
webrick_opts[:SSLCertificate] = ssl_opts[:ssl_cert] | ||
webrick_opts[:SSLPrivateKey] = ssl_opts[:ssl_key] | ||
webrick_opts[:SSLCertName] = [['CN', WEBrick::Utils.getservername]] | ||
end | ||
|
||
Rack::Handler::WEBrick.run(PuppetWebhook, opts) do |server| | ||
Rack::Handler::WEBrick.run(PuppetWebhook, webrick_opts) do |server| | ||
%i[INT TERM].each { |sig| trap(sig) { server.stop } } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
enable_mutex_lock: false | ||
# Authentication | ||
protected: true | ||
user: puppet | ||
pass: puppet | ||
protected: true | ||
|
||
# Mcollective | ||
client_cfg: "/var/lib/peadmin/.mcollective" | ||
client_timeout: "120" | ||
use_mco_ruby: false | ||
use_mcollective: false | ||
discovery_timeout: '10' | ||
|
||
# Slack Notifications | ||
slack_webhook: false | ||
slack_channel: '#default' | ||
slack_username: 'r10k' | ||
slack_proxy_url: ~ | ||
|
||
# R10k | ||
default_branch: production | ||
discovery_timeout: '10' | ||
ignore_environments: [] | ||
prefix: ~ | ||
prefix_command: '' | ||
r10k_deploy_arguments: "-pv" | ||
allow_uppercase: true | ||
github_secret: ~ | ||
repository_events: ~ | ||
command_prefix: 'umask 0022;' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters