Class: PactBroker::Webhooks::WebhookRequestTemplate
- Inherits:
-
Object
- Object
- PactBroker::Webhooks::WebhookRequestTemplate
show all
- Includes:
- Logging, Messages
- Defined in:
- lib/pact_broker/webhooks/webhook_request_template.rb
Constant Summary
collapse
[/authorization/i, /token/i]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Messages
#message, #pluralize, #potential_duplicate_pacticipant_message, #validation_message
Methods included from Logging
included, #log_error, #log_with_tag
Constructor Details
Returns a new instance of WebhookRequestTemplate.
23
24
25
26
27
28
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 23
def initialize attributes = {}
attributes.each do | (name, value) |
instance_variable_set("@#{name}", value) if respond_to?(name)
end
@headers = Rack::Utils::HeaderHash.new(attributes[:headers] || {})
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def body
@body
end
|
Returns the value of attribute headers.
17
18
19
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 17
def
@headers
end
|
#method ⇒ Object
Also known as:
http_method
Returns the value of attribute method.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def method
@method
end
|
#password ⇒ Object
Returns the value of attribute password.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def password
@password
end
|
#url ⇒ Object
Returns the value of attribute url.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def url
@url
end
|
#username ⇒ Object
Returns the value of attribute username.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def username
@username
end
|
#uuid ⇒ Object
Returns the value of attribute uuid.
16
17
18
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 16
def uuid
@uuid
end
|
Instance Method Details
#body_string ⇒ Object
67
68
69
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 67
def body_string
String === body ? body : body&.to_json
end
|
#body_template_parameters(scope = nil) ⇒ Object
79
80
81
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 79
def body_template_parameters(scope = nil)
body_string.scan(parameter_pattern(scope)).flatten.uniq
end
|
#build(template_params, user_agent) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 30
def build(template_params, user_agent)
attributes = {
method: http_method,
url: build_url(template_params),
headers: (template_params),
username: build_string(username, template_params),
password: build_string(password, template_params),
uuid: uuid,
body: build_body(template_params),
user_agent: user_agent
}
PactBroker::Domain::WebhookRequest.new(attributes)
end
|
#credentials_template_parameters(scope = nil) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 92
def credentials_template_parameters(scope = nil)
pattern = parameter_pattern(scope)
[username, password].compact.collect do | credential |
credential.scan(pattern)
end.flatten.uniq
end
|
#display_password ⇒ Object
83
84
85
86
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 83
def (scope = nil)
pattern = parameter_pattern(scope)
.values.collect { |value| value.scan(pattern) }.flatten.uniq
end
|
52
53
54
55
56
57
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 52
def
.each_with_object({}) do | (name, value), |
redact = HEADERS_TO_REDACT.any?{ | pattern | name =~ pattern } && !PactBroker::Webhooks::Render.includes_parameter?(value)
[name] = redact ? "**********" : value
end
end
|
#template_parameters(scope = nil) ⇒ Object
75
76
77
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 75
def template_parameters(scope = nil)
body_template_parameters(scope) + url_template_parameters(scope) + (scope) + credentials_template_parameters(scope)
end
|
#to_s ⇒ Object
71
72
73
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 71
def to_s
"#{method.upcase} #{url}, username=#{username}, password=#{display_password}, headers=#{}, body=#{body}"
end
|
#url_template_parameters(scope = nil) ⇒ Object
88
89
90
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 88
def url_template_parameters(scope = nil)
url.scan(parameter_pattern(scope)).flatten.uniq
end
|
#uses_parameter?(parameter_name) ⇒ Boolean
63
64
65
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 63
def uses_parameter?(parameter_name)
!!body_string&.include?("${" + parameter_name + "}")
end
|