Class: WebHookLog

Inherits:
ApplicationRecord show all
Includes:
CreatedAtFilterable, DeleteWithLimit, PartitionedTable, Presentable
Defined in:
app/models/hooks/web_hook_log.rb

Constant Summary collapse

OVERSIZE_REQUEST_DATA =
{ 'oversize' => true }.freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Presentable

#present

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

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Attribute Details

#interpolated_urlObject

Returns the value of attribute interpolated_url.



11
12
13
# File 'app/models/hooks/web_hook_log.rb', line 11

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.

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'app/models/hooks/web_hook_log.rb', line 35

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

.recentObject



29
30
31
32
# File 'app/models/hooks/web_hook_log.rb', line 29

def self.recent
  where(created_at: 2.days.ago.beginning_of_day..Time.zone.now)
    .order(created_at: :desc)
end

Instance Method Details

#internal_error?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/hooks/web_hook_log.rb', line 45

def internal_error?
  response_status == WebHookService::InternalErrorResponse::ERROR_MESSAGE
end

#oversize?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/hooks/web_hook_log.rb', line 49

def oversize?
  request_data == OVERSIZE_REQUEST_DATA
end

#request_headersObject



53
54
55
56
57
58
# File 'app/models/hooks/web_hook_log.rb', line 53

def request_headers
  super unless web_hook.token?
  super if self[:request_headers]['X-Gitlab-Token'] == _('[REDACTED]')

  self[:request_headers].merge('X-Gitlab-Token' => _('[REDACTED]'))
end

#success?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/hooks/web_hook_log.rb', line 41

def success?
  response_status =~ /^2/
end

#url_current?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'app/models/hooks/web_hook_log.rb', line 60

def url_current?
  # URL hash hasn't been set, so we must assume there's no prior value to
  # compare to.
  return true if url_hash.nil?

  Gitlab::CryptoHelper.sha256(web_hook.interpolated_url) == url_hash
end