Class: WebHook
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- WebHook
- Includes:
- Sortable, WebHooks::AutoDisabling
- Defined in:
- app/models/hooks/web_hook.rb
Direct Known Subclasses
Constant Summary collapse
- InterpolationError =
Class.new(StandardError)
- SECRET_MASK =
'************'
- VARIABLE_REFERENCE_RE =
See app/validators/json_schemas/web_hooks_url_variables.json
/\{([A-Za-z]+[0-9]*(?:[._-][A-Za-z0-9]+)*)\}/
Constants included from WebHooks::AutoDisabling
WebHooks::AutoDisabling::BACKOFF_GROWTH_FACTOR, WebHooks::AutoDisabling::ENABLED_HOOK_TYPES, WebHooks::AutoDisabling::EXCEEDED_FAILURE_THRESHOLD, WebHooks::AutoDisabling::FAILURE_THRESHOLD, WebHooks::AutoDisabling::INITIAL_BACKOFF, WebHooks::AutoDisabling::MAX_BACKOFF, WebHooks::AutoDisabling::MAX_FAILURES
Constants included from Gitlab::Loggable
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Instance Method Summary collapse
-
#allow_local_requests? ⇒ Boolean
Allow urls pointing localhost and the local network.
-
#application_context ⇒ Object
Custom attributes to be included in the worker context.
-
#async_execute(data, hook_name) ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
-
#execute(data, hook_name, force: false) ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
- #help_path ⇒ Object
- #interpolated_url(url = self.url, url_variables = self.url_variables) ⇒ Object
- #masked_token ⇒ Object
-
#parent ⇒ Object
Returns the associated Project or Group for the WebHook if one exists.
-
#rate_limit ⇒ Integer
The rate limit for the WebHook.
-
#rate_limited? ⇒ Boolean
Whether or not the WebHook is currently throttled.
-
#serializable_hash(options = nil) ⇒ Object
Exclude binary columns by default - they have no sensible JSON encoding.
- #update_last_failure ⇒ Object
Methods included from WebHooks::AutoDisabling
#alert_status, #backoff!, #enable!, #executable?, #failed!, #next_backoff, #permanently_disabled?, #temporarily_disabled?
Methods included from Gitlab::Loggable
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Instance Method Details
#allow_local_requests? ⇒ Boolean
Allow urls pointing localhost and the local network
68 69 70 |
# File 'app/models/hooks/web_hook.rb', line 68 def allow_local_requests? Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services? end |
#application_context ⇒ Object
Custom attributes to be included in the worker context.
92 93 94 |
# File 'app/models/hooks/web_hook.rb', line 92 def application_context { related_class: type } end |
#async_execute(data, hook_name) ⇒ Object
rubocop: disable CodeReuse/ServiceClass
62 63 64 |
# File 'app/models/hooks/web_hook.rb', line 62 def async_execute(data, hook_name) WebHookService.new(self, data, hook_name).async_execute if executable? end |
#execute(data, hook_name, force: false) ⇒ Object
rubocop: disable CodeReuse/ServiceClass
55 56 57 58 |
# File 'app/models/hooks/web_hook.rb', line 55 def execute(data, hook_name, force: false) # hook.executable? is checked in WebHookService#execute WebHookService.new(self, data, hook_name, force: force).execute end |
#help_path ⇒ Object
72 73 74 |
# File 'app/models/hooks/web_hook.rb', line 72 def help_path 'user/project/integrations/webhooks' end |
#interpolated_url(url = self.url, url_variables = self.url_variables) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/hooks/web_hook.rb', line 108 def interpolated_url(url = self.url, url_variables = self.url_variables) return url unless url.include?('{') vars = url_variables url.gsub(VARIABLE_REFERENCE_RE) do vars.fetch(_1.delete_prefix('{').delete_suffix('}')) end rescue KeyError => e raise InterpolationError, "Invalid URL template. Missing key #{e.key}" end |
#masked_token ⇒ Object
123 124 125 |
# File 'app/models/hooks/web_hook.rb', line 123 def masked_token token.present? ? SECRET_MASK : nil end |
#parent ⇒ Object
Returns the associated Project or Group for the WebHook if one exists. Overridden by inheriting classes.
88 89 |
# File 'app/models/hooks/web_hook.rb', line 88 def parent end |
#rate_limit ⇒ Integer
Returns The rate limit for the WebHook. ‘0` for no limit.
82 83 84 |
# File 'app/models/hooks/web_hook.rb', line 82 def rate_limit rate_limiter.limit end |
#rate_limited? ⇒ Boolean
Returns Whether or not the WebHook is currently throttled.
77 78 79 |
# File 'app/models/hooks/web_hook.rb', line 77 def rate_limited? rate_limiter.rate_limited? end |
#serializable_hash(options = nil) ⇒ Object
Exclude binary columns by default - they have no sensible JSON encoding
97 98 99 100 101 102 103 |
# File 'app/models/hooks/web_hook.rb', line 97 def serializable_hash( = nil) = .try(:dup) || {} [:except] = Array([:except]).dup [:except].concat [:encrypted_url_variables, :encrypted_url_variables_iv] super() end |
#update_last_failure ⇒ Object
119 120 121 |
# File 'app/models/hooks/web_hook.rb', line 119 def update_last_failure # Overridden in child classes. end |