Class: Chook::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Chook::Server
- Defined in:
- lib/chook/server.rb,
lib/chook/server/log.rb,
lib/chook/server/routes.rb,
lib/chook/server/routes/log.rb,
lib/chook/server/routes/home.rb,
lib/chook/server/routes/handlers.rb,
lib/chook/server/routes/handle_webhook_event.rb
Overview
see server.rb
Defined Under Namespace
Modules: Log
Constant Summary collapse
- DEFAULT_PORT =
80- DEFAULT_SSL_PORT =
443- DEFAULT_CONCURRENCY =
true
Class Method Summary collapse
-
.run!(log_level: nil) ⇒ Object
Run the server.
-
.webhooks_user_pw ⇒ Object
Learn the client password, if we’re using basic auth.
Class Method Details
.run!(log_level: nil) ⇒ Object
Run the server
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chook/server.rb', line 52 def self.run!(log_level: nil) log_level ||= Chook.config.log_level @log_level = Chook::Procs::STRING_TO_LOG_LEVEL.call log_level configure do set :logger, Log.startup(@log_level) set :server, :thin set :bind, '0.0.0.0' set :port, Chook.config.port set :show_exceptions, :after_handler if development? set :root, "#{File.dirname __FILE__}/server" enable :static enable :lock unless Chook.config.concurrency end # configure Chook::HandledEvent::Handlers.load_handlers if Chook.config.use_ssl super do |server| server.ssl = true server. = { cert_chain_file: Chook.config.ssl_cert_path.to_s, private_key_file: Chook.config.ssl_private_key_path.to_s, verify_peer: false } end # super do else super end # if use ssl end |
.webhooks_user_pw ⇒ Object
Learn the client password, if we’re using basic auth
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/chook/server.rb', line 85 def self.webhooks_user_pw return @webhooks_user_pw if @webhooks_user_pw return nil unless Chook.config.webhooks_user_pw setting = Chook.config.webhooks_user_pw @webhooks_user_pw = if setting.end_with? '|' # if the path ends with a pipe, its a command that will # return the desired password, so remove the pipe, # execute it, and return stdout from it. cmd = setting.chomp '|' output = `#{cmd} 2>&1`.chomp raise "Can't get webhooks user password: #{output}" unless $CHILD_STATUS.exitstatus.zero? output else # otherwise its a file path, and read the pw from the contents file = Pathname.new setting return nil unless file.file? stat = file.stat mode = format('%o', stat.mode) raise 'Password file for webhooks user has insecure mode, must be 0600.' unless mode.end_with?('0600') raise "Password file for webhooks user has insecure owner, must be owned by UID #{Process.euid}." unless stat.owned? # chomping an empty string removes all trailing \n's and \r\n's file.read.chomp('') end # if else end |