2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class WebHook < ActiveRecord::Base
|
2015-04-26 12:48:37 +05:30
|
|
|
include Sortable
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
attr_encrypted :token,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
2019-02-15 15:39:39 +05:30
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
attr_encrypted :url,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
2019-02-15 15:39:39 +05:30
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
has_many :web_hook_logs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
validates :url, presence: true, public_url: { allow_localhost: lambda(&:allow_local_requests?),
|
|
|
|
allow_local_network: lambda(&:allow_local_requests?) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
validates :token, format: { without: /\n/ }
|
2018-11-20 20:47:30 +05:30
|
|
|
validates :push_events_branch_filter, branch_filter: true
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ServiceClass
|
2015-09-11 14:41:01 +05:30
|
|
|
def execute(data, hook_name)
|
2017-09-10 17:25:29 +05:30
|
|
|
WebHookService.new(self, data, hook_name).execute
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ServiceClass
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ServiceClass
|
2015-09-11 14:41:01 +05:30
|
|
|
def async_execute(data, hook_name)
|
2017-09-10 17:25:29 +05:30
|
|
|
WebHookService.new(self, data, hook_name).async_execute
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ServiceClass
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
# Allow urls pointing localhost and the local network
|
|
|
|
def allow_local_requests?
|
|
|
|
false
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|