Class: Webhookdb::Replicator::Fake

Inherits:
Base
  • Object
show all
Extended by:
MethodUtilities
Defined in:
lib/webhookdb/replicator/fake.rb

Constant Summary

Constants inherited from Base

Base::MAX_INDEX_NAME_LENGTH

Constants included from DBAdapter::ColumnTypes

DBAdapter::ColumnTypes::BIGINT, DBAdapter::ColumnTypes::BIGINT_ARRAY, DBAdapter::ColumnTypes::BOOLEAN, DBAdapter::ColumnTypes::COLUMN_TYPES, DBAdapter::ColumnTypes::DATE, DBAdapter::ColumnTypes::DECIMAL, DBAdapter::ColumnTypes::DOUBLE, DBAdapter::ColumnTypes::FLOAT, DBAdapter::ColumnTypes::INTEGER, DBAdapter::ColumnTypes::INTEGER_ARRAY, DBAdapter::ColumnTypes::OBJECT, DBAdapter::ColumnTypes::TEXT, DBAdapter::ColumnTypes::TEXT_ARRAY, DBAdapter::ColumnTypes::TIMESTAMP, DBAdapter::ColumnTypes::UUID

Instance Attribute Summary

Attributes inherited from Base

#service_integration

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Methods inherited from Base

#_any_subscriptions_to_notify?, #_backfill_state_change_fields, #_backfillers, #_clear_backfill_information, #_clear_webook_information, #_coalesce_excluded_on_update, #_enqueue_backfill_jobs, #_fetch_enrichment, #_find_dependency_candidate, #_notify_dependents, #_parallel_backfill, #_prepare_for_insert, #_publish_rowupsert, #_resource_to_data, #_store_enrichment_body?, #_to_json, #_upsert_conflict_target, #_upsert_update_expr, #_upsert_webhook, #_upsert_webhook_single_resource, #_verify_backfill_err_msg, #_webhook_state_change_fields, #admin_dataset, #avoid_writes?, #backfill, #backfill_not_supported_message, #calculate_and_backfill_state_machine, #calculate_dependency_state_machine_step, #calculate_preferred_create_state_machine, chunked_row_update_bounds, #clear_backfill_information, #clear_webhook_information, #create_table, #create_table_modification, #create_table_partitions, #data_column, #dbadapter_table, #denormalized_columns, #descriptor, #documentation_url, #enqueue_sync_targets, #enrichment_column, #ensure_all_columns, #ensure_all_columns_modification, #existing_partitions, #find_dependent, #find_dependent!, #indices, #initialize, #on_backfill_error, #on_dependency_webhook_upsert, #partition?, #partitioning, #preferred_create_state_machine_method, #primary_key_column, #process_state_change, #qualified_table_sequel_identifier, #readonly_dataset, #remote_key_column, #resource_name_plural, #resource_name_singular, #schema_and_table_symbols, #storable_columns, #timestamp_column, #upsert_webhook, #upsert_webhook_body, #verify_backfill_credentials, #webhook_endpoint, #webhook_response, #with_advisory_lock

Constructor Details

This class inherits a constructor from Webhookdb::Replicator::Base

Class Method Details

._descriptor(**kw) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webhookdb/replicator/fake.rb', line 17

def self._descriptor(**kw)
  clsname = self.name.split("::").last
  opts = {
    name: clsname.underscore + "_v1",
    ctor: ->(sint) { self.new(sint) },
    feature_roles: ["internal"],
    resource_name_singular: clsname,
    supports_webhooks: true,
    supports_backfill: true,
  }
  opts.merge!(kw)
  return Webhookdb::Replicator::Descriptor.new(**opts)
end

.descriptorObject



31
# File 'lib/webhookdb/replicator/fake.rb', line 31

def self.descriptor = self._descriptor

.resetObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/webhookdb/replicator/fake.rb', line 33

def self.reset
  self.webhook_response = Webhookdb::WebhookResponse.ok
  self.upsert_has_deps = false
  self.resource_and_event_hook = nil
  self.dispatch_request_to_hook = nil
  self.process_webhooks_synchronously = nil
  self.obfuscate_headers_for_logging = []
  self.requires_sequence = false
  self.descendants&.each do |d|
    d.reset if d.respond_to?(:reset)
  end
  self.extra_index_specs = nil
  self.descendants&.each(&:reset)
end

.stub_backfill_request(items, status: 200) ⇒ Object



48
49
50
51
# File 'lib/webhookdb/replicator/fake.rb', line 48

def self.stub_backfill_request(items, status: 200)
  return WebMock::API.stub_request(:get, "https://fake-integration/?token=").
      to_return(status:, body: [items, nil].to_json, headers: {"Content-Type" => "application/json"})
end

Instance Method Details

#_denormalized_columnsObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/webhookdb/replicator/fake.rb', line 109

def _denormalized_columns
  return [
    Webhookdb::Replicator::Column.new(
      :at,
      TIMESTAMP,
      index: true,
      converter: Webhookdb::Replicator::Column::CONV_PARSE_TIME,
    ),
  ]
end

#_extra_index_specsObject



137
# File 'lib/webhookdb/replicator/fake.rb', line 137

def _extra_index_specs = super + (self.class.extra_index_specs || [])

#_fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object



144
145
146
147
148
# File 'lib/webhookdb/replicator/fake.rb', line 144

def _fetch_backfill_page(pagination_token, **_kwargs)
  r = Webhookdb::Http.get("https://fake-integration?token=#{pagination_token}", logger: nil, timeout: 30)
  raise "Expected 2-item array" unless r.parsed_response.is_a?(Array) && r.parsed_response.length == 2
  return r.parsed_response
end

#_remote_key_columnObject



105
106
107
# File 'lib/webhookdb/replicator/fake.rb', line 105

def _remote_key_column
  return Webhookdb::Replicator::Column.new(:my_id, TEXT)
end

#_resource_and_event(request) ⇒ Object



124
125
126
127
# File 'lib/webhookdb/replicator/fake.rb', line 124

def _resource_and_event(request)
  return self.class.resource_and_event_hook.call(request) if self.class.resource_and_event_hook
  return request.body, nil
end

#_timestamp_column_nameObject



120
121
122
# File 'lib/webhookdb/replicator/fake.rb', line 120

def _timestamp_column_name
  return :at
end

#_update_where_exprObject



129
130
131
# File 'lib/webhookdb/replicator/fake.rb', line 129

def _update_where_expr
  return Sequel[self.qualified_table_sequel_identifier][:at] < Sequel[:excluded][:at]
end

#_webhook_response(_request) ⇒ Object



99
100
101
102
103
# File 'lib/webhookdb/replicator/fake.rb', line 99

def _webhook_response(_request)
  r = self.class.webhook_response
  raise r if r.is_a?(Exception)
  return r
end

#calculate_backfill_state_machineObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/webhookdb/replicator/fake.rb', line 80

def calculate_backfill_state_machine
  step = Webhookdb::Replicator::StateMachineStep.new
  # if the service integration doesn't exist, create it with some standard values
  unless self.service_integration.backfill_secret.present?
    step.needs_input = true
    step.output = "Now let's test the backfill flow."
    step.prompt = "Paste or type a string here:"
    step.prompt_is_secret = false
    step.post_to_url = self.service_integration.unauthed_webhook_path + "/transition/backfill_secret"
    step.complete = false
    return step
  end

  step.needs_input = false
  step.output = "The backfill flow is working correctly."
  step.complete = true
  return step
end

#calculate_webhook_state_machineObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/webhookdb/replicator/fake.rb', line 66

def calculate_webhook_state_machine
  step = Webhookdb::Replicator::StateMachineStep.new
  # if the service integration doesn't exist, create it with some standard values
  unless self.service_integration.webhook_secret.present?
    step.output = "You're creating a fake_v1 service integration."
    return step.prompting("fake API secret").webhook_secret(self.service_integration)
  end

  step.output = "The integration creation flow is working correctly. Here is " \
                "the integration's opaque id, which you'll need to enter in a second: " \
                "#{self.service_integration.opaque_id}"
  return step.completed
end

#dispatch_request_to(request) ⇒ Object



139
140
141
142
# File 'lib/webhookdb/replicator/fake.rb', line 139

def dispatch_request_to(request)
  return self.class.dispatch_request_to_hook.call(request) if self.class.dispatch_request_to_hook
  return super
end

#preprocess_headers_for_logging(headers) ⇒ Object



57
58
59
# File 'lib/webhookdb/replicator/fake.rb', line 57

def preprocess_headers_for_logging(headers)
  self.class.obfuscate_headers_for_logging.each { |h| headers[h] = "***" }
end

#process_webhooks_synchronously?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/webhookdb/replicator/fake.rb', line 53

def process_webhooks_synchronously?
  return self.class.process_webhooks_synchronously ? true : false
end

#requires_sequence?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/webhookdb/replicator/fake.rb', line 133

def requires_sequence?
  return self.class.requires_sequence
end

#synchronous_processing_response_bodyObject



61
62
63
64
# File 'lib/webhookdb/replicator/fake.rb', line 61

def synchronous_processing_response_body(**)
  return super unless self.process_webhooks_synchronously?
  return self.class.process_webhooks_synchronously
end

#upsert_has_deps?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/webhookdb/replicator/fake.rb', line 150

def upsert_has_deps?
  return self.class.upsert_has_deps
end