Class: WebHookLog
Constant Summary
collapse
- OVERSIZE_REQUEST_DATA =
{ 'oversize' => true }.freeze
- MAX_RECENT_DAYS =
7
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#present
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, 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
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Instance Attribute Details
#interpolated_url ⇒ Object
Returns the value of attribute interpolated_url.
12
13
14
|
# File 'app/models/hooks/web_hook_log.rb', line 12
def interpolated_url
@interpolated_url
end
|
Class Method Details
.delete_batch_for(web_hook, batch_size:) ⇒ Object
Delete a batch of log records. Returns true if there may be more remaining.
43
44
45
46
47
|
# File 'app/models/hooks/web_hook_log.rb', line 43
def self.delete_batch_for(web_hook, batch_size:)
raise ArgumentError, 'batch_size is too small' if batch_size < 1
where(web_hook: web_hook).limit(batch_size).delete_all == batch_size
end
|
.recent(number_of_days = 2) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'app/models/hooks/web_hook_log.rb', line 32
def self.recent(number_of_days = 2)
if number_of_days > MAX_RECENT_DAYS
raise ArgumentError,
"`recent` scope can only provide up to #{MAX_RECENT_DAYS} days of log records"
end
where(created_at: number_of_days.days.ago.beginning_of_day..Time.zone.now)
.order(created_at: :desc)
end
|
Instance Method Details
#idempotency_key ⇒ Object
67
68
69
|
# File 'app/models/hooks/web_hook_log.rb', line 67
def idempotency_key
self[:request_headers]['Idempotency-Key']
end
|
#internal_error? ⇒ Boolean
#oversize? ⇒ Boolean
57
58
59
|
# File 'app/models/hooks/web_hook_log.rb', line 57
def oversize?
request_data == OVERSIZE_REQUEST_DATA
end
|
61
62
63
64
65
|
# File 'app/models/hooks/web_hook_log.rb', line 61
def
return super unless self[:request_headers]['X-Gitlab-Token']
self[:request_headers].merge('X-Gitlab-Token' => _('[REDACTED]'))
end
|
#success? ⇒ Boolean
49
50
51
|
# File 'app/models/hooks/web_hook_log.rb', line 49
def success?
response_status =~ /^2/
end
|
#url_current? ⇒ Boolean
71
72
73
74
75
76
77
|
# File 'app/models/hooks/web_hook_log.rb', line 71
def url_current?
return true if url_hash.nil?
Gitlab::CryptoHelper.sha256(web_hook.interpolated_url) == url_hash
end
|