avro_schema_registry-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31dd66f6c95e6bc63f0cb37cf0da57794f3d6c75
4
+ data.tar.gz: 69135493b57ccd5987f8780388cf27402222ff2b
5
+ SHA512:
6
+ metadata.gz: 9a49cb4caff0ea7ada702076cfc5f815ef0425c428f6d40289c3632212608811549399951ff3d6e350a90e902c08978b1f241b656c91f73fc3d4f0cf045576b4
7
+ data.tar.gz: 386de0ce6a17c1eeec95196cf487d1e4406c9c5d19ed8e42d530d27d60659429c1922729cb3929630ab22cf2d2053d65b8a74fda14e5d79612d8fd74a1953680
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.overcommit.yml ADDED
@@ -0,0 +1,13 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ required: false
5
+ on_warn: fail
6
+
7
+ HardTabs:
8
+ enabled: true
9
+ required: false
10
+
11
+ CommitMsg:
12
+ TrailingPeriod:
13
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_gem:
2
+ salsify_rubocop: conf/rubocop.yml
3
+
4
+ Style/FileName:
5
+ Exclude:
6
+ - 'lib/avro_schema_registry-client.rb'
7
+ - 'spec/avro_schema_registry-client_spec.rb'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.4
4
+ before_install: gem install bundler -v 1.14.6
5
+ script:
6
+ - bundle exec rubocop
7
+ - bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # avro_schema_registry-client
2
+
3
+ ## v0.1.0
4
+ - Initial version
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # override the :github shortcut to be secure by using HTTPS
4
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
5
+
6
+ # Specify your gem's dependencies in avro_schema_registry-client.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Salsify, Inc
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.
22
+
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # AvroSchemaRegistry::Client
2
+
3
+ Client for the [avro-schema-registry](https://github.com/salsify/avro-schema-registry)
4
+ app.
5
+
6
+ This client extends [AvroTurf::ConfluentSchemaRegistry](https://github.com/dasch/avro_turf)
7
+ to support [extensions](https://github.com/salsify/avro-schema-registry#extensions)
8
+ provided by avro-schema-registry
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'avro_schema_registry-client'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install avro_schema_registry-client
25
+
26
+ ## Usage
27
+
28
+ Create a client:
29
+
30
+ ```ruby
31
+ client = AvroSchemaRegistry::Client.new(registry_url, logger: logger)
32
+ ```
33
+
34
+ Create a client that caches the responses for requests to fetch or register
35
+ an `Avro::Schema`:
36
+
37
+ ```ruby
38
+ cached_client = AvroSchemaRegistry::CachedClient.new(
39
+ AvroSchemaRegistry::Client.new(registry_url, logger: logger)
40
+ )
41
+ ```
42
+
43
+ ### Fake Server
44
+
45
+ This gem also provides a fake avro-schema-registry server that can be used in
46
+ tests. This fake server depends on sinatra, which must be explicitly added
47
+ as a dependency:
48
+
49
+ ```ruby
50
+ require 'avro_schema_registry/test/fake_server'
51
+
52
+ # before hook with rspec
53
+ before do
54
+ WebMock.stub_request(:any, /^#{registry_url}/).to_rack(AvroSchemaRegistry::FakeServer)
55
+ AvroSchemaRegistry::FakeServer.clear
56
+ end
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
62
+ run `rake spec` to run the tests. You can also run `bin/console` for an
63
+ interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`.
66
+
67
+ To release a new version, update the version number in `version.rb`, and then
68
+ run `bundle exec rake release`, which will create a git tag for the version,
69
+ push git commits and tags, and push the `.gem` file to
70
+ [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at
75
+ https://github.com/salsify/avro_schema_registry-client.## License
76
+
77
+ The gem is available as open source under the terms of the
78
+ [MIT License](http://opensource.org/licenses/MIT).
79
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'avro_schema_registry/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'avro_schema_registry-client'
8
+ spec.version = AvroSchemaRegistry::VERSION
9
+ spec.authors = ['Salsify, Inc']
10
+ spec.email = ['engineering@salsify.com']
11
+
12
+ spec.summary = 'Client for the avro-schema-registry app'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/salsify/avro_schema_registry-client'
15
+
16
+ spec.license = 'MIT'
17
+
18
+ # Set 'allowed_push_post' to control where this gem can be published.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.12'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.4'
33
+ spec.add_development_dependency 'salsify_rubocop', '~> 0.47.2'
34
+ spec.add_development_dependency 'overcommit'
35
+ spec.add_development_dependency 'webmock'
36
+ spec.add_development_dependency 'simplecov'
37
+ # For AvroSchemaRegistry::FakeServer
38
+ spec.add_development_dependency 'sinatra'
39
+
40
+ spec.add_runtime_dependency 'avro_turf', '>= 0.8.0'
41
+ spec.add_runtime_dependency 'avro-resolution_canonical_form'
42
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'avro_schema_registry-client'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -v
5
+
6
+ bundle update
7
+
8
+ overcommit --install
@@ -0,0 +1,3 @@
1
+ require 'avro_schema_registry/version'
2
+ require 'avro_schema_registry/client'
3
+ require 'avro_schema_registry/cached_client'
@@ -0,0 +1,11 @@
1
+ require 'avro_turf/cached_confluent_schema_registry'
2
+
3
+ module AvroSchemaRegistry
4
+ class CachedClient < AvroTurf::CachedConfluentSchemaRegistry
5
+
6
+ # delegate additional method to upstream
7
+ def lookup_subject_schema(subject, schema)
8
+ @upstream.lookup_subject_schema(subject, schema)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ require 'avro_turf'
2
+ require 'avro_turf/confluent_schema_registry'
3
+ require 'avro-resolution_canonical_form'
4
+
5
+ module AvroSchemaRegistry
6
+ class Client < AvroTurf::ConfluentSchemaRegistry
7
+
8
+ def lookup_subject_schema(subject, schema)
9
+ schema_object = if schema.is_a?(String)
10
+ Avro::Schema.parse(schema)
11
+ else
12
+ schema
13
+ end
14
+
15
+ data = get("/subjects/#{subject}/fingerprints/#{schema_object.sha256_resolution_fingerprint.to_s(16)}")
16
+ id = data.fetch('id')
17
+ @logger.info("Found schema for subject `#{subject}`; id = #{id}")
18
+ id
19
+ end
20
+
21
+ # Override register to first check if a schema is registered by fingerprint
22
+ # Also, allow additional params to be passed to register.
23
+ def register(subject, schema, **params)
24
+
25
+ lookup_subject_schema(subject, schema)
26
+ rescue Excon::Errors::NotFound
27
+ data = post("/subjects/#{subject}/versions",
28
+ body: { schema: schema.to_s }.merge!(params).to_json)
29
+ id = data.fetch('id')
30
+ @logger.info("Registered schema for subject `#{subject}`; id = #{id}")
31
+ id
32
+
33
+ end
34
+
35
+ # Override to add support for additional params
36
+ def compatible?(subject, schema, version = 'latest', **params)
37
+ data = post("/compatibility/subjects/#{subject}/versions/#{version}",
38
+ expects: [200, 404],
39
+ body: { schema: schema.to_s }.merge!(params).to_json)
40
+ data.fetch('is_compatible', false) unless data.key?('error_code')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ require 'avro_turf/test/fake_confluent_schema_registry_server'
2
+ require 'avro-resolution_canonical_form'
3
+
4
+ module AvroSchemaRegistry
5
+ class FakeServer < FakeConfluentSchemaRegistryServer
6
+ get '/subjects/:subject/fingerprints/:fingerprint' do
7
+ subject = params[:subject]
8
+ halt(404, SCHEMA_NOT_FOUND) unless SUBJECTS.key?(subject)
9
+
10
+ fingerprint = params[:fingerprint]
11
+ fingerprint = fingerprint.to_i.to_s(16) if /^\d+$/ =~ fingerprint
12
+
13
+ schema_id = SCHEMAS.find_index do |schema|
14
+ Avro::Schema.parse(schema).sha256_resolution_fingerprint.to_s(16) == fingerprint
15
+ end
16
+
17
+ halt(404, SCHEMA_NOT_FOUND) unless schema_id && SUBJECTS[subject].include?(schema_id)
18
+
19
+ { id: schema_id }.to_json
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module AvroSchemaRegistry
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avro_schema_registry-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Salsify, Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: salsify_rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.47.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.47.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: overcommit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: avro_turf
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 0.8.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 0.8.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: avro-resolution_canonical_form
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Client for the avro-schema-registry app
154
+ email:
155
+ - engineering@salsify.com
156
+ executables:
157
+ - console
158
+ - setup
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - ".gitignore"
163
+ - ".overcommit.yml"
164
+ - ".rspec"
165
+ - ".rubocop.yml"
166
+ - ".travis.yml"
167
+ - CHANGELOG.md
168
+ - Gemfile
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - avro_schema_registry-client.gemspec
173
+ - bin/console
174
+ - bin/setup
175
+ - lib/avro_schema_registry-client.rb
176
+ - lib/avro_schema_registry/cached_client.rb
177
+ - lib/avro_schema_registry/client.rb
178
+ - lib/avro_schema_registry/test/fake_server.rb
179
+ - lib/avro_schema_registry/version.rb
180
+ homepage: https://github.com/salsify/avro_schema_registry-client
181
+ licenses:
182
+ - MIT
183
+ metadata:
184
+ allowed_push_host: https://rubygems.org
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.6.11
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Client for the avro-schema-registry app
205
+ test_files: []