jetra 1.2.0 → 1.3.0

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: 70c48ffb4371d9cf9311b1c1a8a2c57e8726f9ba1ac1d98a33e75b212621110f
4
- data.tar.gz: 3920ca597c20574c9576cf9f483d6123af507f311faf59bce068f765ec14a930
3
+ metadata.gz: a4533526c7a5f4fa3c65efe5c1705152074745adb524ab5b06906fb86341d6ab
4
+ data.tar.gz: 5a2717571721cd608ad2b63c302ac6f88aa901ff19f8a14ec6ce6771cc24a6ca
5
5
  SHA512:
6
- metadata.gz: bf0b5a6239b0fdbfcb31a86529f2c54e9f08dd48022f16d32bcd22b2e8b27555defcaf7cca980d69d9895179cc08aac15f8cdb8fd217be3c42b6825aec62b818
7
- data.tar.gz: 24fde8d26c56b7be2ada5d76ac9de2eee8a10542a14c77793f6eda068ddc01e6029288044284912576bb6bf158646d3a5cd34be01e170f69d18d1b5ebf02e1db
6
+ metadata.gz: df829138e837af89a99aab77f15cebc8d06555b55ed50b79a33a22745a80ae8bcdfeba28323db5f0afa13288aea73d0904e51481eb42ecbe3e86b6d36a6ea0a4
7
+ data.tar.gz: 8264eb31b1a175e533534e4f8feebbbac62add43eaf5b471d3ed096c17472dfa888394e61cdb5c6fb4793d92bb7a1861799bf998b3458d2ed786183345327feb
@@ -1,2 +1,2 @@
1
-
1
+
2
2
  require "jetra/base"
@@ -1,71 +1,71 @@
1
-
2
- require 'grpc'
3
-
4
- require "jetra/adapter/grpc/jetra_pb"
5
- require "jetra/adapter/grpc/jetra_services_pb"
6
-
7
- require "google/protobuf/well_known_types"
8
-
9
- require 'json'
10
-
11
- module Jetra
12
-
13
- module Grpc
14
-
15
- class Adapter < Interface::Service
16
-
17
- def initialize(app, &custom_block)
18
-
19
- @app = app
20
-
21
- @custom_block = custom_block
22
- end
23
-
24
- def call(request, _unused_call)
25
-
26
- if @custom_block
27
- @custom_block.call(request)
28
- end
29
-
30
- res = @app.call(request.route, request.params, request.headers, request.body)
31
-
32
- anyBody = Google::Protobuf::Any.new
33
- anyBody.pack(res.body)
34
-
35
- response = Response.new
36
- response.status = res.status
37
- response.body = anyBody
38
- response
39
- end
40
-
41
- end
42
-
43
- class Server
44
-
45
- def initialize(handler, bind)
46
-
47
- server = ::GRPC::RpcServer.new
48
- server.add_http2_port(bind, :this_port_is_insecure)
49
- server.handle(handler)
50
-
51
- @server = server
52
- end
53
-
54
- def serve
55
- @server.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT'])
56
- end
57
- end
58
-
59
- class Client
60
-
61
- def initialize(host_and_port)
62
- @client = Interface::Stub.new(host_and_port, :this_channel_is_insecure)
63
- end
64
-
65
- def call(request)
66
- @client.call(request)
67
- end
68
-
69
- end
70
- end
71
- end
1
+
2
+ require 'grpc'
3
+
4
+ require "jetra/adapter/grpc/jetra_pb"
5
+ require "jetra/adapter/grpc/jetra_services_pb"
6
+
7
+ require "google/protobuf/well_known_types"
8
+
9
+ require 'json'
10
+
11
+ module Jetra
12
+
13
+ module Grpc
14
+
15
+ class Adapter < Interface::Service
16
+
17
+ def initialize(app, &custom_block)
18
+
19
+ @app = app
20
+
21
+ @custom_block = custom_block
22
+ end
23
+
24
+ def call(request, _unused_call)
25
+
26
+ if @custom_block
27
+ @custom_block.call(request)
28
+ end
29
+
30
+ res = @app.call(request.route, request.params, request.headers, request.body)
31
+
32
+ anyBody = Google::Protobuf::Any.new
33
+ anyBody.pack(res.body)
34
+
35
+ response = Response.new
36
+ response.status = res.status
37
+ response.body = anyBody
38
+ response
39
+ end
40
+
41
+ end
42
+
43
+ class Server
44
+
45
+ def initialize(handler, bind)
46
+
47
+ server = ::GRPC::RpcServer.new
48
+ server.add_http2_port(bind, :this_port_is_insecure)
49
+ server.handle(handler)
50
+
51
+ @server = server
52
+ end
53
+
54
+ def serve
55
+ @server.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT'])
56
+ end
57
+ end
58
+
59
+ class Client
60
+
61
+ def initialize(host_and_port)
62
+ @client = Interface::Stub.new(host_and_port, :this_channel_is_insecure)
63
+ end
64
+
65
+ def call(request)
66
+ @client.call(request)
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -1,28 +1,28 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: jetra.proto
3
-
4
- require 'google/protobuf'
5
-
6
- require 'google/protobuf/any_pb'
7
- Google::Protobuf::DescriptorPool.generated_pool.build do
8
- add_file("jetra.proto", :syntax => :proto3) do
9
- add_message "jetra.grpc.Request" do
10
- optional :route, :string, 1
11
- map :params, :string, :string, 2
12
- map :headers, :string, :string, 3
13
- optional :body, :message, 4, "google.protobuf.Any"
14
- end
15
- add_message "jetra.grpc.Response" do
16
- optional :status, :int32, 1
17
- optional :body, :message, 2, "google.protobuf.Any"
18
- map :headers, :string, :string, 3
19
- end
20
- end
21
- end
22
-
23
- module Jetra
24
- module Grpc
25
- Request = Google::Protobuf::DescriptorPool.generated_pool.lookup("jetra.grpc.Request").msgclass
26
- Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("jetra.grpc.Response").msgclass
27
- end
28
- end
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: jetra.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/any_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_file("jetra.proto", :syntax => :proto3) do
9
+ add_message "jetra.grpc.Request" do
10
+ optional :route, :string, 1
11
+ map :params, :string, :string, 2
12
+ map :headers, :string, :string, 3
13
+ optional :body, :message, 4, "google.protobuf.Any"
14
+ end
15
+ add_message "jetra.grpc.Response" do
16
+ optional :status, :int32, 1
17
+ optional :body, :message, 2, "google.protobuf.Any"
18
+ map :headers, :string, :string, 3
19
+ end
20
+ end
21
+ end
22
+
23
+ module Jetra
24
+ module Grpc
25
+ Request = Google::Protobuf::DescriptorPool.generated_pool.lookup("jetra.grpc.Request").msgclass
26
+ Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("jetra.grpc.Response").msgclass
27
+ end
28
+ end
@@ -1,24 +1,24 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # Source: jetra.proto for package 'jetra.grpc'
3
-
4
- require 'grpc'
5
- require_relative 'jetra_pb'
6
-
7
- module Jetra
8
- module Grpc
9
- module Interface
10
- class Service
11
-
12
- include GRPC::GenericService
13
-
14
- self.marshal_class_method = :encode
15
- self.unmarshal_class_method = :decode
16
- self.service_name = 'jetra.grpc.Interface'
17
-
18
- rpc :Call, Request, Response
19
- end
20
-
21
- Stub = Service.rpc_stub_class
22
- end
23
- end
24
- end
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: jetra.proto for package 'jetra.grpc'
3
+
4
+ require 'grpc'
5
+ require_relative 'jetra_pb'
6
+
7
+ module Jetra
8
+ module Grpc
9
+ module Interface
10
+ class Service
11
+
12
+ include GRPC::GenericService
13
+
14
+ self.marshal_class_method = :encode
15
+ self.unmarshal_class_method = :decode
16
+ self.service_name = 'jetra.grpc.Interface'
17
+
18
+ rpc :Call, Request, Response
19
+ end
20
+
21
+ Stub = Service.rpc_stub_class
22
+ end
23
+ end
24
+ end
@@ -1,63 +1,63 @@
1
-
2
- require "set"
3
- require 'json'
4
- require 'rack'
5
-
6
- module Jetra
7
-
8
- class RackAdapter
9
-
10
- include Rack::Utils
11
-
12
- def initialize(app, &custom_block)
13
- @app = app
14
-
15
- @custom_block = custom_block
16
-
17
- end
18
-
19
- def call(env)
20
-
21
- request = Rack::Request.new(env)
22
-
23
- route = request.path_info
24
- route.chop! if (char=route[-1]) and char=='/' # ignore last '/' char
25
- route[0] = '' if route[0]=="/" #remove first '/' char
26
-
27
- params = indifferent_params(request.params)
28
-
29
- if @custom_block
30
- @custom_block.call(route, params)
31
- end
32
-
33
- res = @app.call(route, params)
34
-
35
- result = {}
36
- result[:status] = res.status
37
- result[:body] = res.body
38
-
39
- ['200', {'Content-Type' => 'application/json;charset=utf-8'}, [result.to_json]]
40
- end
41
-
42
- # Enable string or symbol key access to the nested params hash.
43
- def indifferent_params(object)
44
- case object
45
- when Hash
46
- new_hash = indifferent_hash
47
- object.each { |key, value| new_hash[key] = indifferent_params(value) }
48
- new_hash
49
- when Array
50
- object.map { |item| indifferent_params(item) }
51
- else
52
- object
53
- end
54
- end
55
-
56
- # Creates a Hash with indifferent access.
57
- def indifferent_hash
58
- Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
59
- end
60
-
61
- end
62
-
1
+
2
+ require "set"
3
+ require 'json'
4
+ require 'rack'
5
+
6
+ module Jetra
7
+
8
+ class RackAdapter
9
+
10
+ include Rack::Utils
11
+
12
+ def initialize(app, &custom_block)
13
+ @app = app
14
+
15
+ @custom_block = custom_block
16
+
17
+ end
18
+
19
+ def call(env)
20
+
21
+ request = Rack::Request.new(env)
22
+
23
+ route = request.path_info
24
+ route.chop! if (char=route[-1]) and char=='/' # ignore last '/' char
25
+ route[0] = '' if route[0]=="/" #remove first '/' char
26
+
27
+ params = indifferent_params(request.params)
28
+
29
+ if @custom_block
30
+ @custom_block.call(route, params)
31
+ end
32
+
33
+ res = @app.call(route.to_sym, params)
34
+
35
+ result = {}
36
+ result[:status] = res.status
37
+ result[:body] = res.body
38
+
39
+ ['200', {'Content-Type' => 'application/json;charset=utf-8'}, [result.to_json]]
40
+ end
41
+
42
+ # Enable string or symbol key access to the nested params hash.
43
+ def indifferent_params(object)
44
+ case object
45
+ when Hash
46
+ new_hash = indifferent_hash
47
+ object.each { |key, value| new_hash[key] = indifferent_params(value) }
48
+ new_hash
49
+ when Array
50
+ object.map { |item| indifferent_params(item) }
51
+ else
52
+ object
53
+ end
54
+ end
55
+
56
+ # Creates a Hash with indifferent access.
57
+ def indifferent_hash
58
+ Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
59
+ end
60
+
61
+ end
62
+
63
63
  end
@@ -1,111 +1,111 @@
1
-
2
- require 'thrift'
3
-
4
- require "jetra/adapter/thrift/jetra_types"
5
- require "jetra/adapter/thrift/jetra_constants"
6
- require "jetra/adapter/thrift/service"
7
-
8
- require 'json'
9
-
10
- module Jetra
11
-
12
- class ThriftAdapter
13
-
14
- def initialize(app, &custom_block)
15
- @app = app
16
-
17
- @custom_block = custom_block
18
- end
19
-
20
- def call(request)
21
-
22
- route = request.route || ""
23
-
24
- params = parse_params(request.params)
25
-
26
- if @custom_block
27
- @custom_block.call(route, params)
28
- end
29
-
30
- res = @app.call(route, params)
31
-
32
- response = Thrift::Response.new
33
- response.status = res.status
34
- response.body = res.body.to_json
35
- response
36
- end
37
-
38
- def parse_params(params)
39
- indifferent_params(JSON.load(params).to_h)
40
- rescue => boom
41
- {}
42
- end
43
-
44
- # Enable string or symbol key access to the nested params hash.
45
- def indifferent_params(object)
46
- case object
47
- when Hash
48
- new_hash = indifferent_hash
49
- object.each { |key, value| new_hash[key] = indifferent_params(value) }
50
- new_hash
51
- when Array
52
- object.map { |item| indifferent_params(item) }
53
- else
54
- object
55
- end
56
- end
57
-
58
- # Creates a Hash with indifferent access.
59
- def indifferent_hash
60
- Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
61
- end
62
-
63
- end
64
-
65
- class ThriftServer
66
-
67
- def initialize(handler, port)
68
- port = port
69
- processor = Thrift::Service::Processor.new(handler)
70
- transport = ::Thrift::ServerSocket.new(port)
71
- transportFactory = ::Thrift::FramedTransportFactory.new()
72
- @server = ::Thrift::NonblockingServer.new(processor, transport, transportFactory)
73
- end
74
-
75
- def serve
76
- @server.serve()
77
- end
78
-
79
- end
80
-
81
- class ThriftClient
82
-
83
- def initialize(host, port)
84
-
85
- transport = ::Thrift::FramedTransport.new(::Thrift::Socket.new(host, port))
86
- protocol = ::Thrift::BinaryProtocol.new(transport)
87
-
88
- @transport = transport
89
-
90
- @client = Thrift::Service::Client.new(protocol)
91
- end
92
-
93
- def call(request)
94
-
95
- @client.call(request)
96
-
97
- rescue ::Thrift::TransportException, IOError => boom
98
-
99
- establish_connection
100
-
101
- @client.call(request)
102
-
103
- end
104
-
105
- def establish_connection
106
- @transport.open
107
- end
108
-
109
- end
110
-
1
+
2
+ require 'thrift'
3
+
4
+ require "jetra/adapter/thrift/jetra_types"
5
+ require "jetra/adapter/thrift/jetra_constants"
6
+ require "jetra/adapter/thrift/service"
7
+
8
+ require 'json'
9
+
10
+ module Jetra
11
+
12
+ class ThriftAdapter
13
+
14
+ def initialize(app, &custom_block)
15
+ @app = app
16
+
17
+ @custom_block = custom_block
18
+ end
19
+
20
+ def call(request)
21
+
22
+ route = request.route || ""
23
+
24
+ params = parse_params(request.params)
25
+
26
+ if @custom_block
27
+ @custom_block.call(route, params)
28
+ end
29
+
30
+ res = @app.call(route, params)
31
+
32
+ response = Thrift::Response.new
33
+ response.status = res.status
34
+ response.body = res.body.to_json
35
+ response
36
+ end
37
+
38
+ def parse_params(params)
39
+ indifferent_params(JSON.load(params).to_h)
40
+ rescue => boom
41
+ {}
42
+ end
43
+
44
+ # Enable string or symbol key access to the nested params hash.
45
+ def indifferent_params(object)
46
+ case object
47
+ when Hash
48
+ new_hash = indifferent_hash
49
+ object.each { |key, value| new_hash[key] = indifferent_params(value) }
50
+ new_hash
51
+ when Array
52
+ object.map { |item| indifferent_params(item) }
53
+ else
54
+ object
55
+ end
56
+ end
57
+
58
+ # Creates a Hash with indifferent access.
59
+ def indifferent_hash
60
+ Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
61
+ end
62
+
63
+ end
64
+
65
+ class ThriftServer
66
+
67
+ def initialize(handler, port)
68
+ port = port
69
+ processor = Thrift::Service::Processor.new(handler)
70
+ transport = ::Thrift::ServerSocket.new(port)
71
+ transportFactory = ::Thrift::FramedTransportFactory.new()
72
+ @server = ::Thrift::NonblockingServer.new(processor, transport, transportFactory)
73
+ end
74
+
75
+ def serve
76
+ @server.serve()
77
+ end
78
+
79
+ end
80
+
81
+ class ThriftClient
82
+
83
+ def initialize(host, port)
84
+
85
+ transport = ::Thrift::FramedTransport.new(::Thrift::Socket.new(host, port))
86
+ protocol = ::Thrift::BinaryProtocol.new(transport)
87
+
88
+ @transport = transport
89
+
90
+ @client = Thrift::Service::Client.new(protocol)
91
+ end
92
+
93
+ def call(request)
94
+
95
+ @client.call(request)
96
+
97
+ rescue ::Thrift::TransportException, IOError => boom
98
+
99
+ establish_connection
100
+
101
+ @client.call(request)
102
+
103
+ end
104
+
105
+ def establish_connection
106
+ @transport.open
107
+ end
108
+
109
+ end
110
+
111
111
  end