nulogy_message_bus_producer 3.2.1 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -22
- data/Rakefile +2 -4
- data/db/migrate/20200611150212_create_public_subscriptions_and_events_tables.rb +2 -2
- data/lib/nulogy_message_bus_producer.rb +15 -8
- data/lib/nulogy_message_bus_producer/base_subscription.rb +1 -1
- data/lib/nulogy_message_bus_producer/config.rb +25 -1
- data/lib/nulogy_message_bus_producer/configuration/query_parser.rb +71 -0
- data/lib/nulogy_message_bus_producer/self_serve_subscription.rb +18 -0
- data/lib/nulogy_message_bus_producer/subscriptions/configured_subscription.rb +14 -0
- data/lib/nulogy_message_bus_producer/subscriptions/finder.rb +40 -0
- data/lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb +13 -6
- data/lib/nulogy_message_bus_producer/subscriptions/query_validator.rb +47 -0
- data/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker.rb +0 -5
- data/lib/nulogy_message_bus_producer/subscriptions/valid_for_schema_validator.rb +14 -0
- data/lib/nulogy_message_bus_producer/version.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/mailers/application_mailer.rb +2 -2
- data/spec/dummy/bin/bundle +2 -2
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +14 -16
- data/spec/dummy/bin/update +10 -10
- data/spec/dummy/bin/yarn +13 -7
- data/spec/dummy/config.ru +2 -1
- data/spec/dummy/config/application.rb +11 -6
- data/spec/dummy/config/boot.rb +2 -4
- data/spec/dummy/config/cable.yml +2 -2
- data/spec/dummy/config/database.yml +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +29 -7
- data/spec/dummy/config/environments/production.rb +50 -20
- data/spec/dummy/config/environments/test.rb +25 -8
- data/spec/dummy/config/initializers/assets.rb +2 -2
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/new_framework_defaults_6_1.rb +67 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/puma.rb +3 -3
- data/spec/dummy/config/spring.rb +2 -2
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/schema.rb +0 -2
- data/spec/dummy/log/development.log +317 -0
- data/spec/dummy/log/test.log +13164 -0
- data/spec/integration/lib/nulogy_message_bus_producer/config_spec.rb +37 -0
- data/spec/integration/lib/nulogy_message_bus_producer/repopulate_replication_slots_spec.rb +6 -7
- data/spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb +3 -57
- data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/finder_spec.rb +54 -0
- data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/no_variables_spec.rb +1 -1
- data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/postgres_transport_spec.rb +100 -54
- data/spec/integration/lib/nulogy_message_bus_producer/{subscriber_graphql_schema_validator_spec.rb → subscriptions/query_validator_spec.rb} +3 -3
- data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker_spec.rb +0 -16
- data/spec/integration_spec_helper.rb +0 -6
- data/spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb +58 -0
- data/spec/nulogy_message_bus_producer/subscriptions/subscription_spec.rb +9 -0
- data/spec/spec_helper.rb +26 -1
- data/spec/support/kafka.rb +9 -10
- data/spec/support/kafka_connect.rb +1 -1
- data/spec/support/shared_examples/subscription_validations.rb +77 -0
- data/spec/support/skip.rb +9 -0
- data/spec/support/sql_helpers.rb +1 -1
- data/spec/support/subscription_helpers.rb +22 -4
- data/spec/support/test_graphql_schema.rb +6 -2
- metadata +131 -79
- data/lib/nulogy_message_bus_producer/subscriber_graphql_schema_validator.rb +0 -45
- data/lib/nulogy_message_bus_producer/subscription.rb +0 -28
@@ -1,45 +0,0 @@
|
|
1
|
-
module NulogyMessageBusProducer
|
2
|
-
# A custom validator that checks that the provided (or all) subscriptions have a query that is valid for its
|
3
|
-
# configured schema. Schemas must be registered with a `schema_key`, that is persisted in the database.
|
4
|
-
# It ties the subscription to a particular schema.
|
5
|
-
#
|
6
|
-
# This validator is run as part of an initializer as a last ditch effort to verify that the stored queries in the
|
7
|
-
# database are valid against the deployed schema, so that when events are generated in the system, they are always
|
8
|
-
# sucessfully created.
|
9
|
-
class SubscriberGraphqlSchemaValidator
|
10
|
-
attr_reader :errors
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@errors = []
|
14
|
-
end
|
15
|
-
|
16
|
-
def validate(subscription_or_subscriptions = NulogyMessageBusProducer::Subscription.all)
|
17
|
-
Array(subscription_or_subscriptions).each do |subscription|
|
18
|
-
schema = find_schema(subscription)
|
19
|
-
next unless schema
|
20
|
-
|
21
|
-
gql_errors = schema.validate(subscription.query)
|
22
|
-
errors = gql_errors.map { |e| "#{e.message} #{display_id(subscription.id)}" }
|
23
|
-
|
24
|
-
@errors.concat(errors)
|
25
|
-
end
|
26
|
-
|
27
|
-
@errors.empty?
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def find_schema(subscription)
|
33
|
-
NulogyMessageBusProducer.resolve_schema(subscription.schema_key) do
|
34
|
-
@errors << "Could not find a schema for schema_key '#{subscription.schema_key}' #{display_id(subscription.id)}"
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def display_id(id)
|
40
|
-
normalized = id.presence || "<new_record>"
|
41
|
-
|
42
|
-
"(id: #{normalized})"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module NulogyMessageBusProducer
|
2
|
-
# This model saves all subscriptions to external systems.
|
3
|
-
# An external system can subscribe to events and specify the shape of data it would like to receive for the event.
|
4
|
-
class Subscription < ApplicationRecord
|
5
|
-
self.table_name = :message_bus_subscriptions
|
6
|
-
|
7
|
-
# Run our validator with familar syntax in this model
|
8
|
-
class ValidForSchemaValidator < ActiveModel::EachValidator
|
9
|
-
def validate_each(record, attribute, _value)
|
10
|
-
return if record.schema_key.blank? || record.query.blank?
|
11
|
-
|
12
|
-
validator = NulogyMessageBusProducer::SubscriberGraphqlSchemaValidator.new
|
13
|
-
|
14
|
-
validator.validate(record)
|
15
|
-
validator.errors.each { |e| record.errors.add(attribute, e) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
validates :schema_key, :event_type, presence: true
|
20
|
-
validates :query, presence: true, valid_for_schema: true
|
21
|
-
|
22
|
-
def self.create_or_update(attrs)
|
23
|
-
find_or_initialize_by(id: attrs[:id]).tap do |model|
|
24
|
-
model.update!(attrs)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|