-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix auth on outgoing webhook delivery. Add logic monitor outgoing event
- Loading branch information
Showing
9 changed files
with
350 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,35 +31,7 @@ def deliver_later | |
def deliver | ||
run_callbacks :deliver do | ||
begin | ||
hook_relay_options = { | ||
headers: { | ||
HR_TARGET_URL: url | ||
} | ||
} | ||
|
||
pagertree_options = { | ||
headers: { | ||
Accept: "*/*", | ||
"User-Agent": "pagertree outgoing webhook service; ref: #{resource&.id}; report: [email protected]", | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
|
||
auth_options = {} | ||
if auth.is_a?(Hash) && (username = auth.dig(:username)).present? && (password = auth.dig(:password)).present? | ||
auth_options = { | ||
headers: { | ||
Authorization: Base64.strict_encode64("#{username}:#{password}") | ||
} | ||
} | ||
end | ||
|
||
options = OutgoingWebhookDelivery::HTTP_OPTIONS | ||
.deep_merge(hook_relay_options) | ||
.deep_merge(pagertree_options) | ||
.deep_merge(auth_options) | ||
|
||
response = HTTParty.post(hook_relay_hook_url, body: body.to_json, **options) | ||
response = HTTParty.post(hook_relay_hook_url, body: body.to_json, **httparty_opts) | ||
|
||
self.thirdparty_id = response["id"] | ||
self.status = :sent | ||
|
@@ -71,19 +43,53 @@ def deliver | |
end # run_callbacks | ||
end | ||
|
||
def httparty_opts | ||
hook_relay_options = { | ||
headers: { | ||
"HR_TARGET_URL" => url | ||
} | ||
} | ||
|
||
pagertree_options = { | ||
headers: { | ||
"Accept" => "*/*", | ||
"User-Agent" => "pagertree outgoing webhook service; ref: #{resource&.id}; report: [email protected]", | ||
"Content-Type" => "application/json" | ||
} | ||
} | ||
|
||
auth_options = {} | ||
if auth.is_a?(Hash) | ||
auth_indifferent = auth.with_indifferent_access | ||
if (username = auth_indifferent.dig(:username)).present? && (password = auth_indifferent.dig(:password)).present? | ||
auth_options = { | ||
headers: { | ||
"Authorization" => Base64.strict_encode64("#{username}:#{password}") | ||
} | ||
} | ||
end | ||
end | ||
|
||
OutgoingWebhookDelivery::HTTP_OPTIONS | ||
.deep_merge(hook_relay_options) | ||
.deep_merge(pagertree_options) | ||
.deep_merge(auth_options) | ||
.deep_merge((options&.symbolize_keys || {})) | ||
end | ||
|
||
def delivery | ||
return @delivery if @delivery | ||
return {} unless thirdparty_id | ||
|
||
options = { | ||
opts = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer #{OutgoingWebhookDelivery::HookRelay.hook_relay_api_key}" | ||
"Content-Type" => "application/json", | ||
"Authorization" => "Bearer #{OutgoingWebhookDelivery::HookRelay.hook_relay_api_key}" | ||
}, | ||
timeout: 15 | ||
} | ||
|
||
response = ::HTTParty.get(hook_relay_delivery_url, **options) | ||
response = ::HTTParty.get(hook_relay_delivery_url, **opts) | ||
@delivery = response.parsed_response if response.success? | ||
|
||
@delivery || {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4"> | ||
<div class="form-group group"> | ||
<%= form.label :option_logic_monitor_account_name %> | ||
<%= form.text_field :option_logic_monitor_account_name, class: "form-control" %> | ||
<p class="form-hint"><%== t(".option_logic_monitor_account_name_hint_html") %></p> | ||
</div> | ||
|
||
<div class="form-group group"> | ||
<%= form.label :option_access_id %> | ||
<%= form.text_field :option_access_id, class: "form-control" %> | ||
<p class="form-hint"><%== t(".option_access_id_hint_html") %></p> | ||
</div> | ||
|
||
<div class="form-group group"> | ||
<%= form.label :option_access_key %> | ||
<%= form.text_field :option_access_key, class: "form-control" %> | ||
<p class="form-hint"><%== t(".option_access_key_hint_html") %></p> | ||
</div> | ||
|
||
<div class="form-group group"> | ||
<%= form.check_box :option_alert_acknowledged, class: "form-checkbox" %> | ||
<%= form.label :option_alert_acknowledged, class: "inline-block" %> | ||
<p class="form-hint md:inline-block"><%== t(".option_alert_acknowledged_hint_html") %></p> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<div class="sm:col-span-1"> | ||
<dt class="text-sm font-medium text-gray-500"> | ||
<%= t("activerecord.attributes.pager_tree/integrations/logic_monitor/v3.option_alert_acknowledged") %> | ||
</dt> | ||
<dd class="mt-1 text-sm text-gray-900"> | ||
<%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_alert_acknowledged } %> | ||
</dd> | ||
</div> | ||
|
||
<div class="sm:col-span-1"> | ||
<dt class="text-sm font-medium text-gray-500"> | ||
<%= t("activerecord.attributes.pager_tree/integrations/logic_monitor/v3.option_logic_monitor_account_name") %> | ||
</dt> | ||
<dd class="mt-1 text-sm text-gray-900"> | ||
<div class="flex items-center gap-2"> | ||
<p class="text-sm truncate"> | ||
<%= integration.option_logic_monitor_account_name %> | ||
</p> | ||
</div> | ||
</dd> | ||
</div> | ||
|
||
<div class="sm:col-span-1"> | ||
<dt class="text-sm font-medium text-gray-500"> | ||
<%= t("activerecord.attributes.pager_tree/integrations/logic_monitor/v3.option_access_id") %> | ||
</dt> | ||
<dd class="mt-1 text-sm text-gray-900"> | ||
<div class="flex items-center gap-2"> | ||
<p class="text-sm truncate"> | ||
<%= mask integration.option_access_id %> | ||
</p> | ||
</div> | ||
</dd> | ||
</div> | ||
|
||
<div class="sm:col-span-1"> | ||
<dt class="text-sm font-medium text-gray-500"> | ||
<%= t("activerecord.attributes.pager_tree/integrations/logic_monitor/v3.option_access_key") %> | ||
</dt> | ||
<dd class="mt-1 text-sm text-gray-900"> | ||
<div class="flex items-center gap-2"> | ||
<p class="text-sm truncate"> | ||
<%= mask integration.option_access_key %> | ||
</p> | ||
</div> | ||
</dd> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.