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, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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
#sharding_organization
#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
.created_between(start_time, end_time) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/models/hooks/web_hook_log.rb', line 41
def self.created_between(start_time, end_time)
raise ArgumentError, '`start_time` and `end_time` must be present' if start_time.blank? || end_time.blank?
raise ArgumentError, '`start_time` must be before `end_time`' if start_time > end_time
if max_recent_days_ago > start_time
raise ArgumentError, "`start_time` to `end_time` range must be within the last #{MAX_RECENT_DAYS} days"
end
where(created_at: start_time..end_time).order(created_at: :desc)
end
|
.delete_batch_for(web_hook, batch_size:) ⇒ Object
Delete a batch of log records. Returns true if there may be more remaining.
54
55
56
57
58
|
# File 'app/models/hooks/web_hook_log.rb', line 54
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
|
.max_recent_days_ago ⇒ Object
60
61
62
|
# File 'app/models/hooks/web_hook_log.rb', line 60
def self.max_recent_days_ago
WebHookLog::MAX_RECENT_DAYS.days.ago.beginning_of_day
end
|
.recent(number_of_days = 2) ⇒ Object
32
33
34
35
36
37
38
39
|
# 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
created_between(number_of_days.days.ago.beginning_of_day, Time.zone.now)
end
|
Instance Method Details
#idempotency_key ⇒ Object
90
91
92
|
# File 'app/models/hooks/web_hook_log.rb', line 90
def idempotency_key
self[:request_headers]['Idempotency-Key']
end
|
#internal_error? ⇒ Boolean
#oversize? ⇒ Boolean
72
73
74
|
# File 'app/models/hooks/web_hook_log.rb', line 72
def oversize?
request_data == OVERSIZE_REQUEST_DATA
end
|
76
77
78
79
80
|
# File 'app/models/hooks/web_hook_log.rb', line 76
def
return super unless self[:request_headers]['X-Gitlab-Token']
self[:request_headers].merge('X-Gitlab-Token' => _('[REDACTED]'))
end
|
82
83
84
|
# File 'app/models/hooks/web_hook_log.rb', line 82
def
()
end
|
86
87
88
|
# File 'app/models/hooks/web_hook_log.rb', line 86
def
()
end
|
#success? ⇒ Boolean
64
65
66
|
# File 'app/models/hooks/web_hook_log.rb', line 64
def success?
response_status =~ /^2/
end
|
#url_current? ⇒ Boolean
94
95
96
97
98
99
100
|
# File 'app/models/hooks/web_hook_log.rb', line 94
def url_current?
return true if url_hash.nil?
Gitlab::CryptoHelper.sha256(web_hook.interpolated_url) == url_hash
end
|