Class: PactBroker::Domain::WebhookRequest

Inherits:
Object
  • Object
show all
Includes:
Logging, Messages
Defined in:
lib/pact_broker/domain/webhook_request.rb

Constant Summary collapse

HEADERS_TO_REDACT =
[/authorization/i, /token/i]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Messages

#message, #potential_duplicate_pacticipant_message, #validation_message

Methods included from Logging

included

Constructor Details

#initialize(attributes = {}) ⇒ WebhookRequest

Returns a new instance of WebhookRequest.



66
67
68
69
70
71
72
73
74
# File 'lib/pact_broker/domain/webhook_request.rb', line 66

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

#bodyObject

Returns the value of attribute body.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def body
  @body
end

#headersObject

Returns the value of attribute headers.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def headers
  @headers
end

#methodObject Also known as: http_method

Returns the value of attribute method.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def method
  @method
end

#passwordObject

Returns the value of attribute password.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def password
  @password
end

#urlObject

Returns the value of attribute url.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def url
  @url
end

#usernameObject

Returns the value of attribute username.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



60
61
62
# File 'lib/pact_broker/domain/webhook_request.rb', line 60

def uuid
  @uuid
end

Instance Method Details

#descriptionObject



76
77
78
# File 'lib/pact_broker/domain/webhook_request.rb', line 76

def description
  "#{method.upcase} #{URI(url).host}"
end

#display_passwordObject



80
81
82
# File 'lib/pact_broker/domain/webhook_request.rb', line 80

def display_password
  password.nil? ? nil : "**********"
end

#execute(options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/pact_broker/domain/webhook_request.rb', line 91

def execute options = {}
  @options = options
  @logs = StringIO.new
  @execution_logger = Logger.new(logs)
  begin
    execute_and_build_result
  rescue StandardError => e
    handle_error_and_build_result(e)
  end
end

#redacted_headersObject



84
85
86
87
88
89
# File 'lib/pact_broker/domain/webhook_request.rb', line 84

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