teneo_grpc 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12432238a9422f1a3c5726c0750b1771710271fffc898e1f1fe39fb4a856e305
4
- data.tar.gz: 82067e9dd7db3312dd5f32ec7be962d5a57c459f09b8ced7e7af266b56ef501d
3
+ metadata.gz: 0ece2a9ed1c60d97d4abf65fb9b601596d1a3de8fb013c0ad178dff0f6668d77
4
+ data.tar.gz: a108072ce6b4dcde064e9e9c0b208ebaae8fe50d57bdb91077f3b4f68e07bb7f
5
5
  SHA512:
6
- metadata.gz: beba697be0259b03345587363640f2c5fbe5ff687c3bb7746a8e22e88d563653c2cb96b2333996463f1fe20b6e429fff43fa95709628cc0360e018f0106466d1
7
- data.tar.gz: fca4b1c4ae17d1b4bd5dc60c1fee94c258ef81c4a7a186dede6fbe646b14fa7790a737181c3d06b388f98283a2a196adc5bb65b0825d3588af1731506fe5a384
6
+ metadata.gz: d2962260d5ba65df5e1c297e762f4433b779192302e7c8aac950ed1e45b30d2584796d6f0c77edb142449d7de549d849bfb52859af146589c0961e31b6767bc9
7
+ data.tar.gz: ae7cc8b83c7c5723fb856c9df6f3077c50a1a1df75abe4a4f46c666d512458f272bdbbee277cd7a7cd0febb66cbecf724640f11dc68d74c1b645df0f8b53edba
data/Gemfile CHANGED
@@ -3,6 +3,7 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gem 'debug', require: false # requires libyaml-dev to be installed on system (Ubuntu)
6
+ gem 'dotenv', groups: %i[development test]
6
7
  gem 'grpc'
7
8
  gem 'grpc-tools'
8
9
  gem 'protobuf'
data/Gemfile.lock CHANGED
@@ -25,6 +25,7 @@ GEM
25
25
  irb (~> 1.10)
26
26
  reline (>= 0.3.8)
27
27
  diff-lcs (1.5.1)
28
+ dotenv (3.1.7)
28
29
  drb (2.2.1)
29
30
  google-protobuf (4.29.3)
30
31
  bigdecimal
@@ -117,6 +118,7 @@ PLATFORMS
117
118
 
118
119
  DEPENDENCIES
119
120
  debug
121
+ dotenv
120
122
  grpc
121
123
  grpc-tools
122
124
  protobuf
data/bin/dotenv ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby3.0
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'dotenv' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("dotenv", "dotenv")
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'util/env'
3
4
  require_relative 'util/convert'
4
5
  require_relative 'grpc_services/cloud_event_enum'
5
6
  require_relative 'proto/cloud_event_services_pb'
@@ -9,6 +10,8 @@ class Client
9
10
  attr_accessor :socket, :stub
10
11
 
11
12
  def initialize(socket:)
13
+ Env.valid_settings?
14
+
12
15
  @socket = socket
13
16
  @stub = CloudEvents::Stub.new(@socket, :this_channel_is_insecure)
14
17
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This error should get raised when the environment does not provide
4
+ # the required attributes.
5
+ class EnvSettingsError < StandardError
6
+ def initialize(msg = 'ERROR: invalid settings in .env file')
7
+ super(msg)
8
+ end
9
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # This error should get raised when a socket string has an invalid format
4
4
  class SocketFormatError < StandardError
5
- def initialize(msg = 'ERROR: invalid socket')
5
+ def initialize(msg = 'invalid socket')
6
6
  super(msg)
7
7
  end
8
8
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'securerandom'
4
4
 
5
+ require_relative '../util/convert'
6
+
5
7
  # CloudEventEnum provides an Enumerator of cloud events
6
8
  class CloudEventEnum
7
9
  def initialize(array:)
@@ -12,13 +14,7 @@ class CloudEventEnum
12
14
  return enum_for(:each) unless block_given?
13
15
 
14
16
  @array.each do |element|
15
- yield CloudEvent.new(
16
- id: SecureRandom.uuid,
17
- source: '/server-context',
18
- spec_version: '1.0',
19
- type: 'com.example.server-event',
20
- text_data: element
21
- )
17
+ yield Convert.text_to_cloudevent(data: element)
22
18
  end
23
19
  end
24
20
  end
@@ -2,14 +2,17 @@
2
2
 
3
3
  require_relative 'client'
4
4
  require_relative 'service_orchestrator'
5
+ require_relative 'util/env'
5
6
 
6
7
  # Encapsulating class for all gRPC communication
7
8
  class Server
8
9
  attr_accessor :socket, :remote_hosts, :clients
9
10
 
10
- def initialize(socket:, remote_hosts:)
11
- @socket = socket
12
- @remote_hosts = remote_hosts
11
+ def initialize
12
+ Env.valid_settings?
13
+
14
+ @socket = "#{ENV["LISTEN_ADDRESS"]}:#{ENV["PORT"]}"
15
+ @remote_hosts = ENV['REMOTE_HOSTS'].split('|') unless ENV['REMOTE_HOSTS'].nil?
13
16
 
14
17
  @clients = []
15
18
  @remote_hosts&.each do |remote|
@@ -8,11 +8,14 @@ require_relative '../grpc_services/cloud_event_enum'
8
8
  # The Convert module provides functionality on custom data conversion operations.
9
9
  module Convert
10
10
  def self.text_to_cloudevent(data:)
11
+ source = ENV['CLOUDEVENTS_SOURCE']
12
+ source = "#{ENV["LISTEN_ADDRESS"]}:#{ENV["PORT"]}" if source.nil?
13
+
11
14
  CloudEvent.new(
12
15
  id: SecureRandom.uuid,
13
- source: '/context',
14
- spec_version: '1.0',
15
- type: 'com.example.event',
16
+ source: source,
17
+ spec_version: ENV['CLOUDEVENTS_SPEC_VERSION'],
18
+ type: ENV['CLOUDEVENTS_TYPE_PREFIX'],
16
19
  text_data: data
17
20
  )
18
21
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ require_relative '../error_classes/env_settings_error'
6
+ require_relative '../error_classes/socket_format_error'
7
+
8
+ # The Env module provides functionality for env variable settings.
9
+ module Env
10
+ def self.valid_settings?
11
+ mandatory_settings = %w[LISTEN_ADDRESS PORT CLOUDEVENTS_SPEC_VERSION CLOUDEVENTS_TYPE_PREFIX]
12
+ mandatory_settings.each do |setting|
13
+ raise EnvSettingsError, "environment variable '#{setting}' not found" if ENV[setting].nil?
14
+ end
15
+
16
+ socket = "#{ENV["LISTEN_ADDRESS"]}:#{ENV["PORT"]}"
17
+ raise SocketFormatError unless socket =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}:\d{1,5}$/
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teneo_grpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Vanoverschelde
@@ -38,6 +38,7 @@ files:
38
38
  - Rakefile
39
39
  - bin/bundle
40
40
  - bin/console
41
+ - bin/dotenv
41
42
  - bin/grpc_tools_ruby_protoc
42
43
  - bin/grpc_tools_ruby_protoc_plugin
43
44
  - bin/htmldiff
@@ -58,6 +59,7 @@ files:
58
59
  - bin/thor
59
60
  - lib/teneo_grpc.rb
60
61
  - lib/teneo_grpc/client.rb
62
+ - lib/teneo_grpc/error_classes/env_settings_error.rb
61
63
  - lib/teneo_grpc/error_classes/socket_format_error.rb
62
64
  - lib/teneo_grpc/grpc_services/cloud_event_enum.rb
63
65
  - lib/teneo_grpc/proto/cloud_event_pb.rb
@@ -65,6 +67,7 @@ files:
65
67
  - lib/teneo_grpc/server.rb
66
68
  - lib/teneo_grpc/service_orchestrator.rb
67
69
  - lib/teneo_grpc/util/convert.rb
70
+ - lib/teneo_grpc/util/env.rb
68
71
  homepage: https://github.com/libis/teneo-grpc_skeleton_ruby
69
72
  licenses:
70
73
  - MIT