Class: Runner::Base
- Inherits:
-
Object
- Object
- Runner::Base
- Defined in:
- lib/shared_infrastructure/runner/base.rb
Overview
Basic runner for nginx config file generation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#builder_class ⇒ Object
readonly
Returns the value of attribute builder_class.
Instance Method Summary collapse
- #main ⇒ Object
- #options_for_config(options) ⇒ Object
- #process_args(opts = nil) ⇒ Object
- #process_options(http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) ⇒ Object
- #protocol_factory(options, http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) ⇒ Object
Instance Attribute Details
#builder_class ⇒ Object (readonly)
Returns the value of attribute builder_class.
100 101 102 |
# File 'lib/shared_infrastructure/runner/base.rb', line 100 def builder_class @builder_class end |
Instance Method Details
#main ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/shared_infrastructure/runner/base.rb', line 14 def main = puts "options: #{.inspect}" if Runner.debug Nginx.prepare_fake_files([:domain_name], [:certificate_domain]) if Nginx.root? @builder_class = protocol_factory() puts "builder_class: #{builder_class.inspect}" if Runner.debug builder_class end |
#options_for_config(options) ⇒ Object
26 27 28 |
# File 'lib/shared_infrastructure/runner/base.rb', line 26 def () .select { |k, _v| k == :user } end |
#process_args(opts = nil) ⇒ Object
30 31 32 33 |
# File 'lib/shared_infrastructure/runner/base.rb', line 30 def process_args(opts = nil) raise MissingArgument.new("domain required", opts) if ARGV.size == 0 { domain_name: ARGV } end |
#process_options(http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/shared_infrastructure/runner/base.rb', line 35 def (http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) = {} opts = OptionParser.new do |opts| opts. = "Usage: [options]" # FIXME: This is only applicable to Rails apps. opts.on("-a LOCATION", "--accel LOCATION", "Location below application root to serve when app responds with 'X-Accel'") do |accel_location| [:accel_location] = accel_location end opts.on("-c DOMAIN", "--certificate-domain DOMAIN", "Use the certificate for DOMAIN.") do |certificate_domain| [:certificate_domain] = certificate_domain end opts.on("-d", "--debug", "Print debugging information.") do [:debug] = true Runner.debug = true end opts.on("-d RAILS_ENV", "--rails-env RAILS_ENV", "Build files for the specified RAILS_ENV") do |rails_env| [:rails_env] = rails_env end opts.on("-P PROTOCOL", "--protocol PROTOCOL", "HTTP|HTTPS. Default: HTTPS if key files exist, else HTTP.") do |protocol| [:protocol] = case protocol.upcase when "HTTP" http_builder_class when "HTTPS" https_builder_class else opts.abort opts.help end end opts.on("-r DIRECTORY", "--root DIRECTORY", "DIRECTORY. Set a root for files. This options is for debugging.") do |directory| Nginx.chroot(directory) SharedInfrastructure::Output.fake_root(directory) end opts.on("-u USER", "--user USER", "User to be the owner of certain files. Default: the current user.") do |user| [:user] = user end opts.on("--dhparam KEYSIZE", "KEYSIZE. Default: 2048 should be used. This option is for testing.") do |keysize| Nginx.dhparam = keysize end .merge! yield opts if block_given? end opts.parse! .merge!(process_args(opts)) end |
#protocol_factory(options, http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/shared_infrastructure/runner/base.rb', line 102 def protocol_factory(, http_builder_class = Nginx::Builder::SiteHttp, https_builder_class = Nginx::Builder::SiteHttps) if [:protocol] [:protocol] else certificate_directory = Nginx.certificate_directory( [:certificate_domain] || [:domain_name].first # FIXME: ) if File.exist?(File.join(certificate_directory, "privkey.pem")) && File.exist?(File.join(certificate_directory, "fullchain.pem")) && File.exist?(File.join(certificate_directory, "chain.pem")) && File.exist?(File.join(certificate_directory, "cert.pem")) https_builder_class else http_builder_class end end end |