schema_registry 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema_registry/client.rb +15 -2
- data/lib/schema_registry/subject.rb +20 -5
- data/lib/schema_registry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 123c56978eca9e032fb3031fd89fad4a8845a81b
|
4
|
+
data.tar.gz: e40bb00dcccdc774a9517f38763e1dfea2e9e4f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e48444ab0c919fa9f1ed578a98b5fbfffcc6a0ef64f8c6e6dcb5dd2caf0a5911d31b94292cf7d7a94a19600cf15c16048c833c3e15f5183b0d77182f3306f1
|
7
|
+
data.tar.gz: 56063fd8b4b087ef2121dc2b202ff105b8cb1f5a22bf7f5bcd4b179a0815b1af8e12b8a06f37333f6bda344bdb3d09d80ae996bf02ba457f567e0b8d13503d2b
|
@@ -11,6 +11,16 @@ module SchemaRegistry
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
RESPONSE_ERROR_CODES = {
|
15
|
+
40401 => (SubjectNotFound = Class.new(SchemaRegistry::ResponseError)),
|
16
|
+
40402 => (VersionNotFound = Class.new(SchemaRegistry::ResponseError)),
|
17
|
+
40403 => (SchemaNotFound = Class.new(SchemaRegistry::ResponseError)),
|
18
|
+
42201 => (InvalidAvroSchema = Class.new(SchemaRegistry::ResponseError)),
|
19
|
+
42202 => (InvalidVersion = Class.new(SchemaRegistry::ResponseError)),
|
20
|
+
42203 => (InvalidCompatibilityLevel = Class.new(SchemaRegistry::ResponseError)),
|
21
|
+
409 => (IncompatibleAvroSchema = Class.new(SchemaRegistry::ResponseError)),
|
22
|
+
}
|
23
|
+
|
14
24
|
class Client
|
15
25
|
|
16
26
|
attr_reader :endpoint, :username, :password
|
@@ -62,8 +72,11 @@ module SchemaRegistry
|
|
62
72
|
response = http.request(request)
|
63
73
|
response_data = JSON.parse(response.body)
|
64
74
|
case response
|
65
|
-
|
66
|
-
|
75
|
+
when Net::HTTPSuccess;
|
76
|
+
response_data
|
77
|
+
else
|
78
|
+
error_class = RESPONSE_ERROR_CODES[response_data['error_code']] || SchemaRegistry::ResponseError
|
79
|
+
raise error_class.new(response_data['error_code'], response_data['message'])
|
67
80
|
end
|
68
81
|
end
|
69
82
|
end
|
@@ -1,5 +1,20 @@
|
|
1
1
|
module SchemaRegistry
|
2
2
|
|
3
|
+
class SchemaRegistration
|
4
|
+
attr_accessor :subject, :id, :version, :schema
|
5
|
+
|
6
|
+
def initialize(subject, options = {})
|
7
|
+
@subject = subject
|
8
|
+
@id = options['id']
|
9
|
+
@version = options['version']
|
10
|
+
@schema = options['schema']
|
11
|
+
end
|
12
|
+
|
13
|
+
def pretty_json
|
14
|
+
JSON.pretty_generate(JSON.parse(@schema))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
class Subject
|
4
19
|
attr_reader :client, :name
|
5
20
|
|
@@ -12,15 +27,15 @@ module SchemaRegistry
|
|
12
27
|
end
|
13
28
|
|
14
29
|
def version(version)
|
15
|
-
client.request(:get, "/subjects/#{name}/versions/#{version}")
|
30
|
+
SchemaRegistration.new(self, client.request(:get, "/subjects/#{name}/versions/#{version}"))
|
16
31
|
end
|
17
32
|
|
18
33
|
def verify_schema(schema_json)
|
19
|
-
client.request(:post, "/subjects/#{name}", schema: schema_json)
|
34
|
+
SchemaRegistration.new(self, client.request(:post, "/subjects/#{name}", schema: schema_json))
|
20
35
|
end
|
21
36
|
|
22
|
-
def
|
23
|
-
client.request(:post, "/subjects/#{name}/versions", schema: schema_json)[
|
37
|
+
def register_schema(schema_json)
|
38
|
+
client.request(:post, "/subjects/#{name}/versions", schema: schema_json)['id']
|
24
39
|
end
|
25
40
|
|
26
41
|
def compatibility_level
|
@@ -29,7 +44,7 @@ module SchemaRegistry
|
|
29
44
|
end
|
30
45
|
|
31
46
|
def compatibility_level=(level)
|
32
|
-
|
47
|
+
client.request(:put, "/config/#{name}", compatibility: level)
|
33
48
|
end
|
34
49
|
|
35
50
|
def compatible?(schema, version = "latest")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|