Class: Pact::V2::Provider::PactBrokerProxyRunner
- Inherits:
-
Object
- Object
- Pact::V2::Provider::PactBrokerProxyRunner
- Defined in:
- lib/pact/v2/provider/pact_broker_proxy_runner.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(pact_broker_host:, port: 9002, host: "127.0.0.1", pact_broker_user: nil, pact_broker_password: nil, pact_broker_token: nil, logger: nil) ⇒ PactBrokerProxyRunner
constructor
A new instance of PactBrokerProxyRunner.
- #proxy_url ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(pact_broker_host:, port: 9002, host: "127.0.0.1", pact_broker_user: nil, pact_broker_password: nil, pact_broker_token: nil, logger: nil) ⇒ PactBrokerProxyRunner
Returns a new instance of PactBrokerProxyRunner.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 12 def initialize(pact_broker_host:, port: 9002, host: "127.0.0.1", pact_broker_user: nil, pact_broker_password: nil, pact_broker_token: nil, logger: nil) @host = host @port = port @pact_broker_host = pact_broker_host @pact_broker_user = pact_broker_user @pact_broker_password = pact_broker_password @pact_broker_token = pact_broker_token @logger = logger || Logger.new($stdout) @thread = nil end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 9 def logger @logger end |
Instance Method Details
#proxy_url ⇒ Object
24 25 26 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 24 def proxy_url "http://#{@host}:#{@port}" end |
#run ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 64 def run start yield rescue => e logger.fatal("FATAL ERROR: #{e.} #{e.backtrace.join("\n")}") raise ensure stop end |
#start ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 28 def start raise "server already running, stop server before starting new one" if @thread # Rack 2/3 compatibility begin require 'rack/handler/webrick' handler = ::Rack::Handler::WEBrick rescue LoadError require 'rackup/handler/webrick' handler = Class.new(Rackup::Handler::WEBrick) end @server = WEBrick::HTTPServer.new({BindAddress: @host, Port: @port}, WEBrick::Config::HTTP) @server.mount("/", handler, PactBrokerProxy.new( nil, backend: @pact_broker_host, streaming: false, username: @pact_broker_user || nil, password: @pact_broker_password || nil, token: @pact_broker_token || nil, logger: @logger )) @thread = Thread.new do @logger.debug "starting pact broker proxy server" @server.start end end |
#stop ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/pact/v2/provider/pact_broker_proxy_runner.rb', line 55 def stop @logger.info("stopping pact broker proxy server") @server&.shutdown @thread&.join @logger.info("pact broker proxy server stopped") end |