Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ group :development, :test do
gem "pry-byebug", platform: :mri, require: false
gem 'rubocop'
gem 'yard'
gem 'hrr_rb_ssh', git: "https://github.com/adfoster-r7/hrr_rb_ssh.git", branch: "investigate-openssl3-support"
gem 'hrr_rb_sftp'
end
57 changes: 37 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
GIT
remote: https://github.com/adfoster-r7/hrr_rb_ssh.git
revision: c804e69c4e364ce7fc2092a3e654c4d920c8c54f
branch: investigate-openssl3-support
specs:
hrr_rb_ssh (0.4.2)

PATH
remote: .
specs:
event_source (0.5.8)
addressable (>= 2.8.0)
bunny (>= 2.14)
deep_merge (~> 1.2.0)
dry-configurable (~> 0.12)
dry-configurable (~> 0.12.0)
dry-container (~> 0.8.0)
dry-core (< 0.8.0)
dry-events (~> 0.3)
dry-inflector (~> 0.2)
dry-initializer (~> 3.0)
dry-inflector (< 0.3.0)
dry-initializer (~> 3.0.0)
dry-monads (~> 1.3)
dry-schema (~> 1.6)
dry-schema (~> 1.6.0)
dry-struct (~> 1.4)
dry-types (~> 1.5)
dry-validation (~> 1.6)
faraday (~> 1.4.1)
faraday_middleware (~> 1.0)
logging (~> 2.3.0)
mime-types
net-sftp
nokogiri (>= 1.13.0)
oj (~> 3.11)
ox (~> 2.14)
oj (< 3.14)
ox (< 2.14.15)
set (< 1.0.4)
typhoeus (~> 1.4.0)

GEM
Expand Down Expand Up @@ -91,7 +102,7 @@ GEM
ast (2.4.2)
bson (4.12.1)
builder (3.2.4)
bunny (2.19.0)
bunny (2.22.0)
amq-protocol (~> 2.3, >= 2.3.1)
sorted_set (~> 1, >= 1.0.2)
byebug (11.1.3)
Expand All @@ -106,7 +117,7 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
deep_merge (1.2.1)
deep_merge (1.2.2)
diff-lcs (1.4.4)
dry-configurable (0.12.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -153,7 +164,7 @@ GEM
dry-initializer (~> 3.0)
dry-schema (~> 1.5, >= 1.5.2)
erubi (1.10.0)
ethon (0.15.0)
ethon (0.16.0)
ffi (>= 1.15.0)
faker (2.18.0)
i18n (>= 1.6, < 2)
Expand All @@ -172,15 +183,16 @@ GEM
faraday-net_http_persistent (1.2.0)
faraday_middleware (1.2.0)
faraday (~> 1.0)
ffi (1.15.4)
ffi (1.16.3)
globalid (0.5.2)
activesupport (>= 5.0)
hashdiff (1.0.1)
hrr_rb_sftp (0.2.0)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
little-plugger (1.1.4)
logging (2.3.0)
logging (2.3.1)
little-plugger (~> 1.1)
multi_json (~> 1.14)
loofah (2.12.0)
Expand All @@ -190,24 +202,27 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.2)
method_source (1.0.0)
mime-types (3.3.1)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0901)
mime-types-data (3.2024.0206)
mini_mime (1.1.2)
mini_portile2 (2.8.1)
mini_portile2 (2.8.5)
minitest (5.14.4)
mongo (2.14.0)
bson (>= 4.8.2, < 5.0.0)
mongoid (7.3.0)
activemodel (>= 5.1, < 6.2)
mongo (>= 2.10.5, < 3.0.0)
multi_json (1.15.0)
multipart-post (2.1.1)
multipart-post (2.4.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-ssh (7.2.1)
nio4r (2.5.8)
oj (3.13.9)
ox (2.14.5)
oj (3.13.23)
ox (2.14.14)
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
Expand All @@ -218,7 +233,7 @@ GEM
byebug (~> 11.0)
pry (~> 0.10)
public_suffix (4.0.6)
racc (1.6.2)
racc (1.7.3)
rack (2.2.3)
rack-protection (2.1.0)
rack
Expand Down Expand Up @@ -285,7 +300,7 @@ GEM
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
set (1.0.2)
set (1.0.3)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -303,7 +318,7 @@ GEM
sprockets (>= 3.0.0)
thor (1.1.0)
tilt (2.0.10)
typhoeus (1.4.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
Expand All @@ -325,6 +340,8 @@ DEPENDENCIES
database_cleaner
event_source!
faker
hrr_rb_sftp
hrr_rb_ssh!
mongoid
pry
pry-byebug
Expand Down
23 changes: 16 additions & 7 deletions event_source.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ lib = File.expand_path('../lib', __FILE__)

$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'event_source/version'
require 'event_source/ruby_versions'

Gem::Specification.new do |spec|
spec.name = 'event_source'
Expand Down Expand Up @@ -38,23 +39,31 @@ Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '>= 2.8.0'
spec.add_dependency 'bunny', '>= 2.14'
spec.add_dependency 'deep_merge', '~> 1.2.0'
spec.add_dependency 'dry-configurable', '~> 0.12'
spec.add_dependency 'dry-core', '< 0.8.0'
spec.add_dependency 'dry-configurable', '~> 0.12.0'
spec.add_dependency 'dry-container', '~> 0.8.0'
spec.add_dependency 'dry-events', '~> 0.3'
spec.add_dependency 'dry-inflector', '~> 0.2'
spec.add_dependency 'dry-initializer', '~> 3.0'
spec.add_dependency 'dry-inflector', '< 0.3.0'
spec.add_dependency 'dry-initializer', '~> 3.0.0'
spec.add_dependency 'dry-monads', '~> 1.3'
spec.add_dependency 'dry-struct', '~> 1.4'
spec.add_dependency 'dry-types', '~> 1.5'
spec.add_dependency 'dry-validation', '~> 1.6'
spec.add_dependency 'dry-schema', '~> 1.6'
spec.add_dependency 'dry-schema', '~> 1.6.0'
spec.add_dependency 'faraday', '~> 1.4.1'
spec.add_dependency 'faraday_middleware', '~> 1.0'
spec.add_dependency 'logging', '~> 2.3.0'
spec.add_dependency 'nokogiri', '>= 1.13.0'
if EventSource::RubyVersions::GREATER_THAN_TWO_SIX
spec.add_dependency 'nokogiri', '>= 1.13.0'
else
spec.add_dependency 'nokogiri', '< 1.14.0'
end
spec.add_dependency 'set', '< 1.0.4'
spec.add_dependency 'mime-types'
spec.add_dependency 'oj', '~> 3.11'
spec.add_dependency 'ox', '~> 2.14'
spec.add_dependency 'oj', '< 3.14'
spec.add_dependency 'ox', '< 2.14.15'
spec.add_dependency 'typhoeus', '~> 1.4.0'
spec.add_dependency 'net-sftp'

# TODO: Change to development dependency
spec.add_development_dependency 'database_cleaner'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PublishOperationBindingsContract < Contract
params do
optional(:http).hash
optional(:amqp).hash
optional(:sftp).hash
end

rule(:http) do
Expand Down
1 change: 1 addition & 0 deletions lib/event_source/async_api/publish_bindings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PublishBindings < Dry::Struct
transform_keys(&:to_sym)
attribute :http, ::EventSource::Protocols::Http::PublishBindings.meta(omittable: true)
attribute :amqp, Types::Hash.meta(omittable: true)
attribute :sftp, Types::Hash.meta(omittable: true)
attribute :x_amqp_exchange_to_exchanges, Types::Hash.meta(omittable: true)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/event_source/configure/contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative "contracts/client_certificate_settings_contract"
require_relative "contracts/soap_settings_contract"
require_relative "contracts/http_configuration_contract"
require_relative "contracts/sftp_configuration_contract"

module EventSource
module Configure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module EventSource
module Configure
module Contracts
# Contract for Sftp configuration.
class SftpConfigurationContract < Dry::Validation::Contract
params do
optional(:ref).value(:string)
optional(:url).value(:string)
optional(:host).value(:string)
optional(:port).value(::EventSource::Configure::Types::SftpPortSettingType)
optional(:path).value(:string)
required(:user_name).value(:string)
optional(:password).value(:string)
optional(:private_key).value(::EventSource::Configure::Types::SftpPrivateKeySettingType)
required(:call_location).array(:string)
end

rule(:url, :host) do
key.failure("either :url or :host must be specified") if values[:url].blank? && values[:host].blank?
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def validate_configuration(sc)
result = ::EventSource::Configure::Contracts::HttpConfigurationContract.new.call(params_as_hash)
return Success(sc) if result.success?
Failure([sc, result.errors])
when ::EventSource::Configure::SftpConfiguration
result = ::EventSource::Configure::Contracts::SftpConfigurationContract.new.call(params_as_hash)
return Success(sc) if result.success?
Failure([sc, result.errors])
else
Success(sc)
end
Expand Down
25 changes: 25 additions & 0 deletions lib/event_source/configure/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ def to_h
end
end

SftpConfiguration = Struct.new(
:protocol,
:ref,
:host,
:port,
:url,
:user_name,
:password,
:path,
:private_key,
:call_location
) do
def to_h
attribute_hash = super()
attribute_hash.compact
end
end

# Represents a server configuration.
class Servers
attr_reader :default_content_type, :configurations
Expand All @@ -84,6 +102,13 @@ def amqp
yield(amqp_conf)
@configurations.push(amqp_conf)
end

def sftp
sftp_conf = SftpConfiguration.new(:sftp)
sftp_conf.call_location = caller(1)
yield(sftp_conf)
@configurations.push(sftp_conf)
end
end
end
end
3 changes: 3 additions & 0 deletions lib/event_source/configure/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Configure
module Types
send(:include, Dry.Types)

SftpPortSettingType = Types::Params::Integer.default(22)
SftpPrivateKeySettingType = Types::String

SoapSecurityTimestampUseSettingType = Types::Bool.default(false)
SoapPasswordDigestSettingType = Types::Symbol.default(:digest).enum(:digest, :plain)
SoapTimestampTtlSettingType = Types::Params::Integer.default(60)
Expand Down
3 changes: 2 additions & 1 deletion lib/event_source/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def add_connection(async_api_server)
# an {EventSource::AsyncApi::Server} configuration
# @return [EventSource::Connection] Connection
def fetch_connection(async_api_server)
# raise connections.keys.inspect
client_klass = protocol_klass_for(async_api_server.protocol)
connection_uri = client_klass.connection_uri_for(async_api_server)
connections[connection_uri]
Expand Down Expand Up @@ -171,6 +170,8 @@ def protocol_klass_for(protocol)
EventSource::Protocols::Amqp::BunnyConnectionProxy
when :http, :https, 'http', 'https'
EventSource::Protocols::Http::FaradayConnectionProxy
when :sftp, 'sftp'
EventSource::Protocols::Sftp::SftpConnectionProxy
else
raise EventSource::Protocols::Amqp::Error::UnknownConnectionProtocolError,
"unknown protocol: #{protocol}"
Expand Down
37 changes: 37 additions & 0 deletions lib/event_source/protocols/sftp/sftp_channel_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module EventSource
module Protocols
module Sftp
class SftpChannelProxy
include EventSource::Logging

# @param sftp_connection_proxy [EventSource::Protocols::Sftp::SftpConnectionProxy] The Connection proxy instance
# @param channel_item_key [EventSource::AsyncApi::ChannelItem] unique name for the channel
# @param async_api_channel_item [EventSource::AsyncApi::ChannelItem] configuration settings for the Channel
# @return [SftpChannelProxy] Channel proxy instance
def initialize(
sftp_connection_proxy,
channel_item_key,
async_api_channel_item
)
@sftp_connection_proxy = sftp_connection_proxy
@channel_item_key = channel_item_key
@async_api_channel_item = async_api_channel_item
end

# Create and register an operation to broadcast messages
# @param async_api_channel_item [Hash] configuration values in the form of
# an {EventSource::AsyncApi::ChannelItem}
# @return [SftpPublishProxy]
def add_publish_operation(async_api_channel_item)
SftpPublishProxy.new(self, async_api_channel_item)
end

def execute(&blk)
@sftp_connection_proxy.execute(&blk)
end
end
end
end
end
Loading