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
|
# 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
69
70
71
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 69
def body_string
String === body ? body : body&.to_json
end
|
#body_template_parameters(scope = nil) ⇒ Object
81
82
83
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 81
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 30
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
94
95
96
97
98
99
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 94
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
85
86
87
88
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 85
def (scope = nil)
pattern = parameter_pattern(scope)
.values.collect { |value| value.scan(pattern) }.flatten.uniq
end
|
54
55
56
57
58
59
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 54
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
77
78
79
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 77
def template_parameters(scope = nil)
body_template_parameters(scope) + url_template_parameters(scope) + (scope) + credentials_template_parameters(scope)
end
|
#to_s ⇒ Object
73
74
75
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 73
def to_s
"#{method.upcase} #{url}, username=#{username}, password=#{display_password}, headers=#{}, body=#{body}"
end
|
#url_template_parameters(scope = nil) ⇒ Object
90
91
92
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 90
def url_template_parameters(scope = nil)
url.scan(parameter_pattern(scope)).flatten.uniq
end
|
#uses_parameter?(parameter_name) ⇒ Boolean
65
66
67
|
# File 'lib/pact_broker/webhooks/webhook_request_template.rb', line 65
def uses_parameter?(parameter_name)
!!body_string&.include?("${" + parameter_name + "}")
end
|