Skip to content

Commit 44a6ca9

Browse files
committed
Add protocol and configuration bindings for outbound SNS.
This adds protocol and configuration bindings for outbound SNS messaging using AWS, particularly for SMS messages. Testing is still pending, as a working application generating events is needed to verify the implementation.
1 parent 0832b7f commit 44a6ca9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+719
-36
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ group :development, :test do
1313
gem 'rubocop'
1414
gem 'yard'
1515
gem 'rubocop-git'
16+
gem 'aws-sdk-sns'
1617
end

Gemfile.lock

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PATH
1818
faraday_middleware (~> 1.0)
1919
logging (~> 2.3.0)
2020
mime-types
21-
nokogiri (= 1.15.7)
21+
nokogiri (>= 1.13.0)
2222
oj (~> 3.11)
2323
ox (~> 2.14)
2424
typhoeus (~> 1.4.0)
@@ -89,6 +89,21 @@ GEM
8989
public_suffix (>= 2.0.2, < 5.0)
9090
amq-protocol (2.3.2)
9191
ast (2.4.2)
92+
aws-eventstream (1.3.2)
93+
aws-partitions (1.1098.0)
94+
aws-sdk-core (3.223.0)
95+
aws-eventstream (~> 1, >= 1.3.0)
96+
aws-partitions (~> 1, >= 1.992.0)
97+
aws-sigv4 (~> 1.9)
98+
base64
99+
jmespath (~> 1, >= 1.6.1)
100+
logger
101+
aws-sdk-sns (1.98.0)
102+
aws-sdk-core (~> 3, >= 3.216.0)
103+
aws-sigv4 (~> 1.5)
104+
aws-sigv4 (1.11.0)
105+
aws-eventstream (~> 1, >= 1.0.2)
106+
base64 (0.2.0)
92107
bson (4.12.1)
93108
builder (3.2.4)
94109
bunny (2.19.0)
@@ -179,7 +194,9 @@ GEM
179194
i18n (1.8.10)
180195
concurrent-ruby (~> 1.0)
181196
ice_nine (0.11.2)
197+
jmespath (1.6.2)
182198
little-plugger (1.1.4)
199+
logger (1.7.0)
183200
logging (2.3.0)
184201
little-plugger (~> 1.1)
185202
multi_json (~> 1.14)
@@ -327,6 +344,7 @@ PLATFORMS
327344
ruby
328345

329346
DEPENDENCIES
347+
aws-sdk-sns
330348
database_cleaner
331349
event_source!
332350
faker

lib/event_source.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require 'event_source/async_api/async_api'
2525
require 'event_source/railtie' if defined?(Rails)
2626
require 'event_source/configure'
27+
require 'event_source/protocols'
2728
require 'event_source/connection'
2829
require 'event_source/connection_manager'
2930
require 'event_source/channel'

lib/event_source/async_api/async_api.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module EventSource
1414
#
1515
# See {Protocols} for the data communication protocols EventSource supports.
1616
module AsyncApi
17-
require 'event_source/uris/amqp_uri'
1817
require_relative 'error'
1918
require_relative 'types'
2019
require_relative 'external_documentation'

lib/event_source/async_api/contracts/publish_operation_bindings_contract.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "event_source/protocols/http/contracts/publish_operation_bindings_contract"
44
require "event_source/protocols/amqp/contracts/publish_operation_binding_contract"
5+
require "event_source/protocols/sns/contracts/publish_operation_binding_contract"
56

67
module EventSource
78
module AsyncApi
@@ -11,6 +12,21 @@ class PublishOperationBindingsContract < Contract
1112
params do
1213
optional(:http).hash
1314
optional(:amqp).hash
15+
optional(:sns).hash
16+
end
17+
18+
rule(:sns) do
19+
if key? && value
20+
validation_result = ::EventSource::Protocols::Sns::Contracts::PublishOperationBindingsContract.new.call(value)
21+
if validation_result&.failure?
22+
key.failure(
23+
text: 'invalid operation bindings',
24+
error: validation_result.errors.to_h
25+
)
26+
else
27+
values.data.merge({ sns: validation_result.values })
28+
end
29+
end
1430
end
1531

1632
rule(:http) do

lib/event_source/async_api/publish_bindings.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "event_source/protocols/http/publish_bindings"
55
require "event_source/protocols/amqp/types"
66
require "event_source/protocols/amqp/publish_bindings"
7+
require "event_source/protocols/sns/publish_bindings"
78

89
module EventSource
910
module AsyncApi
@@ -12,6 +13,7 @@ class PublishBindings < Dry::Struct
1213
transform_keys(&:to_sym)
1314
attribute :http, ::EventSource::Protocols::Http::PublishBindings.meta(omittable: true)
1415
attribute :amqp, Types::Hash.meta(omittable: true)
16+
attribute :sns, ::EventSource::Protocols::Sns::PublishBindings.meta(omittable: true)
1517
attribute :x_amqp_exchange_to_exchanges, Types::Hash.meta(omittable: true)
1618
end
1719
end

lib/event_source/channel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def add_publish_operation(async_api_channel_item)
7676
@channel_proxy.add_publish_operation(async_api_channel_item)
7777
return false unless publish_proxy
7878

79-
@channel_proxy.create_exchange_to_exchange_bindings(publish_proxy) if @connection.protocol == :amqp
79+
@channel_proxy.publish_proxy_created(publish_proxy)
8080
operation_id = async_api_channel_item.publish.operationId
8181

8282
logger.info "Adding Publish Operation: #{operation_id}"

lib/event_source/configure/config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def initialize
1919
def load_protocols
2020
@protocols.each do |protocol|
2121
require "event_source/protocols/#{protocol}_protocol"
22+
protocol_module = EventSource::Protocols.const_get(protocol.camelize)
23+
EventSource::Protocols::Registry.register_protocol(
24+
protocol_module
25+
)
2226
end
2327
end
2428

lib/event_source/configure/contracts.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative "contracts/client_certificate_settings_contract"
44
require_relative "contracts/soap_settings_contract"
55
require_relative "contracts/http_configuration_contract"
6+
require_relative "contracts/sns_configuration_contract"
67

78
module EventSource
89
module Configure
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module EventSource
4+
module Configure
5+
module Contracts
6+
# Contract for SNS configuration.
7+
class SnsConfigurationContract < Dry::Validation::Contract
8+
params do
9+
required(:url).value(:string)
10+
required(:region).value(:string)
11+
required(:access_key_id).value(:string)
12+
required(:secret_access_key).value(:string)
13+
end
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)