multiprotocol_thrift_rack_app 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 35c30a64c3997fd22ed21a97e5fdc81c48055587657e8c366e3ea7ba10a274b9
4
+ data.tar.gz: d51987bd983a27176886c4cc53e379a737a6381487eda0e15c641269a0026e5a
5
+ SHA512:
6
+ metadata.gz: a834dce0808da1b7cdc1a76416bb972c8f1199a009c6e5a712fce636f0ed5d1bd90fdcc5013e1962c4f6a86c39970dfc15e52e3477f7f0a832820dd52344a65e
7
+ data.tar.gz: b2f42faad34872c3cdd74ba7d5f1cc32541aa2d19b33b0f5b90b5231355c2f1d1c1cfe5b47f95857227e98e4591eea077d44ae5fc499cea3e8fa22f8a09b3055
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ vendor/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,54 @@
1
+ .test_shared: &test_shared
2
+ before_script:
3
+ - apk add --update
4
+ git
5
+ ruby-dev
6
+ build-base
7
+
8
+ - gem update --system
9
+ - gem install bundler --version 2.0.1
10
+ - bundler install --jobs $(nproc) --path vendor/
11
+ - bundler update
12
+
13
+ - ruby --version
14
+ - gem --version
15
+ - bundler --version
16
+
17
+ script:
18
+ - bundle exec rake
19
+
20
+ test/2.3:
21
+ <<: *test_shared
22
+ stage: test
23
+ image: ruby:2.3-alpine
24
+
25
+ cache:
26
+ paths:
27
+ - vendor/ruby/2.3.0
28
+
29
+ test/2.4:
30
+ <<: *test_shared
31
+ stage: test
32
+ image: ruby:2.4-alpine
33
+
34
+ cache:
35
+ paths:
36
+ - vendor/ruby/2.4.0
37
+
38
+ test/2.5:
39
+ <<: *test_shared
40
+ stage: test
41
+ image: ruby:2.5-alpine
42
+
43
+ cache:
44
+ paths:
45
+ - vendor/ruby/2.5.0
46
+
47
+ test/2.6:
48
+ <<: *test_shared
49
+ stage: test
50
+ image: ruby:2.6-alpine
51
+
52
+ cache:
53
+ paths:
54
+ - vendor/ruby/2.6.0
data/.reek.yml ADDED
@@ -0,0 +1,7 @@
1
+ detectors:
2
+ UtilityFunction:
3
+ public_methods_only: yes
4
+
5
+ BooleanParameter:
6
+ exclude:
7
+ - MultiprotocolThriftRackApp#initialize
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
7
+
8
+ Style/TrailingCommaInArguments:
9
+ EnforcedStyleForMultiline: comma
10
+
11
+ Style/TrailingCommaInArrayLiteral:
12
+ EnforcedStyleForMultiline: comma
13
+
14
+ Style/TrailingCommaInHashLiteral:
15
+ EnforcedStyleForMultiline: comma
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - spec/**/*
20
+
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in multiprotocol_thrift_rack_app.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dmitrij Fedorenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Multiprotocol Thrift Rack application
2
+
3
+ This library allows you to create a Thrift RPC server from a Rack application, which can simultaneously receive requests encoded in JSON and Thrift.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'multiprotocol_thrift_rack_app
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install multiprotocol_thrift_rack_app
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `VERSION`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/c0va23/multiprotocol_thrift_rack_app.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new(:rubocop) do |t|
10
+ t.options = ['--config', '.rubocop.yml']
11
+ end
12
+
13
+ require 'reek/rake/task'
14
+ Reek::Rake::Task.new(:reek)
15
+
16
+ task default: %i[rubocop reek spec]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'multiprotocol_thrift_rack_app'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+ require 'thrift'
5
+ require 'logger'
6
+
7
+ # Multiprotocol Thrift Rack application
8
+ class MultiprotocolThriftRackApp
9
+ def initialize(
10
+ processor,
11
+ protocol_factory_map,
12
+ logger: default_logger,
13
+ buffered: false
14
+ )
15
+ @processor = processor
16
+ @protocol_factory_map = protocol_factory_map.freeze
17
+ @logger = logger
18
+ @buffered = buffered
19
+ end
20
+
21
+ def call(env)
22
+ request = Rack::Request.new(env)
23
+ return failure_response('Not POST method') unless request.post?
24
+
25
+ protocol_factory, content_type = find_protocol_factory(request)
26
+ return failure_response('Unknown Content-Type') unless protocol_factory
27
+
28
+ successful_response(request.body, protocol_factory, content_type)
29
+ end
30
+
31
+ private
32
+
33
+ CONTENT_TYPE_ENV = 'CONTENT_TYPE'
34
+
35
+ def default_logger
36
+ Logger.new(STDERR, level: Logger::INFO)
37
+ end
38
+
39
+ def failure_response(error_message)
40
+ Rack::Response.new(error_message, 400, {})
41
+ end
42
+
43
+ def fetch_content_type(request)
44
+ request.get_header(CONTENT_TYPE_ENV)
45
+ end
46
+
47
+ def debug_protocol_factory(protocol_factory, content_type)
48
+ if protocol_factory
49
+ @logger.debug("Match #{content_type} for #{protocol_factory}")
50
+ else
51
+ @logger.error("Unexpected Content-Type #{content_type}")
52
+ end
53
+ end
54
+
55
+ def find_protocol_factory(request)
56
+ content_type = fetch_content_type(request)
57
+
58
+ protocol_factory, =
59
+ @protocol_factory_map.find do |(_protocol_factory, content_types)|
60
+ content_types.include?(content_type)
61
+ end
62
+
63
+ debug_protocol_factory(protocol_factory, content_type)
64
+
65
+ [protocol_factory, content_type]
66
+ end
67
+
68
+ def build_transport(raw_transport)
69
+ if @buffered
70
+ Thrift::BufferedTransport.new(raw_transport)
71
+ else
72
+ raw_transport
73
+ end
74
+ end
75
+
76
+ def successful_response(request_body, protocol_factory, content_type)
77
+ Rack::Response.new(
78
+ [],
79
+ 200,
80
+ Rack::CONTENT_TYPE => content_type,
81
+ ) do |response|
82
+ raw_transport = Thrift::IOStreamTransport.new(request_body, response)
83
+ transport = build_transport(raw_transport)
84
+ protocol = protocol_factory.get_protocol(transport)
85
+ @processor.process(protocol, protocol)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'multiprotocol_thrift_rack_app'
8
+ spec.version = File.read('VERSION').strip
9
+ spec.authors = ['Dmitrij Fedorenko']
10
+ spec.email = ['c0va23@gmail.com']
11
+
12
+ spec.summary = 'Multiprotocol Thrift Rack app server'
13
+ spec.description = 'Ruby HTTP Thrif server with support muptiple ' \
14
+ 'protocols (JSON, Binary and etc.)'
15
+ spec.homepage = "https://gitlab.com/c0va23/#{spec.name}"
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'rack'
26
+ spec.add_dependency 'thrift', '~> 0.9'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'reek', '~> 5.4'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.68.1'
33
+ spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
34
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.32.0'
35
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multiprotocol_thrift_rack_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Dmitrij Fedorenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thrift
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: reek
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.68.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.68.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.1.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.32.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.32.0
139
+ description: Ruby HTTP Thrif server with support muptiple protocols (JSON, Binary
140
+ and etc.)
141
+ email:
142
+ - c0va23@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".gitlab-ci.yml"
149
+ - ".reek.yml"
150
+ - ".rspec"
151
+ - ".rubocop.yml"
152
+ - ".travis.yml"
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - VERSION
158
+ - bin/console
159
+ - bin/setup
160
+ - lib/multiprotocol_thrift_rack_app.rb
161
+ - multiprotocol_thrift_rack_app.gemspec
162
+ homepage: https://gitlab.com/c0va23/multiprotocol_thrift_rack_app
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubygems_version: 3.0.3
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Multiprotocol Thrift Rack app server
185
+ test_files: []