volcano-sdk 0.5.2 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 661418937049846fdcdec6332b897bc1b88e7359ed0b70f71e29cdd342302302
4
- data.tar.gz: 6284d21cb08cdf77ea42829fe3fcefd48b3f741b9c49ad71665249a63c941e17
3
+ metadata.gz: e1c358710803cb0542775a53699fda168e00aa0292d6fe0861287d4175373ecb
4
+ data.tar.gz: a1e9f5146e6fd06d956ff7a505f391a72eef8b65cc3a4cf39ae4599a9e1346a5
5
5
  SHA512:
6
- metadata.gz: 6acc1b7db432a0e7a33bffe77a8a7463e0c9b063049f0807327bcafd9e1e7f44bd2f5a973bb905705598254a2c51b5cc86abd403a357516eda3659c0a885fb6c
7
- data.tar.gz: f582e4a361354e3e41a1988a423260638770543dc1c268dbb99f37d42ee7b13e2a373ae4872af7fa994a729cc33e8aaad9a1cfd3ecde8aa6b2cdf57f1f3569e9
6
+ metadata.gz: e5a1dd2cf0df583e5b02d954aeaaa9c63f4d122658605dbf78dac8a4d6f9fade33422742fc54c6f8dae6d22b4019d91aac73519beb2de83913bc4a27cfe160a9
7
+ data.tar.gz: 6939426bd9514b8fe97c8e413c61c04acb1559efbcc33afbcf8e6102ac6b09aa96ecc7369859465b1b8f897ce4fe47d8d329ea4ea6fcdaf5aeaa7f52915e444e
data/README.md CHANGED
@@ -1,9 +1,23 @@
1
1
  # Volcano Ruby SDK
2
2
 
3
- Official Ruby SDK for Volcano. This repository is a private proof of concept;
4
- the gem is not published yet.
3
+ Official Ruby SDK for Volcano. Requires Ruby 3.2 or later.
5
4
 
6
- ## Proof-of-concept API
5
+ ## Install
6
+
7
+ Add the gem to your Gemfile and run `bundle install`:
8
+
9
+ ```ruby
10
+ gem "volcano-sdk"
11
+ ```
12
+
13
+ Require it with `require "volcano"`. New versions publish to RubyGems
14
+ automatically after a Release Please release PR merges and the release checks
15
+ pass.
16
+
17
+ Maintainers: see [Publishing releases](https://github.com/Kong/volcano-sdk-ruby/blob/main/PUBLISHING.md) for trusted publisher setup
18
+ and the release procedure.
19
+
20
+ ## Create a client
7
21
 
8
22
  Create a client with the project URL and anonymous key from Volcano:
9
23
 
@@ -55,6 +69,17 @@ raise "session changed" unless current_session == session
55
69
  `current_session` reads immutable local state. It does not refresh or validate
56
70
  the token.
57
71
 
72
+ Sessions returned by authentication retain the user payload in `session.user`,
73
+ including metadata. The snapshot is deeply immutable and available without a
74
+ request. It is cached data, not proof of authentication; use `auth.user` to fetch
75
+ the server-validated profile. Existing three-field `Session` construction still
76
+ works, with `user: nil`. An adopted snapshot must have the same user ID.
77
+ Snapshots contain deeply frozen JSON data. Plain `Time` timestamps become UTC
78
+ ISO8601 strings with nanosecond precision; symbols become strings. Custom objects,
79
+ container/string/time subclasses, non-finite numbers, duplicate JSON keys, and
80
+ structures deeper than 100 levels raise `TypeError`. Use the typed `auth.user`
81
+ profile when you need Ruby `Time` values.
82
+
58
83
  ### Get the current user
59
84
 
60
85
  ```ruby
@@ -414,7 +439,11 @@ result = client.functions.invoke(
414
439
  puts [result.status, result.version, result.data]
415
440
  ```
416
441
 
417
- `invoke` resolves a DNS-safe function name and sends a JSON object. It uses the
442
+ `invoke` resolves a DNS-safe function name and sends a JSON object. The request
443
+ goes to the function's own domain rather than to `api_url`, so an egress rule
444
+ that allows only the API host will block it; the resolved endpoint is cached for
445
+ the lifetime the platform gives it. Deployments with no public function domain
446
+ invoke through the API host instead. It uses the
418
447
  active user session when present, then a configured service key, then the
419
448
  anonymous key. An anonymous key can invoke a public function without a user
420
449
  session; the function receives no user identity. The immutable result includes
data/lib/volcano/auth.rb CHANGED
@@ -86,14 +86,21 @@ module Volcano
86
86
  owned_session(
87
87
  access_token: payload.fetch('access_token'),
88
88
  refresh_token: payload.fetch('refresh_token'),
89
- user_id: payload.fetch('user').fetch('id')
89
+ user_id: payload.fetch('user').fetch('id'),
90
+ user: payload.fetch('user')
90
91
  )
91
92
  end
92
93
 
93
94
  def complete_session?(session)
94
95
  return false unless session.is_a?(Session)
95
96
 
96
- session.to_h.values.all? { |value| value.is_a?(String) && !value.strip.empty? }
97
+ values = [session.access_token, session.refresh_token, session.user_id]
98
+ values.all? { |value| value.is_a?(String) && !value.strip.empty? } &&
99
+ matching_session_user?(session)
100
+ end
101
+
102
+ def matching_session_user?(session)
103
+ session.user.nil? || (session.user.is_a?(Hash) && session.user['id'] == session.user_id)
97
104
  end
98
105
 
99
106
  def owned_complete_session(session)
@@ -102,11 +109,12 @@ module Volcano
102
109
  owned_session(**session.to_h)
103
110
  end
104
111
 
105
- def owned_session(access_token:, refresh_token:, user_id:)
112
+ def owned_session(access_token:, refresh_token:, user_id:, user: nil)
106
113
  Session.new(
107
114
  access_token: access_token.dup.freeze,
108
115
  refresh_token: refresh_token.dup.freeze,
109
- user_id: user_id.dup.freeze
116
+ user_id: user_id.dup.freeze,
117
+ user: user
110
118
  )
111
119
  end
112
120
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- Session = Data.define(:access_token, :refresh_token, :user_id)
5
4
  AUTH_SESSION_ATTRIBUTES = %i[
6
5
  id user_id provider expires_at is_active is_current user_agent ip_address last_ip_address
7
6
  last_activity_at session_started_at created_at updated_at
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'time'
5
+
6
+ module Volcano
7
+ SESSION_USER_CODER = JSON::Coder.new(freeze: true, allow_duplicate_key: false) do |value|
8
+ value.instance_of?(Time) ? Time.at(value.to_r).utc.iso8601(9) : value
9
+ end
10
+ private_constant :SESSION_USER_CODER
11
+
12
+ # In-memory credentials with an optional, unverified local user snapshot.
13
+ Session = Data.define(:access_token, :refresh_token, :user_id, :user) do
14
+ def initialize(access_token:, refresh_token:, user_id:, user: nil)
15
+ super(access_token:, refresh_token:, user_id:, user: immutable_user(user))
16
+ end
17
+
18
+ private
19
+
20
+ def immutable_user(value)
21
+ SESSION_USER_CODER.load(SESSION_USER_CODER.dump(value))
22
+ rescue JSON::GeneratorError, JSON::NestingError
23
+ raise TypeError, 'Session user snapshot must contain JSON values or timestamps', cause: nil
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- VERSION = '0.5.2'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/volcano.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'volcano/version'
4
4
  require_relative 'volcano/connection_string'
5
5
  require_relative 'volcano/models'
6
+ require_relative 'volcano/session'
6
7
  require_relative 'volcano/function_response'
7
8
  require_relative 'volcano/log_responses'
8
9
  require_relative 'volcano/storage_models'
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kong
@@ -51,6 +51,34 @@ dependencies:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.30.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: base64
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.2'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: json
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.17'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.17'
54
82
  - !ruby/object:Gem::Dependency
55
83
  name: logger
56
84
  requirement: !ruby/object:Gem::Requirement
@@ -546,6 +574,7 @@ files:
546
574
  - lib/volcano/realtime/protocol_recovery_position.rb
547
575
  - lib/volcano/realtime/reconnect.rb
548
576
  - lib/volcano/redaction.rb
577
+ - lib/volcano/session.rb
549
578
  - lib/volcano/sign_up_result.rb
550
579
  - lib/volcano/storage.rb
551
580
  - lib/volcano/storage_models.rb