Class: PactBroker::Webhooks::WebhookRequestTemplate
- Inherits:
-
Object
- Object
- PactBroker::Webhooks::WebhookRequestTemplate
- Defined in:
- lib/pact_broker/webhooks/webhook_request_template.rb
Constant Summary collapse
- HEADERS_TO_REDACT =
[/authorization/i, /token/i]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#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.
-
#username ⇒ Object
Returns the value of attribute username.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #build(context) ⇒ Object
- #build_body(pact, verification) ⇒ Object
- #build_url(pact, verification) ⇒ Object
- #description ⇒ Object
- #display_password ⇒ Object
-
#initialize(attributes = {}) ⇒ WebhookRequestTemplate
constructor
A new instance of WebhookRequestTemplate.
- #redacted_headers ⇒ Object
Methods included from Messages
#message, #potential_duplicate_pacticipant_message, #validation_message
Methods included from Logging
Constructor Details
#initialize(attributes = {}) ⇒ WebhookRequestTemplate
Returns a new instance of WebhookRequestTemplate.
20 21 22 23 24 25 26 27 28 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 20 def initialize attributes = {} @method = attributes[:method] @url = attributes[:url] @username = attributes[:username] @password = attributes[:password] @headers = attributes[:headers] || {} @body = attributes[:body] @uuid = attributes[:uuid] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def headers @headers end |
#method ⇒ Object Also known as: http_method
Returns the value of attribute method.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def method @method end |
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def username @username end |
#uuid ⇒ Object
Returns the value of attribute uuid.
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 14 def uuid @uuid end |
Instance Method Details
#build(context) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 30 def build(context) attributes = { method: http_method, url: build_url(context[:pact], context[:verification]), headers: headers, username: username, password: password, uuid: uuid, body: build_body(context[:pact], context[:verification]) } PactBroker::Domain::WebhookRequest.new(attributes) end |
#build_body(pact, verification) ⇒ Object
47 48 49 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 47 def build_body(pact, verification) PactBroker::Webhooks::Render.call(String === body ? body : body.to_json, pact, verification) end |
#build_url(pact, verification) ⇒ Object
43 44 45 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 43 def build_url(pact, verification) URI(PactBroker::Webhooks::Render.call(url, pact, verification){ | value | CGI::escape(value) if !value.nil? } ).to_s end |
#description ⇒ Object
51 52 53 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 51 def description "#{http_method.upcase} #{URI(url.gsub(PactBroker::Webhooks::Render::TEMPLATE_PARAMETER_REGEXP, 'placeholder')).host}" end |
#display_password ⇒ Object
55 56 57 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 55 def display_password password.nil? ? nil : "**********" end |
#redacted_headers ⇒ Object
59 60 61 62 63 64 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 59 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 |