schema_registry 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1d530b329c2ffc4f471bed84fc897843fdc932b
4
- data.tar.gz: b770be7557c4c038494147e5aed96d1052d3f486
3
+ metadata.gz: 2899eb9d0ac483c1f750a4e0abd8254fcd276696
4
+ data.tar.gz: f67cd142dbf9e9454115e8381de05645a60b5dae
5
5
  SHA512:
6
- metadata.gz: 8c45a230a3a73add3ec82751dcdc275979d5cd27f38c769157c819864da2ad8beae1de676c0dd960d854487a1e50dddbb8d3e839ca950b743253e3644e045c77
7
- data.tar.gz: 7bf8a528e69c471c4d25ae299fd00d0a0ca68c0dfa5d42a3fa7148cd950829a192cd22fce37a001517f549741c41e33fa1b315e78e30cd810c5c39d530889bab
6
+ metadata.gz: 37e0bb51c00b9b0d6600f3176a187fef49652368a6b60d8e7ffc554526f356e86b949bdbdad2aeb2942a6648a40b847835225105da77b2ee62f5f5c781be30d3
7
+ data.tar.gz: 6af7faeb40307bd2b547f503b42654fc51fa61e5fc2ace719a91007be23a8afb082229042dd21b25c4d94029057302ab5c8b96e23ac99ce516a0dee32db3ed50
data/README.md CHANGED
@@ -23,6 +23,41 @@ Or install it yourself as:
23
23
 
24
24
  TODO: Write usage instructions here
25
25
 
26
+
27
+ ### TLS
28
+
29
+ The registry does support client TLS cerificates as a means of authenticating w/ the schema registry.
30
+
31
+ You have two options of passing options to net/http. You can pass in all the config as named parameters
32
+
33
+ ##### Example
34
+
35
+ ```ruby
36
+ @client = SchemaRegistry::Client.new(
37
+ 'https://testschmreg.domain.com:8082',
38
+ cert: OpenSSL::X509::Certificate.new(File.read('./client.crt')),
39
+ key: OpenSSL::PKey::RSA.new(File.read('./client.key')),
40
+ ca_file: './ca.pem',
41
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
42
+ )
43
+ ```
44
+
45
+ The second option is to use a helper static method to avoid having to handle the encoding.
46
+
47
+ ##### Helper Example
48
+
49
+ ```ruby
50
+ @client = SchemaRegistry::Client.new(
51
+ "https://testschmreg.domain.com:8082",
52
+ SchemaRegistry::Client.connection_options(
53
+ client_certificate: './client.crt',
54
+ client_key: './client.key',
55
+ ca_certificate: "./ca.pem",
56
+ verify_mode: :verify_peer
57
+ )
58
+ )
59
+ ```
60
+
26
61
  ## Contributing
27
62
 
28
63
  1. Fork it ( https://github.com/[my-github-username]/schema_registry/fork )
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'openssl'
3
4
 
4
5
  module SchemaRegistry
5
6
  class ResponseError < Error
@@ -12,6 +13,7 @@ module SchemaRegistry
12
13
  end
13
14
 
14
15
  InvalidResponse = Class.new(SchemaRegistry::Error)
16
+ ServerError = Class.new(SchemaRegistry::ResponseError)
15
17
 
16
18
  RESPONSE_ERROR_CODES = {
17
19
  40401 => (SubjectNotFound = Class.new(SchemaRegistry::ResponseError)),
@@ -26,11 +28,12 @@ module SchemaRegistry
26
28
 
27
29
  class Client
28
30
 
29
- attr_reader :endpoint, :username, :password
31
+ attr_reader :endpoint, :username, :password, :http_options
30
32
 
31
- def initialize(endpoint, username = nil, password = nil)
33
+ def initialize(endpoint, username = nil, password = nil, **http_options)
32
34
  @endpoint = URI(endpoint)
33
35
  @username, @password = username, password
36
+ @http_options = http_options
34
37
  end
35
38
 
36
39
  def schema(id)
@@ -54,8 +57,48 @@ module SchemaRegistry
54
57
  request(:put, "/config", compatibility: level)
55
58
  end
56
59
 
60
+ # Build options hash for net/http based on params provided. Primary for selectivly adding TLS config options for MTLS
61
+ def self.connection_options(**config)
62
+ options = {}
63
+
64
+ unless config[:verify_mode].nil?
65
+ options[:verify_mode] = OpenSSL::SSL.const_get(config[:verify_mode].upcase)
66
+ end
67
+
68
+ unless config[:ca_certificate].nil?
69
+ if File.exist?(config[:ca_certificate])
70
+ options[:ca_file] = config[:ca_certificate]
71
+ else
72
+ raise ArgumentError, "ca file not found [#{config[:ca_certificate]}]"
73
+ end
74
+ end
75
+
76
+ unless config[:client_key].nil?
77
+ if File.exist?(config[:client_key])
78
+ options[:key] = OpenSSL::PKey::RSA.new(File.read(config[:client_key]))
79
+ else
80
+ raise ArgumentError, "client key file not found [#{config[:client_key]}]"
81
+ end
82
+ end
83
+
84
+ unless config[:client_certificate].nil?
85
+ if File.exist?(config[:client_certificate])
86
+ options[:cert] = OpenSSL::X509::Certificate.new(File.read(config[:client_certificate]))
87
+ else
88
+ raise ArgumentError, "client cert file not found [#{config[:client_certificate]}]"
89
+ end
90
+ end
91
+ options
92
+ end
93
+
57
94
  def request(method, path, body = nil)
58
- Net::HTTP.start(endpoint.host, endpoint.port, use_ssl: endpoint.scheme == 'https') do |http|
95
+
96
+ # build config for http client
97
+ default_options = {
98
+ use_ssl: endpoint.scheme == 'https'
99
+ }.merge!(@http_options)
100
+
101
+ Net::HTTP.start(endpoint.host, endpoint.port, default_options) do |http|
59
102
  request_class = case method
60
103
  when :get; Net::HTTP::Get
61
104
  when :post; Net::HTTP::Post
@@ -80,6 +123,9 @@ module SchemaRegistry
80
123
  raise SchemaRegistry::InvalidResponse, "Invalid JSON in response: #{e.message}"
81
124
  end
82
125
 
126
+ when Net::HTTPInternalServerError
127
+ raise SchemaRegistry::ServerError, "Schema registy responded with a server error: #{esponse.code.to_i}"
128
+
83
129
  when Net::HTTPForbidden
84
130
  message = username.nil? ? "Unauthorized" : "User `#{username}` failed to authenticate"
85
131
  raise SchemaRegistry::UnauthorizedRequest.new(response.code.to_i, message)
@@ -1,3 +1,3 @@
1
1
  module SchemaRegistry
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: avro
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.7'
69
69
  description: Ruby client for Confluent Inc.'s schema-registry. The schema-registry
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
80
  - Gemfile
81
81
  - LICENSE.txt
82
82
  - Makefile
@@ -101,17 +101,17 @@ require_paths:
101
101
  - lib
102
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.0.14
114
+ rubygems_version: 2.5.2
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Ruby client for Confluent Inc.'s schema-registry