volcano-sdk 0.32.3 → 0.32.5
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 +4 -4
- data/lib/volcano/storage_object_response.rb +26 -4
- data/lib/volcano/transport.rb +3 -40
- data/lib/volcano/transport_json.rb +84 -0
- data/lib/volcano/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: daa3b30e5d6ef2a172ccad71ae9ace1de3d3699dd6563865c0374619d1ba619f
|
|
4
|
+
data.tar.gz: dd35800dd54f826f75cb544138a48c12b3a98a1e335dda1f3f423fda3c431ab6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3754eae91b45c73dbf26c74469d04a20290e5a493955f9484c1e37b9376075ef375d0e5fdb77c982ec11fc704a6776a806eeed909d3b2f741ff8139cf9067c8
|
|
7
|
+
data.tar.gz: 9c4aa2b75b21ff3ff9cea9380260ed8f90ee4429a85798f8beb6d7b2ae215f6c76b0152f608ff7c01d85ab8c845e498b3fbd0344eb93f995251e87a64c0ba4f9
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
3
5
|
module Volcano
|
|
4
6
|
# Validates object metadata and paginated storage responses.
|
|
5
7
|
module StorageObjectResponse
|
|
@@ -69,20 +71,40 @@ module Volcano
|
|
|
69
71
|
def storage_json_hash(value)
|
|
70
72
|
raise Error::TransportError, 'invalid storage JSON object' unless value.is_a?(Hash)
|
|
71
73
|
|
|
74
|
+
# @type var active: Hash[Integer, bool]
|
|
75
|
+
active = {}
|
|
76
|
+
copy = storage_json_container(value, active) { storage_json_entries(value, active) }
|
|
77
|
+
JSON.generate(copy)
|
|
78
|
+
copy
|
|
79
|
+
rescue JSON::GeneratorError
|
|
80
|
+
raise Error::TransportError, 'invalid storage JSON value', cause: nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def storage_json_entries(value, active)
|
|
72
84
|
value.to_h do |key, item|
|
|
73
85
|
raise Error::TransportError, 'invalid storage JSON key' unless key.is_a?(String)
|
|
74
86
|
|
|
75
|
-
[key, storage_json_value(item)]
|
|
87
|
+
[key, storage_json_value(item, active)]
|
|
76
88
|
end
|
|
77
89
|
end
|
|
78
90
|
|
|
79
|
-
def storage_json_value(value)
|
|
91
|
+
def storage_json_value(value, active)
|
|
80
92
|
case value
|
|
81
93
|
when NilClass, TrueClass, FalseClass, Integer, Float, String then value
|
|
82
|
-
when Array then value.map { |item| storage_json_value(item) }
|
|
83
|
-
when Hash then
|
|
94
|
+
when Array then storage_json_container(value, active) { value.map { |item| storage_json_value(item, active) } }
|
|
95
|
+
when Hash then storage_json_container(value, active) { storage_json_entries(value, active) }
|
|
84
96
|
else raise Error::TransportError, 'invalid storage JSON value'
|
|
85
97
|
end
|
|
86
98
|
end
|
|
99
|
+
|
|
100
|
+
def storage_json_container(value, active)
|
|
101
|
+
id = value.object_id
|
|
102
|
+
raise Error::TransportError, 'invalid storage JSON value' if active.key?(id) || active.size >= 100
|
|
103
|
+
|
|
104
|
+
active[id] = true
|
|
105
|
+
copy = yield
|
|
106
|
+
active.delete(id)
|
|
107
|
+
copy
|
|
108
|
+
end
|
|
87
109
|
end
|
|
88
110
|
end
|
data/lib/volcano/transport.rb
CHANGED
|
@@ -52,45 +52,6 @@ module Volcano
|
|
|
52
52
|
message.is_a?(String) ? message : 'Volcano request failed'
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
def self.json_value(value)
|
|
56
|
-
case value
|
|
57
|
-
when Array then value.map { |entry| json_value(entry) }
|
|
58
|
-
when Hash then json_object(value)
|
|
59
|
-
else json_scalar(value)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def self.json_object(value, message: 'Expected a JSON object')
|
|
64
|
-
raise TypeError, message unless value.is_a?(Hash)
|
|
65
|
-
|
|
66
|
-
value.to_h do |key, item|
|
|
67
|
-
raise TypeError, message unless key.is_a?(String)
|
|
68
|
-
|
|
69
|
-
[key, json_value(item)]
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def self.json_rows(value)
|
|
74
|
-
rows = json_object(value)['data']
|
|
75
|
-
raise TypeError, 'Expected database rows' unless rows.is_a?(Array)
|
|
76
|
-
|
|
77
|
-
rows.map { |row| json_object(row) }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def self.finite_float(value)
|
|
81
|
-
raise TypeError, 'Expected a finite JSON number' unless value.finite?
|
|
82
|
-
|
|
83
|
-
value
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def self.json_scalar(value)
|
|
87
|
-
case value
|
|
88
|
-
when NilClass, TrueClass, FalseClass, Integer, String then value
|
|
89
|
-
when Float then finite_float(value)
|
|
90
|
-
else raise TypeError, 'Expected a JSON response'
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
55
|
def self.error_type(status)
|
|
95
56
|
ERROR_TYPES.fetch(status) do
|
|
96
57
|
status.between?(500, 599) ? Error::ServerError : Error::VolcanoError
|
|
@@ -101,6 +62,8 @@ module Volcano
|
|
|
101
62
|
value = headers&.find { |key, _| key.casecmp?(name) }&.last
|
|
102
63
|
Integer(value, exception: false)
|
|
103
64
|
end
|
|
104
|
-
private_class_method :error_type, :integer_header, :response_error
|
|
65
|
+
private_class_method :error_type, :integer_header, :response_error
|
|
105
66
|
end
|
|
106
67
|
end
|
|
68
|
+
|
|
69
|
+
require_relative 'transport_json'
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Volcano
|
|
6
|
+
# Validates and copies JSON response values from function and database transports.
|
|
7
|
+
module Transport
|
|
8
|
+
def self.json_value(value)
|
|
9
|
+
# @type var active: Hash[Integer, bool]
|
|
10
|
+
active = {}
|
|
11
|
+
copy = json_copy(value, active)
|
|
12
|
+
validate_json_encoding(copy)
|
|
13
|
+
copy
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.json_copy(value, active)
|
|
17
|
+
case value
|
|
18
|
+
when Array then json_container(value, active) { value.map { |entry| json_copy(entry, active) } }
|
|
19
|
+
when Hash then json_hash(value, active, message: 'Expected a JSON object')
|
|
20
|
+
else json_scalar(value)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.json_object(value, message: 'Expected a JSON object')
|
|
25
|
+
# @type var active: Hash[Integer, bool]
|
|
26
|
+
active = {}
|
|
27
|
+
copy = json_hash(value, active, message:)
|
|
28
|
+
validate_json_encoding(copy)
|
|
29
|
+
copy
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.json_hash(value, active, message:)
|
|
33
|
+
raise TypeError, message unless value.is_a?(Hash)
|
|
34
|
+
|
|
35
|
+
json_container(value, active) do
|
|
36
|
+
value.to_h do |key, item|
|
|
37
|
+
raise TypeError, message unless key.is_a?(String)
|
|
38
|
+
|
|
39
|
+
[key, json_copy(item, active)]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.json_container(value, active)
|
|
45
|
+
id = value.object_id
|
|
46
|
+
raise TypeError, 'Expected a JSON response' if active.key?(id) || active.size >= 100
|
|
47
|
+
|
|
48
|
+
active[id] = true
|
|
49
|
+
copy = yield
|
|
50
|
+
active.delete(id)
|
|
51
|
+
copy
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.validate_json_encoding(value)
|
|
55
|
+
JSON.generate(value)
|
|
56
|
+
nil
|
|
57
|
+
rescue JSON::GeneratorError
|
|
58
|
+
raise TypeError, 'Expected a JSON response', cause: nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.json_rows(value)
|
|
62
|
+
rows = json_object(value)['data']
|
|
63
|
+
raise TypeError, 'Expected database rows' unless rows.is_a?(Array)
|
|
64
|
+
|
|
65
|
+
rows.map { |row| json_object(row) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.finite_float(value)
|
|
69
|
+
raise TypeError, 'Expected a finite JSON number' unless value.finite?
|
|
70
|
+
|
|
71
|
+
value
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.json_scalar(value)
|
|
75
|
+
case value
|
|
76
|
+
when NilClass, TrueClass, FalseClass, Integer, String then value
|
|
77
|
+
when Float then finite_float(value)
|
|
78
|
+
else raise TypeError, 'Expected a JSON response'
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private_class_method :json_copy, :json_hash, :json_container, :validate_json_encoding, :finite_float, :json_scalar
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/volcano/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: volcano-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.32.
|
|
4
|
+
version: 0.32.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kong
|
|
@@ -613,6 +613,7 @@ files:
|
|
|
613
613
|
- lib/volcano/storage_upload_models.rb
|
|
614
614
|
- lib/volcano/storage_upload_sessions.rb
|
|
615
615
|
- lib/volcano/transport.rb
|
|
616
|
+
- lib/volcano/transport_json.rb
|
|
616
617
|
- lib/volcano/user.rb
|
|
617
618
|
- lib/volcano/version.rb
|
|
618
619
|
- sig/auth_credentials.rbs
|