2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class WebHook < ApplicationRecord
|
2015-02-05 17:20:55 -05:00
|
|
|
include Sortable
|
2011-12-14 11:38:52 -05:00
|
|
|
|
2018-09-10 08:05:22 -04:00
|
|
|
attr_encrypted :token,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
2018-12-04 18:54:29 -05:00
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
2018-09-10 08:05:22 -04:00
|
|
|
|
|
|
|
attr_encrypted :url,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
2018-12-04 18:54:29 -05:00
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
2018-09-10 08:05:22 -04:00
|
|
|
|
2017-06-08 11:16:27 -04:00
|
|
|
has_many :web_hook_logs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2017-04-27 06:08:57 -04:00
|
|
|
|
2019-07-30 06:53:23 -04:00
|
|
|
validates :url, presence: true
|
|
|
|
validates :url, public_url: true, unless: ->(hook) { hook.is_a?(SystemHook) }
|
2018-06-01 07:43:53 -04:00
|
|
|
|
2018-01-05 16:36:18 -05:00
|
|
|
validates :token, format: { without: /\n/ }
|
2018-06-07 03:35:17 -04:00
|
|
|
validates :push_events_branch_filter, branch_filter: true
|
2011-12-14 11:38:52 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ServiceClass
|
2015-01-23 19:10:43 -05:00
|
|
|
def execute(data, hook_name)
|
2017-04-27 06:08:57 -04:00
|
|
|
WebHookService.new(self, data, hook_name).execute
|
2011-12-14 11:38:52 -05:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ServiceClass
|
2013-01-24 15:15:24 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ServiceClass
|
2015-01-23 19:10:43 -05:00
|
|
|
def async_execute(data, hook_name)
|
2017-04-27 06:08:57 -04:00
|
|
|
WebHookService.new(self, data, hook_name).async_execute
|
2016-04-27 03:24:49 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ServiceClass
|
2018-06-01 07:43:53 -04:00
|
|
|
|
|
|
|
# Allow urls pointing localhost and the local network
|
|
|
|
def allow_local_requests?
|
2019-07-26 06:21:52 -04:00
|
|
|
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
|
2018-06-01 07:43:53 -04:00
|
|
|
end
|
2011-12-14 11:38:52 -05:00
|
|
|
end
|