volcano-sdk 0.7.0 → 0.7.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 +4 -4
- data/README.md +4 -1
- data/lib/volcano/auth_anonymous.rb +6 -8
- data/lib/volcano/auth_email_change.rb +4 -5
- data/lib/volcano/auth_get_user.rb +10 -5
- data/lib/volcano/auth_refresh.rb +4 -4
- data/lib/volcano/auth_update_user.rb +5 -8
- data/lib/volcano/client.rb +2 -2
- data/lib/volcano/storage.rb +20 -8
- data/lib/volcano/storage_mutations.rb +11 -11
- data/lib/volcano/storage_upload_sessions.rb +10 -10
- data/lib/volcano/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b992adf24aad6b7edea16323e1f9b21c8db08cefe1380cffaf12c99ed436baf4
|
|
4
|
+
data.tar.gz: 3770340779a1a5cf0b985b6290a185223632f85863e56ab33c4f8f443ce02f0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8bd2583130b36e6ede81cdb096cfe97cff10aa9aebe8fb086cff5dd1d13c8883f6bc196b9d528c4e437fb7533df568aab7fce759d0a79f134983b825b730f9d7
|
|
7
|
+
data.tar.gz: d5118276bfe5a10d157e637643827a07586cba53d632b5f966501f3ffa9bf5562c1d1a682d8286026f0109f77b19cf701cd3a536d0fc419badf7e34e8d9f3a89
|
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Official Ruby SDK for Volcano. Requires Ruby 3.2 or later.
|
|
4
4
|
|
|
5
|
+
Start with the [Ruby quickstart](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/README.md).
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
Add the gem to your Gemfile and run `bundle install`:
|
|
@@ -487,7 +489,8 @@ syntax. Both methods require an active user session.
|
|
|
487
489
|
rows = client.database("main").from("items").select("*").eq("slug", "a").execute
|
|
488
490
|
```
|
|
489
491
|
|
|
490
|
-
Database selects, inserts, updates, deletes,
|
|
492
|
+
Database selects, inserts, updates, deletes, log reads, and authenticated storage
|
|
493
|
+
requests (including upload sessions and parts) refresh the captured
|
|
491
494
|
session after an HTTP 401 and retry the same request once. Concurrent requests reuse a successful
|
|
492
495
|
refresh for that session.
|
|
493
496
|
Replacing or signing out the session before replay, or while replay is in flight,
|
|
@@ -13,14 +13,12 @@ module Volcano
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def convert_anonymous(email:, password:, metadata: {})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
anonymous_conversion_response(
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
cache_current_user(payload, generation)
|
|
16
|
+
profile_request do
|
|
17
|
+
request_email = email.dup.freeze
|
|
18
|
+
request_password = password.dup.freeze
|
|
19
|
+
request_metadata = JSON.parse(JSON.generate(Hash(metadata)), freeze: true)
|
|
20
|
+
->(token) { anonymous_conversion_response(token, request_email, request_password, request_metadata) }
|
|
21
|
+
end
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
private
|
|
@@ -26,11 +26,10 @@ module Volcano
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def confirm_email_change(token:)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
cache_current_user(payload, generation)
|
|
29
|
+
profile_request do
|
|
30
|
+
request_token = token.dup.freeze
|
|
31
|
+
->(access_token) { confirm_email_change_response(access_token, request_token) }
|
|
32
|
+
end
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
private
|
|
@@ -15,17 +15,22 @@ module Volcano
|
|
|
15
15
|
:USER_OPTIONAL_VALUES, :USER_STATUSES, :USER_TIMESTAMPS
|
|
16
16
|
|
|
17
17
|
def user
|
|
18
|
-
|
|
19
|
-
raise Error::AuthenticationError, 'No active session' unless current
|
|
20
|
-
|
|
21
|
-
payload = Transport.body(get_user_response(current.access_token), 200)
|
|
22
|
-
cache_current_user(payload, generation)
|
|
18
|
+
profile_request { method(:get_user_response) }
|
|
23
19
|
end
|
|
24
20
|
|
|
25
21
|
alias get_user user
|
|
26
22
|
|
|
27
23
|
private
|
|
28
24
|
|
|
25
|
+
def profile_request
|
|
26
|
+
binding = @client.capture_session_binding
|
|
27
|
+
raise Error::AuthenticationError, 'No active session' unless binding.last
|
|
28
|
+
|
|
29
|
+
request = yield
|
|
30
|
+
payload = Transport.body(session_request(binding: binding, &request), 200)
|
|
31
|
+
cache_current_user(payload, owned_session_binding(binding).first)
|
|
32
|
+
end
|
|
33
|
+
|
|
29
34
|
def cache_current_user(payload, generation)
|
|
30
35
|
profile = user_payload(payload)
|
|
31
36
|
user = build_user(profile)
|
data/lib/volcano/auth_refresh.rb
CHANGED
|
@@ -10,10 +10,10 @@ module Volcano
|
|
|
10
10
|
refresh_captured_session(binding)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def session_request
|
|
14
|
-
binding = @client.capture_session_binding
|
|
13
|
+
def session_request(binding: @client.capture_session_binding)
|
|
15
14
|
raise Error::AuthenticationError, 'No active session' unless binding.last
|
|
16
15
|
|
|
16
|
+
binding = owned_session_binding(binding)
|
|
17
17
|
response = yield(binding.last.access_token)
|
|
18
18
|
return response unless response.status == 401
|
|
19
19
|
|
|
@@ -65,10 +65,10 @@ module Volcano
|
|
|
65
65
|
active = @client.capture_session_binding
|
|
66
66
|
raise Error::AuthenticationError, 'No active session' if rejected_refresh?(binding, active)
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
_, active_lineage, current = active
|
|
69
69
|
raise Error::SessionChangedError unless current && active_lineage == binding[1]
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
active
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def rejected_refresh?(binding, active)
|
|
@@ -4,14 +4,11 @@ module Volcano
|
|
|
4
4
|
# Current-user update behavior for the authentication facade.
|
|
5
5
|
class Auth
|
|
6
6
|
def update_user(password: nil, metadata: nil)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
200
|
|
13
|
-
)
|
|
14
|
-
cache_current_user(payload, generation)
|
|
7
|
+
profile_request do
|
|
8
|
+
request_password = password&.dup&.freeze
|
|
9
|
+
request_metadata = metadata.nil? ? nil : JSON.parse(JSON.generate(Hash(metadata)), freeze: true)
|
|
10
|
+
->(token) { update_user_response(token, password: request_password, metadata: request_metadata) }
|
|
11
|
+
end
|
|
15
12
|
end
|
|
16
13
|
|
|
17
14
|
private
|
data/lib/volcano/client.rb
CHANGED
data/lib/volcano/storage.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Volcano
|
|
|
28
28
|
def initialize(client, transport, name, api_url:, anon_key:)
|
|
29
29
|
@client = client
|
|
30
30
|
@transport = transport
|
|
31
|
-
@name = name
|
|
31
|
+
@name = name.dup.freeze
|
|
32
32
|
@api_url = api_url.dup.freeze
|
|
33
33
|
@anon_key = anon_key.dup.freeze
|
|
34
34
|
freeze
|
|
@@ -36,12 +36,16 @@ module Volcano
|
|
|
36
36
|
|
|
37
37
|
def upload(path, value, content_type: nil)
|
|
38
38
|
mime_type = upload_content_type(content_type)
|
|
39
|
-
|
|
39
|
+
path = storage_paths(path).first
|
|
40
|
+
binding = @client.capture_session_binding
|
|
41
|
+
@client.session_token
|
|
42
|
+
content = upload_bytes(value).freeze
|
|
43
|
+
response = storage_request(binding: binding) do |token|
|
|
40
44
|
@transport.upload_storage_object(
|
|
41
|
-
authorization:
|
|
45
|
+
authorization: token,
|
|
42
46
|
bucket_name: @name,
|
|
43
47
|
path: path,
|
|
44
|
-
data:
|
|
48
|
+
data: content,
|
|
45
49
|
content_type: mime_type
|
|
46
50
|
)
|
|
47
51
|
end
|
|
@@ -49,9 +53,11 @@ module Volcano
|
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def download(path, range: nil)
|
|
52
|
-
|
|
56
|
+
path = storage_paths(path).first
|
|
57
|
+
range = range&.dup&.freeze
|
|
58
|
+
response = storage_request do |token|
|
|
53
59
|
@transport.download_storage_object(
|
|
54
|
-
authorization:
|
|
60
|
+
authorization: token,
|
|
55
61
|
bucket_name: @name,
|
|
56
62
|
path: path,
|
|
57
63
|
byte_range: range
|
|
@@ -63,9 +69,11 @@ module Volcano
|
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
def list(prefix = '', limit: nil, cursor: nil)
|
|
66
|
-
|
|
72
|
+
prefix = prefix.dup.freeze
|
|
73
|
+
cursor = cursor&.dup&.freeze
|
|
74
|
+
response = storage_request do |token|
|
|
67
75
|
@transport.list_storage_objects(
|
|
68
|
-
authorization:
|
|
76
|
+
authorization: token,
|
|
69
77
|
bucket_name: @name,
|
|
70
78
|
prefix: prefix,
|
|
71
79
|
limit: limit,
|
|
@@ -82,6 +90,10 @@ module Volcano
|
|
|
82
90
|
|
|
83
91
|
private
|
|
84
92
|
|
|
93
|
+
def storage_request(binding: @client.capture_session_binding)
|
|
94
|
+
@client.session_request(binding: binding) { |token| Transport.invoke { yield(token) } }
|
|
95
|
+
end
|
|
96
|
+
|
|
85
97
|
def upload_content_type(value)
|
|
86
98
|
return if value.nil?
|
|
87
99
|
return value.dup.freeze if value.is_a?(String) && value.match?(/\A[\x20-\x7e]+\z/) && !value.strip.empty?
|
|
@@ -5,16 +5,16 @@ module Volcano
|
|
|
5
5
|
class StorageBucket
|
|
6
6
|
def remove(paths)
|
|
7
7
|
deleted = storage_paths(paths)
|
|
8
|
-
|
|
9
|
-
deleted.each { |path| delete_path(path,
|
|
8
|
+
binding = @client.capture_session_binding
|
|
9
|
+
deleted.each { |path| delete_path(path, binding) }
|
|
10
10
|
deleted
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def move(from_path, to_path)
|
|
14
14
|
source, destination = storage_paths([from_path, to_path])
|
|
15
|
-
response =
|
|
15
|
+
response = storage_request do |token|
|
|
16
16
|
@transport.move_storage_object(
|
|
17
|
-
authorization:
|
|
17
|
+
authorization: token,
|
|
18
18
|
bucket_name: @name,
|
|
19
19
|
from_path: source,
|
|
20
20
|
to_path: destination
|
|
@@ -25,9 +25,9 @@ module Volcano
|
|
|
25
25
|
|
|
26
26
|
def copy(from_path, to_path)
|
|
27
27
|
source, destination = storage_paths([from_path, to_path])
|
|
28
|
-
response =
|
|
28
|
+
response = storage_request do |token|
|
|
29
29
|
@transport.copy_storage_object(
|
|
30
|
-
authorization:
|
|
30
|
+
authorization: token,
|
|
31
31
|
bucket_name: @name,
|
|
32
32
|
from_path: source,
|
|
33
33
|
to_path: destination
|
|
@@ -39,9 +39,9 @@ module Volcano
|
|
|
39
39
|
def update_visibility(path, public:)
|
|
40
40
|
object_path = storage_paths(path).fetch(0)
|
|
41
41
|
visibility = visibility_value(public)
|
|
42
|
-
response =
|
|
42
|
+
response = storage_request do |token|
|
|
43
43
|
@transport.update_storage_object_visibility(
|
|
44
|
-
authorization:
|
|
44
|
+
authorization: token,
|
|
45
45
|
bucket_name: @name,
|
|
46
46
|
path: object_path,
|
|
47
47
|
is_public: visibility
|
|
@@ -61,10 +61,10 @@ module Volcano
|
|
|
61
61
|
path_list.map { |path| path.dup.freeze }.freeze
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def delete_path(path,
|
|
65
|
-
response =
|
|
64
|
+
def delete_path(path, binding)
|
|
65
|
+
response = storage_request(binding: binding) do |token|
|
|
66
66
|
@transport.delete_storage_object(
|
|
67
|
-
authorization:
|
|
67
|
+
authorization: token,
|
|
68
68
|
bucket_name: @name,
|
|
69
69
|
path: path
|
|
70
70
|
)
|
|
@@ -15,9 +15,9 @@ module Volcano
|
|
|
15
15
|
total_size: total_size,
|
|
16
16
|
part_size: part_size
|
|
17
17
|
)
|
|
18
|
-
response =
|
|
18
|
+
response = storage_request do |token|
|
|
19
19
|
@transport.create_upload_session(
|
|
20
|
-
authorization:
|
|
20
|
+
authorization: token,
|
|
21
21
|
bucket_name: @name,
|
|
22
22
|
request: request
|
|
23
23
|
)
|
|
@@ -32,9 +32,9 @@ module Volcano
|
|
|
32
32
|
part_number: part_number,
|
|
33
33
|
data: upload_bytes(data)
|
|
34
34
|
)
|
|
35
|
-
response =
|
|
35
|
+
response = storage_request do |token|
|
|
36
36
|
@transport.upload_part(
|
|
37
|
-
authorization:
|
|
37
|
+
authorization: token,
|
|
38
38
|
bucket_name: @name,
|
|
39
39
|
request: request
|
|
40
40
|
)
|
|
@@ -44,9 +44,9 @@ module Volcano
|
|
|
44
44
|
|
|
45
45
|
def complete_upload_session(path, session_id:)
|
|
46
46
|
request = UploadSessionReference.new(path: path, session_id: session_id)
|
|
47
|
-
response =
|
|
47
|
+
response = storage_request do |token|
|
|
48
48
|
@transport.complete_upload_session(
|
|
49
|
-
authorization:
|
|
49
|
+
authorization: token,
|
|
50
50
|
bucket_name: @name,
|
|
51
51
|
request: request
|
|
52
52
|
)
|
|
@@ -56,9 +56,9 @@ module Volcano
|
|
|
56
56
|
|
|
57
57
|
def get_upload_session(path, session_id:)
|
|
58
58
|
request = UploadSessionReference.new(path: path, session_id: session_id)
|
|
59
|
-
response =
|
|
59
|
+
response = storage_request do |token|
|
|
60
60
|
@transport.get_upload_session(
|
|
61
|
-
authorization:
|
|
61
|
+
authorization: token,
|
|
62
62
|
bucket_name: @name,
|
|
63
63
|
request: request
|
|
64
64
|
)
|
|
@@ -68,9 +68,9 @@ module Volcano
|
|
|
68
68
|
|
|
69
69
|
def abort_upload_session(path, session_id:)
|
|
70
70
|
request = UploadSessionReference.new(path: path, session_id: session_id)
|
|
71
|
-
response =
|
|
71
|
+
response = storage_request do |token|
|
|
72
72
|
@transport.abort_upload_session(
|
|
73
|
-
authorization:
|
|
73
|
+
authorization: token,
|
|
74
74
|
bucket_name: @name,
|
|
75
75
|
request: request
|
|
76
76
|
)
|
data/lib/volcano/version.rb
CHANGED