debian-mirror-gitlab/app/models/hooks/web_hook.rb

45 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class WebHook < ApplicationRecord
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
2019-12-21 20:55:43 +05:30
has_many :web_hook_logs
2014-09-02 18:07:02 +05:30
2019-10-12 21:52:04 +05:30
validates :url, presence: true
validates :url, public_url: true, unless: ->(hook) { hook.is_a?(SystemHook) }
2018-11-08 19:23:39 +05:30
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?
2019-10-12 21:52:04 +05:30
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
2018-11-08 19:23:39 +05:30
end
2020-01-01 13:55:28 +05:30
def help_path
'user/project/integrations/webhooks'
end
2014-09-02 18:07:02 +05:30
end