Class: PactBroker::Domain::WebhookRequest
- Inherits:
-
Object
- Object
- PactBroker::Domain::WebhookRequest
- Includes:
- Logging
- Defined in:
- lib/pact_broker/domain/webhook_request.rb
Constant Summary collapse
- HEADERS_TO_REDACT =
[/authorization/i, /token/i]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#cert_store ⇒ Object
Returns the value of attribute cert_store.
-
#disable_ssl_verification ⇒ Object
Returns the value of attribute disable_ssl_verification.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
(also: #http_method)
Returns the value of attribute method.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#username ⇒ Object
Returns the value of attribute username.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #description ⇒ Object
- #display_password ⇒ Object
- #execute ⇒ Object
- #http_request ⇒ Object
-
#initialize(attributes = {}) ⇒ WebhookRequest
constructor
A new instance of WebhookRequest.
- #redacted_headers ⇒ Object
Methods included from Logging
included, #log_error, #log_with_tag, #measure_info
Constructor Details
#initialize(attributes = {}) ⇒ WebhookRequest
Returns a new instance of WebhookRequest.
27 28 29 30 31 32 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 27 def initialize attributes = {} attributes.each do | (name, value) | instance_variable_set("@#{name}", value) if respond_to?(name) end @headers = attributes[:headers] || {} end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def body @body end |
#cert_store ⇒ Object
Returns the value of attribute cert_store.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def cert_store @cert_store end |
#disable_ssl_verification ⇒ Object
Returns the value of attribute disable_ssl_verification.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def disable_ssl_verification @disable_ssl_verification end |
#headers ⇒ Object
Returns the value of attribute headers.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def headers @headers end |
#method ⇒ Object Also known as: http_method
Returns the value of attribute method.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def method @method end |
#password ⇒ Object
Returns the value of attribute password.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def url @url end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def user_agent @user_agent end |
#username ⇒ Object
Returns the value of attribute username.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def username @username end |
#uuid ⇒ Object
Returns the value of attribute uuid.
21 22 23 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 21 def uuid @uuid end |
Instance Method Details
#description ⇒ Object
34 35 36 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 34 def description "#{method.upcase} #{URI(url).host}" end |
#display_password ⇒ Object
38 39 40 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 38 def display_password password.nil? ? nil : "**********" end |
#execute ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 49 def execute = PactBroker::BuildHttpOptions.call(uri, disable_ssl_verification: disable_ssl_verification, cert_store: cert_store).merge(read_timeout: 15, open_timeout: 15) req = http_request Net::HTTP.start(uri.hostname, uri.port, :ENV, ) do |http| http.request req end end |
#http_request ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 57 def http_request @http_request ||= begin req = Net::HTTP.const_get(method.capitalize).new(uri.request_uri) req.delete("accept-encoding") req["user-agent"] = user_agent headers.each_pair { | name, value | req[name] = value } req.basic_auth(username, password) if username && username.size > 0 req.body = body unless body.nil? req end end |
#redacted_headers ⇒ Object
42 43 44 45 46 47 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 42 def redacted_headers headers.each_with_object({}) do | (name, value), new_headers | redact = HEADERS_TO_REDACT.any?{ | pattern | name =~ pattern } new_headers[name] = redact ? "**********" : value end end |