Module: SpiderGazelle::Spider::AppStore
- Defined in:
- lib/spider-gazelle/spider/app_store.rb
Constant Summary collapse
- PROTOCOLS =
['h2', 'http/1.1'].freeze
Class Method Summary collapse
-
.add(app, options) ⇒ Object
Add an already loaded application.
- .configure_tls(opts) ⇒ Object
-
.get(id) ⇒ Object
Get an app using the id directly.
-
.load(rackup, options) ⇒ Object
Load an app and assign it an ID.
-
.lookup(app) ⇒ Object
Lookup an application.
Class Method Details
.add(app, options) ⇒ Object
Add an already loaded application
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spider-gazelle/spider/app_store.rb', line 37 def self.add(app, ) @critical.synchronize { obj_id = app.object_id return if @loaded[obj_id] id = @apps.length tls = configure_tls() port = tls ? 443 : 80 val = [app, port.to_s, tls] @apps << val @loaded[obj_id] = val id } end |
.configure_tls(opts) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/spider-gazelle/spider/app_store.rb', line 65 def self.configure_tls(opts) return false unless opts[:tls] tls = { protocols: PROTOCOLS, fallback: 'http/1.1' } tls[:verify_peer] = true if opts[:verify_peer] tls[:ciphers] = opts[:ciphers] if opts[:ciphers] # NOTE:: Blocking reads however only during load so it's OK private_key = opts[:private_key] if private_key tls[:private_key] = ::FFI::MemoryPointer.from_string(File.read(private_key)) end cert_chain = opts[:cert_chain] if cert_chain tls[:cert_chain] = ::FFI::MemoryPointer.from_string(File.read(cert_chain)) end tls end |
.get(id) ⇒ Object
Get an app using the id directly
60 61 62 |
# File 'lib/spider-gazelle/spider/app_store.rb', line 60 def self.get(id) @apps[id.to_i] end |
.load(rackup, options) ⇒ Object
Load an app and assign it an ID
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spider-gazelle/spider/app_store.rb', line 14 def self.load(rackup, ) begin @critical.synchronize { return if @loaded[rackup] app, opts = ::Rack::Builder.parse_file(rackup) app = Rack::Lint.new(app) if [:lint] tls = configure_tls() port = tls ? 443 : 80 val = [app, port, tls] @apps << val @loaded[rackup] = val } rescue Exception => e # Prevent other threads from trying to load this too (might be in threaded mode) @loaded[rackup] = true @logger.print_error(e, "loading rackup #{rackup}") Reactor.instance.shutdown end end |
.lookup(app) ⇒ Object
Lookup an application
55 56 57 |
# File 'lib/spider-gazelle/spider/app_store.rb', line 55 def self.lookup(app) @loaded[app.to_s] end |