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, #validation_message, #validation_message_at_index
Methods included from Logging
included, #log_error, #log_with_tag, #measure_info
Constructor Details
Returns a new instance of WebhookRequestTemplate.
23
24
25
26
27
28
29
|
# 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::Headers.new
@headers.merge!(attributes[:headers]) if 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
70
71
72
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 70
def body_string
String === body ? body : body&.to_json
end
|
#body_template_parameters(scope = nil) ⇒ Object
82
83
84
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 82
def body_template_parameters(scope = nil)
body_string.scan(parameter_pattern(scope)).flatten.uniq
end
|
#build(template_params, user_agent: nil, disable_ssl_verification: false, cert_store: nil) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 31
def build(template_params, user_agent: nil, disable_ssl_verification: false, cert_store: nil)
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,
disable_ssl_verification: disable_ssl_verification,
cert_store: cert_store
}
PactBroker::Domain::WebhookRequest.new(attributes)
end
|
#credentials_template_parameters(scope = nil) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 95
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
86
87
88
89
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 86
def (scope = nil)
pattern = parameter_pattern(scope)
.values.collect { |value| value.scan(pattern) }.flatten.uniq
end
|
55
56
57
58
59
60
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 55
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
78
79
80
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 78
def template_parameters(scope = nil)
body_template_parameters(scope) + url_template_parameters(scope) + (scope) + credentials_template_parameters(scope)
end
|
#to_s ⇒ Object
74
75
76
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 74
def to_s
"#{method.upcase} #{url}, username=#{username}, password=#{display_password}, headers=#{}, body=#{body}"
end
|
#url_template_parameters(scope = nil) ⇒ Object
91
92
93
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 91
def url_template_parameters(scope = nil)
url.scan(parameter_pattern(scope)).flatten.uniq
end
|
#uses_parameter?(parameter_name) ⇒ Boolean
66
67
68
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 66
def uses_parameter?(parameter_name)
!!body_string&.include?("${" + parameter_name + "}")
end
|