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(template_params) ⇒ Object
- #description ⇒ Object
- #display_password ⇒ Object
-
#initialize(attributes = {}) ⇒ WebhookRequestTemplate
constructor
A new instance of WebhookRequestTemplate.
- #redacted_headers ⇒ Object
- #to_s ⇒ 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.
23 24 25 26 27 28 29 30 31 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 23 def initialize attributes = {} @method = attributes[:method] @url = attributes[:url] @username = attributes[:username] @password = attributes[:password] @headers = Rack::Utils::HeaderHash.new(attributes[:headers] || {}) @body = attributes[:body] @uuid = attributes[:uuid] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def headers @headers end |
#method ⇒ Object Also known as: http_method
Returns the value of attribute method.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def method @method end |
#password ⇒ Object
Returns the value of attribute password.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def username @username end |
#uuid ⇒ Object
Returns the value of attribute uuid.
17 18 19 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17 def uuid @uuid end |
Instance Method Details
#build(template_params) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 33 def build(template_params) attributes = { method: http_method, url: build_url(template_params), headers: build_headers(template_params), username: build_string(username, template_params), password: build_string(password, template_params), uuid: uuid, body: build_body(template_params) } PactBroker::Domain::WebhookRequest.new(attributes) end |
#description ⇒ Object
46 47 48 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 46 def description "#{http_method.upcase} #{URI(PactBroker::Webhooks::Render.render_with_placeholder(url)).host}" end |
#display_password ⇒ Object
50 51 52 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 50 def display_password password.nil? ? nil : (PactBroker::Webhooks::Render.includes_parameter?(password) ? password : "**********") end |
#redacted_headers ⇒ Object
54 55 56 57 58 59 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 54 def redacted_headers headers.each_with_object({}) do | (name, value), new_headers | redact = HEADERS_TO_REDACT.any?{ | pattern | name =~ pattern } && !PactBroker::Webhooks::Render.includes_parameter?(value) new_headers[name] = redact ? "**********" : value end end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 66 def to_s "#{method.upcase} #{url}, username=#{username}, password=#{display_password}, headers=#{redacted_headers}, body=#{body}" end |