volcano-sdk 0.35.1 → 0.36.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: 9bc53fe0031fedb1b85c60946ec98c92a47a26267e75833a665c86cac7185885
4
- data.tar.gz: 885ff240ad177e3a45612c1a2edc3e347d4803a53f13c0b50094701b57668b51
3
+ metadata.gz: 570b92c882eb5fdf5d8273c7eac36133f75cb87c7d3a7d3227bc0c76e1da33c7
4
+ data.tar.gz: 4086cfd1a3f9346dde7d95a9adaae3b2c80b0bea1751faaf4174fc7d19f60cad
5
5
  SHA512:
6
- metadata.gz: 1f7007d35cef25585d0e0af0fec22015e644f454b4c574579d4a82ea488e5a6d3d9a44cdd711590ce5f9a5d7fc17c70c500da3a75ae6876bbbd5870cafb687e9
7
- data.tar.gz: 06eafce9b7e78def2c7c881dfaad4c757adb30a7defea52166f5025381aebd570ab7a9308e038901acfb0fabe174f48c8e20f188eb313b06891a87c29dedfdd3
6
+ metadata.gz: 2dc85974d39abedc1e63dddd648cfd248be4f1fbb99fe489c69a3514d21d17885a84201f589a460a65567602b9b053b12edef240c86385b7239873dcd3e9bc87
7
+ data.tar.gz: 76fd85b2073b9f32d3bedb2b9ddb4dc89b0a873e5bbe28003ba0c61580c7d6ba403e0fad6e0854d725fbcd6ab9e6090a0a34f035681cf51300dea291b66c2a20
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Official Ruby SDK for Volcano. Requires Ruby 3.3 or later.
4
4
 
5
- Start with the [Ruby quickstart](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/README.md).
5
+ Start with the [Ruby quickstart](https://docs.volcano.dev/sdk/ruby).
6
6
 
7
- See [Authentication](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/authentication.md) for account, session, email, and OAuth workflows.
7
+ See [Authentication](https://docs.volcano.dev/sdk/ruby/authentication) for account, session, email, and OAuth workflows.
8
8
 
9
9
  ## Install
10
10
 
@@ -393,7 +393,7 @@ without changing credentials. Without a refresh token, `refresh_session` raises
393
393
  `Volcano::Error::AuthenticationError`. `sign_out` clears local state and revokes the server
394
394
  session when the access JWT contains a readable UUID `session_id`. Supplied credentials require both a refresh token and an access JWT with a readable UUID
395
395
  `session_id` to enable refresh.
396
- See the [token bootstrap example](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/README.md#use-a-supplied-access-token).
396
+ See the [token bootstrap example](https://docs.volcano.dev/sdk/ruby#use-a-supplied-access-token).
397
397
 
398
398
  ### Adopt an existing session
399
399
 
@@ -493,25 +493,61 @@ prevents replay under another identity. The call preserves its original payload
493
493
  A function's own response, HTTP 403, or a network failure never triggers this retry.
494
494
  Anonymous and service keys do not refresh.
495
495
 
496
- See the [functions guide](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/functions.md).
496
+ See the [functions guide](https://docs.volcano.dev/sdk/ruby/functions).
497
497
 
498
498
  ### Start and follow a durable execution
499
499
 
500
500
  ```ruby
501
- project_id = "00000000-0000-4000-8000-000000000001"
502
501
  handle = client.durable.start(
503
502
  "charge-order",
504
503
  { order_id: "order-9" },
505
504
  execution_name: "order-9"
506
505
  )
506
+ token = handle.client_token
507
+
508
+ execution = client.durable.get_from_application("charge-order", handle.id, client_token: token)
509
+ puts [execution.status, execution.terminal?, execution.result]
510
+
511
+ client.durable.stop_from_application("charge-order", handle.id, client_token: token)
512
+ ```
513
+
514
+ `start` takes a durable function's name or its id and returns a handle, never a
515
+ result: an execution can run for up to 366 days, so its result is read back with
516
+ `get_from_application`. `start`, `get_from_application`, and
517
+ `stop_from_application` use the same credential `invoke` does — the active user
518
+ session, then a configured service key, then the anonymous key. An
519
+ `execution_name` makes the start idempotent: starting again under the same name
520
+ returns the execution that already exists rather than beginning a second one.
521
+ Only the start that creates the execution returns its `client_token`; reads
522
+ never return it.
523
+
524
+ A service key holding `*`, the default, reads and stops any execution of the
525
+ project. A signed-in user reaches the executions they started without the
526
+ client token. An anonymous key, a user who did not start the execution, or a
527
+ service key scoped to a list without `*` passes `client_token:`. An anonymous
528
+ key or a service key scoped without `*` also needs `functions.invoke`; without it
529
+ the call raises `Volcano::Error::PermissionDeniedError`. The function's
530
+ visibility must also admit the credential: an anonymous key on an
531
+ `authenticated` function raises `Volcano::Error::PermissionDeniedError`, even
532
+ with the token, and a `private` function raises `Volcano::Error::NotFoundError`
533
+ for every credential but a service key. An execution the credential cannot
534
+ reach raises `Volcano::Error::NotFoundError`, as a missing one does, and so does
535
+ one still `pending` unless the credential is a service key holding `*`. A stop
536
+ answered with a `503` `Volcano::Error::ServerError` may already have been sent,
537
+ so read the execution before stopping it again.
538
+
539
+ Tooling that manages a project reads, lists, and stops executions with the
540
+ owner-scoped `get`, `list`, and `stop`, which reach any execution without a
541
+ client token:
507
542
 
543
+ ```ruby
544
+ project_id = "00000000-0000-4000-8000-000000000001"
508
545
  owner_client = Volcano::Client.new(
509
546
  api_url: "https://api.volcano.dev",
510
547
  anon_key: ENV.fetch("VOLCANO_ANON_KEY"),
511
548
  access_token: ENV.fetch("VOLCANO_PLATFORM_TOKEN")
512
549
  )
513
550
  execution = owner_client.durable.get(project_id, "charge-order", handle.id)
514
- puts [execution.status, execution.terminal?, execution.result]
515
551
 
516
552
  page = owner_client.durable.list(project_id, "charge-order", status: "running")
517
553
  puts [page.total, page.has_more]
@@ -519,29 +555,19 @@ puts [page.total, page.has_more]
519
555
  owner_client.durable.stop(project_id, "charge-order", handle.id)
520
556
  ```
521
557
 
522
- `start` takes a durable function's name or its id and returns a handle, never a
523
- result: an execution can run for up to 366 days, so its result is read back with `get`.
524
- It uses the same credential `invoke` does — the active user session, then a
525
- configured service key, then the anonymous key — and is, with `messages`, the
526
- only durable operation an application credential may perform. An
527
- `execution_name` makes the start idempotent: starting again under the same name
528
- returns the execution that already exists rather than beginning a second one.
529
- Only the start that creates the execution returns its `client_token`.
530
-
531
- `get`, `list`, and `stop` are owner-scoped and require the project owner's
532
- platform user token or a project access token, because an execution is
533
- addressed by its id alone. A `read_only` project access token can read and list
534
- but not stop. Auth-user sessions, anonymous keys, and service keys are not
535
- accepted. `get` carries the deeply
536
- frozen `result` once the execution has succeeded, and `error` when it failed;
537
- `result_expired` separates a result the platform has discarded from a function
538
- that returned nothing. `terminal?` reports whether the execution has stopped
539
- changing, and counts `unknown` — the status the platform writes for an outcome
540
- it could not determine — as finished. `list` returns one page of executions,
541
- most recent first, each carrying the status last observed rather than a live
542
- one. `stop` is accepted rather than awaited: what it returns is the execution
543
- read back after asking, often still `running`, so poll `get` to see it reach
544
- `stopped`. Repeating a stop is safe.
558
+ They require the project owner's platform user token or a project access token.
559
+ A `read_only` project access token can read and list but not stop. Auth-user
560
+ sessions, anonymous keys, and service keys are not accepted.
561
+
562
+ Either read carries the deeply frozen `result` once the execution has succeeded,
563
+ and `error` when it failed; `result_expired` separates a result the platform has
564
+ discarded from a function that returned nothing. `terminal?` reports whether the
565
+ execution has stopped changing, and counts `unknown` — the status the platform
566
+ writes for an outcome it could not determine — as finished. `list` returns one
567
+ page of executions, most recent first, each carrying the status last observed
568
+ rather than a live one. A stop is accepted rather than awaited: what it returns
569
+ is the execution read back after asking, often still `running`, so poll a read
570
+ to see it reach `stopped`. Repeating a stop is safe.
545
571
 
546
572
  This gem starts and follows durable executions; it cannot write the durable
547
573
  function itself. Checkpointing a handler needs a durable authoring API, and
@@ -654,7 +680,7 @@ they started; the anon key, or another user, passes the execution's
654
680
  `client_token:`, which only the creating start returns. Pass `project_id:` to
655
681
  `send_message`, `list`, or `subscribe` to use the owner's route with a platform
656
682
  user token or a project access token; `subscribe` reads back over it. See the
657
- [functions guide](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/functions.md#message-a-durable-execution).
683
+ [functions guide](https://docs.volcano.dev/sdk/ruby/functions#message-a-durable-execution).
658
684
 
659
685
  ### Read project logs
660
686
 
@@ -682,7 +708,7 @@ events. Pass `next_cursor` back as `cursor` to continue a search. `activity`
682
708
  returns immutable time buckets using the same resource selector and query
683
709
  syntax. Both methods require a platform user token or a project access token.
684
710
  A `read_only` project token is sufficient; end-user sessions cannot read project logs.
685
- See the [logs guide](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/logs.md).
711
+ See the [logs guide](https://docs.volcano.dev/sdk/ruby/logs).
686
712
 
687
713
  ### Query a database
688
714
 
@@ -864,7 +890,7 @@ Acquisition accepts caller-owned UUID `token` and `request_id` values and retrie
864
890
  an ambiguous transport failure or HTTP 503 once with the same request and credential.
865
891
  Retain those IDs to recover an uncertain acquisition. Other lock methods accept
866
892
  `request_id`; block-scoped helpers forward initial IDs only to acquisition.
867
- See the [lock guide](https://github.com/Kong/volcano-sdk-ruby/blob/main/docs/locks.md)
893
+ See the [lock guide](https://docs.volcano.dev/sdk/ruby/locks)
868
894
  for examples and fencing requirements.
869
895
 
870
896
  `locks.get` returns immutable lock availability, expiry, and fencing-token
@@ -1013,7 +1039,7 @@ The internal REST transport is generated from `openapi/openapi.yaml`, which
1013
1039
  matches the public bundle from [Hosting #991](https://github.com/Kong/volcano-hosting/pull/991)
1014
1040
  at commit `ef03f689e`.
1015
1041
  Its SHA-256 is `076d97809c95f50567d8b100f4188c1fe2b74e73a388e335c79850e66edfc0e4`.
1016
- Generation uses `@openapitools/openapi-generator-cli` 2.41.0 with OpenAPI
1042
+ Generation uses `@openapitools/openapi-generator-cli` 2.42.2 with OpenAPI
1017
1043
  Generator 7.17.0. Node is used only to regenerate the committed client and is
1018
1044
  not a gem runtime dependency.
1019
1045
 
@@ -10,7 +10,7 @@ module Volcano
10
10
  private_constant :HOSTED_AUTH_ACTIONS
11
11
 
12
12
  def get_hosted_auth_url(project_id:, state:, action: 'login')
13
- project = hosted_auth_parameter(project_id).strip
13
+ project = PathSegments.check_identifier!(hosted_auth_parameter(project_id).strip, 'project_id')
14
14
  auth_state = hosted_auth_parameter(state)
15
15
  raise ArgumentError, 'Unsupported hosted auth action' unless HOSTED_AUTH_ACTIONS.include?(action)
16
16
 
@@ -7,6 +7,7 @@ module Volcano
7
7
  # contract so a refusal is the facade's rather than the generated client's.
8
8
  EXECUTION_NAME = /\A[A-Za-z0-9._-]{1,255}\z/
9
9
  include DurableArguments
10
+ include DurableMessageArguments
10
11
  include DurableResponses
11
12
 
12
13
  # Lists, reads, and decides the approvals durable workflows request.
@@ -24,14 +25,14 @@ module Volcano
24
25
 
25
26
  # Starts an execution and returns its handle. A durable function is never
26
27
  # invoked synchronously: it can outlive any request a caller could hold
27
- # open, so its result is read back with #get.
28
+ # open, so its result is read back with #get_from_application or #get.
28
29
  #
29
- # Starting takes the token an invoke takes, and is, with #messages, the
30
- # only durable operation an application credential may perform. Passing an
31
- # +execution_name+ makes the start idempotent: starting again under the
32
- # same name returns the execution that already exists rather than
33
- # beginning a second one. Only the start that created the execution
34
- # returns its +client_token+.
30
+ # Starting takes the token an invoke takes. Passing an +execution_name+
31
+ # makes the start idempotent: starting again under the same name returns
32
+ # the execution that already exists rather than beginning a second one.
33
+ # Only the start that created the execution returns its +client_token+;
34
+ # keep it where #get_from_application, #stop_from_application, and
35
+ # #messages need it.
35
36
  def start(function_name, payload = {}, execution_name: nil)
36
37
  # A durable function's id is accepted here as well as its name, so the
37
38
  # DNS-safe name pattern an invoke checks would reject half the input.
@@ -47,12 +48,55 @@ module Volcano
47
48
  durable_execution(Transport.body(response, 202))
48
49
  end
49
50
 
51
+ # Reads an execution with the credential #start uses, including its result
52
+ # once it has succeeded. The function's visibility must admit the
53
+ # credential. A service key holding `*`, the default, reaches any
54
+ # execution of the project. A signed-in user reaches the executions they
55
+ # started. An anon key, a user who did not start the execution, or a
56
+ # service key scoped to a list without `*` passes the +client_token+ its
57
+ # start returned; it is sent with whichever credential is in use. An anon
58
+ # key or a service key scoped without `*` also needs `functions.invoke`;
59
+ # without it the call raises Error::PermissionDeniedError. An anon key on
60
+ # an +authenticated+ function raises Error::PermissionDeniedError too, even
61
+ # with the token, and a +private+ function raises Error::NotFoundError for
62
+ # every credential but a service key. An execution the credential cannot
63
+ # reach, or one still +pending+ for any credential but a service key
64
+ # holding `*`, raises Error::NotFoundError, as a missing one does.
65
+ def get_from_application(function_name, execution_id, client_token: nil)
66
+ function_id, execution, token = application_target(function_name, execution_id, client_token)
67
+ response = Transport.invoke do
68
+ @transport.get_durable_execution_from_application(
69
+ authorization: @client.function_token,
70
+ function_id: function_id, execution_id: execution, client_token: token
71
+ )
72
+ end
73
+ durable_execution(Transport.body(response, 200))
74
+ end
75
+
76
+ # Asks a running execution to stop, with the credential and +client_token+
77
+ # #get_from_application takes. Accepted rather than awaited, as #stop is:
78
+ # poll #get_from_application to see it reach +stopped+. Only a service key
79
+ # holding `*` reaches an execution still +pending+, and stopping one raises
80
+ # Error::ConflictError. A stop answered with a 503 Error::ServerError may
81
+ # already have been sent, so read the execution before stopping again.
82
+ def stop_from_application(function_name, execution_id, client_token: nil)
83
+ function_id, execution, token = application_target(function_name, execution_id, client_token)
84
+ response = Transport.invoke do
85
+ @transport.stop_durable_execution_from_application(
86
+ authorization: @client.function_token,
87
+ function_id: function_id, execution_id: execution, client_token: token
88
+ )
89
+ end
90
+ durable_execution(Transport.body(response, 200))
91
+ end
92
+
50
93
  # Reads an execution, including its result once it has succeeded.
51
94
  #
52
- # Owner-scoped: an execution is addressed by its id alone, so this takes
53
- # the project id and the project owner's platform user token or a project
54
- # access token. Auth-user sessions, anon keys, and service keys are not
55
- # accepted. Poll it from a backend, not a browser.
95
+ # Owner-scoped: this takes the project id and the project owner's platform
96
+ # user token or a project access token, and reaches any execution of the
97
+ # project without a client token. Auth-user sessions, anon keys, and
98
+ # service keys are not accepted; an application reads its executions with
99
+ # #get_from_application instead.
56
100
  def get(project_id, function_name, execution_id)
57
101
  project, function_id, execution = execution_path(project_id, function_name, execution_id)
58
102
  response = Transport.invoke do
@@ -85,7 +129,8 @@ module Volcano
85
129
  # comes back is the execution read after asking, and it often still says
86
130
  # +running+, so poll #get to see it reach +stopped+. Completed steps are
87
131
  # not undone, and repeating a stop is safe — an execution that has already
88
- # finished reports the state it settled in. Owner-scoped, like #get.
132
+ # finished reports the state it settled in. Owner-scoped, like #get; an
133
+ # application stops its executions with #stop_from_application.
89
134
  def stop(project_id, function_name, execution_id)
90
135
  project, function_id, execution = execution_path(project_id, function_name, execution_id)
91
136
  response = Transport.invoke do
@@ -107,6 +152,11 @@ module Volcano
107
152
  ]
108
153
  end
109
154
 
155
+ def application_target(function_name, execution_id, client_token)
156
+ [identifier(function_name, 'function_name'), identifier(execution_id, 'execution_id'),
157
+ bounded_text(client_token, 'client_token', MAX_CLIENT_TOKEN_LENGTH)]
158
+ end
159
+
110
160
  def execution_name_argument(value)
111
161
  name = identifier(value, 'execution_name')
112
162
  unless EXECUTION_NAME.match?(name)
@@ -739,6 +739,82 @@ module Volcano::Generated
739
739
  return data, status_code, headers
740
740
  end
741
741
 
742
+ # Get a durable execution from an application
743
+ # Returns the execution's current state with the credential that started it, including its `result` once it has succeeded. Poll this to wait for an execution to finish. **With a service key:** any execution in the project when the key holds `*`, the default. A key scoped to a list without `*` reaches an execution whose `X-Volcano-Client-Token` the request carries, as an anon key does; the start returns that token. **With an auth user token:** an execution the user started, or one whose `X-Volcano-Client-Token` the request carries, of a durable function whose `visibility` is `authenticated` or `public`. **With an anon key:** an execution whose `X-Volcano-Client-Token` the request carries, of a function with `visibility: public`. Only a service key holding `*` reaches an execution that is still `pending`. Any other execution answers `404`, as a missing one does. The response is the one `GET /projects/{id}/durable-functions/{functionId}/executions/{executionId}` returns. It never carries `client_token`.
744
+ # @param function_id [String] Durable function ID, or its name within the project
745
+ # @param execution_id [String] Durable execution ID
746
+ # @param [Hash] opts the optional parameters
747
+ # @option opts [String] :x_volcano_client_token The `client_token` the execution's start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without `*` read and stop it.
748
+ # @return [DurableExecution]
749
+ def get_durable_execution_from_application(function_id, execution_id, opts = {})
750
+ data, _status_code, _headers = get_durable_execution_from_application_with_http_info(function_id, execution_id, opts)
751
+ data
752
+ end
753
+
754
+ # Get a durable execution from an application
755
+ # Returns the execution's current state with the credential that started it, including its `result` once it has succeeded. Poll this to wait for an execution to finish. **With a service key:** any execution in the project when the key holds `*`, the default. A key scoped to a list without `*` reaches an execution whose `X-Volcano-Client-Token` the request carries, as an anon key does; the start returns that token. **With an auth user token:** an execution the user started, or one whose `X-Volcano-Client-Token` the request carries, of a durable function whose `visibility` is `authenticated` or `public`. **With an anon key:** an execution whose `X-Volcano-Client-Token` the request carries, of a function with `visibility: public`. Only a service key holding `*` reaches an execution that is still `pending`. Any other execution answers `404`, as a missing one does. The response is the one `GET /projects/{id}/durable-functions/{functionId}/executions/{executionId}` returns. It never carries `client_token`.
756
+ # @param function_id [String] Durable function ID, or its name within the project
757
+ # @param execution_id [String] Durable execution ID
758
+ # @param [Hash] opts the optional parameters
759
+ # @option opts [String] :x_volcano_client_token The `client_token` the execution's start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without `*` read and stop it.
760
+ # @return [Array<(DurableExecution, Integer, Hash)>] DurableExecution data, response status code and response headers
761
+ def get_durable_execution_from_application_with_http_info(function_id, execution_id, opts = {})
762
+ if @api_client.config.debugging
763
+ @api_client.config.logger.debug 'Calling API: DurableFunctionsApi.get_durable_execution_from_application ...'
764
+ end
765
+ # verify the required parameter 'function_id' is set
766
+ if @api_client.config.client_side_validation && function_id.nil?
767
+ fail ArgumentError, "Missing the required parameter 'function_id' when calling DurableFunctionsApi.get_durable_execution_from_application"
768
+ end
769
+ # verify the required parameter 'execution_id' is set
770
+ if @api_client.config.client_side_validation && execution_id.nil?
771
+ fail ArgumentError, "Missing the required parameter 'execution_id' when calling DurableFunctionsApi.get_durable_execution_from_application"
772
+ end
773
+ if @api_client.config.client_side_validation && !opts[:'x_volcano_client_token'].nil? && opts[:'x_volcano_client_token'].to_s.length > 128
774
+ fail ArgumentError, 'invalid value for "opts[:"x_volcano_client_token"]" when calling DurableFunctionsApi.get_durable_execution_from_application, the character length must be smaller than or equal to 128.'
775
+ end
776
+
777
+ # resource path
778
+ local_var_path = '/durable-functions/{functionId}/executions/{executionId}'.sub('{' + 'functionId' + '}', CGI.escape(function_id.to_s)).sub('{' + 'executionId' + '}', CGI.escape(execution_id.to_s))
779
+
780
+ # query parameters
781
+ query_params = opts[:query_params] || {}
782
+
783
+ # header parameters
784
+ header_params = opts[:header_params] || {}
785
+ # HTTP header 'Accept' (if needed)
786
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
787
+ header_params[:'X-Volcano-Client-Token'] = opts[:'x_volcano_client_token'] if !opts[:'x_volcano_client_token'].nil?
788
+
789
+ # form parameters
790
+ form_params = opts[:form_params] || {}
791
+
792
+ # http body (model)
793
+ post_body = opts[:debug_body]
794
+
795
+ # return_type
796
+ return_type = opts[:debug_return_type] || 'DurableExecution'
797
+
798
+ # auth_names
799
+ auth_names = opts[:debug_auth_names] || ['ServiceRoleKey', 'AuthUserAccessToken', 'AnonKey']
800
+
801
+ new_options = opts.merge(
802
+ :operation => :"DurableFunctionsApi.get_durable_execution_from_application",
803
+ :header_params => header_params,
804
+ :query_params => query_params,
805
+ :form_params => form_params,
806
+ :body => post_body,
807
+ :auth_names => auth_names,
808
+ :return_type => return_type
809
+ )
810
+
811
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
812
+ if @api_client.config.debugging
813
+ @api_client.config.logger.debug "API called: DurableFunctionsApi#get_durable_execution_from_application\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
814
+ end
815
+ return data, status_code, headers
816
+ end
817
+
742
818
  # Get durable function by ID or name
743
819
  # @param id [String] Project ID
744
820
  # @param function_id [String] Durable function ID, or its name within the project
@@ -1582,7 +1658,7 @@ module Volcano::Generated
1582
1658
  # @param function_id [String] Durable function ID, or its name within the project
1583
1659
  # @param execution_id [String] Durable execution ID
1584
1660
  # @param [Hash] opts the optional parameters
1585
- # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it.
1661
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
1586
1662
  # @option opts [DurableMessageDirection] :direction Return only messages travelling this way.
1587
1663
  # @option opts [String] :name Return only messages with this name.
1588
1664
  # @option opts [Integer] :after Return only messages whose &#x60;seq&#x60; is greater than this. (default to 0)
@@ -1598,7 +1674,7 @@ module Volcano::Generated
1598
1674
  # @param function_id [String] Durable function ID, or its name within the project
1599
1675
  # @param execution_id [String] Durable execution ID
1600
1676
  # @param [Hash] opts the optional parameters
1601
- # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it.
1677
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
1602
1678
  # @option opts [DurableMessageDirection] :direction Return only messages travelling this way.
1603
1679
  # @option opts [String] :name Return only messages with this name.
1604
1680
  # @option opts [Integer] :after Return only messages whose &#x60;seq&#x60; is greater than this. (default to 0)
@@ -2092,7 +2168,7 @@ module Volcano::Generated
2092
2168
  # @param send_durable_message_request [SendDurableMessageRequest]
2093
2169
  # @param [Hash] opts the optional parameters
2094
2170
  # @option opts [String] :idempotency_key Makes a send safe to retry. A repeat with a key the same sender has used on the execution returns the first message and sends nothing. Keys of different senders never collide. Up to 255 characters.
2095
- # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it.
2171
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
2096
2172
  # @return [DurableMessage]
2097
2173
  def send_durable_message_from_application(function_id, execution_id, send_durable_message_request, opts = {})
2098
2174
  data, _status_code, _headers = send_durable_message_from_application_with_http_info(function_id, execution_id, send_durable_message_request, opts)
@@ -2106,7 +2182,7 @@ module Volcano::Generated
2106
2182
  # @param send_durable_message_request [SendDurableMessageRequest]
2107
2183
  # @param [Hash] opts the optional parameters
2108
2184
  # @option opts [String] :idempotency_key Makes a send safe to retry. A repeat with a key the same sender has used on the execution returns the first message and sends nothing. Keys of different senders never collide. Up to 255 characters.
2109
- # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it.
2185
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
2110
2186
  # @return [Array<(DurableMessage, Integer, Hash)>] DurableMessage data, response status code and response headers
2111
2187
  def send_durable_message_from_application_with_http_info(function_id, execution_id, send_durable_message_request, opts = {})
2112
2188
  if @api_client.config.debugging
@@ -2272,7 +2348,7 @@ module Volcano::Generated
2272
2348
  end
2273
2349
 
2274
2350
  # Start a durable execution from an application
2275
- # Starts an execution of a durable function using an application credential, and returns its handle. This is the durable counterpart of `POST /functions/{functionId}/invoke`, and it is the endpoint an application calls. Like that one, it is not project-scoped: an anon key, a service key and an auth user token each carry their own project. The project-scoped collection under `/projects/{id}/durable-functions/...` remains the owner's management surface. **With a service key:** any durable function in the project. **With an auth user token:** a durable function whose `visibility` is `authenticated` or `public`. **With an anon key:** requires the `functions.invoke` permission, and the function must have `visibility: public`. A `private` durable function answers every credential but a service key exactly as a missing one, with 404. Starting is all this endpoint does. Reading a result or stopping an execution requires the project owner's token, because an anon key is shared by everyone who loads the page and an execution is addressed by id alone. Send `X-Volcano-Execution-Name` to make the start idempotent: repeating a start with the same name returns the existing execution instead of beginning a second one. Each execution counts once against the project's durable execution allowance, however many times the start is retried under the same execution name, and the number in flight at once is capped by the plan. The operations the execution performs are counted against the durable operations allowance when it finishes.
2351
+ # Starts an execution of a durable function using an application credential, and returns its handle. This is the durable counterpart of `POST /functions/{functionId}/invoke`, and it is the endpoint an application calls. Like that one, it is not project-scoped: an anon key, a service key and an auth user token each carry their own project. The project-scoped collection under `/projects/{id}/durable-functions/...` remains the owner's management surface. **With a service key:** any durable function in the project. **With an auth user token:** a durable function whose `visibility` is `authenticated` or `public`. **With an anon key:** requires the `functions.invoke` permission, and the function must have `visibility: public`. A `private` durable function answers every credential but a service key exactly as a missing one, with 404. The start returns a `client_token`. An anon key, or a user who did not start the execution, sends it as `X-Volcano-Client-Token` to read the execution, stop it, and reach its messages. A service key scoped to a list without `*` sends it to read and stop the execution. An anon key is shared by everyone who loads the page, so the id alone never reaches an execution. Listing executions takes the project owner's token or a project access token. Send `X-Volcano-Execution-Name` to make the start idempotent: repeating a start with the same name returns the existing execution instead of beginning a second one. Each execution counts once against the project's durable execution allowance, however many times the start is retried under the same execution name, and the number in flight at once is capped by the plan. The operations the execution performs are counted against the durable operations allowance when it finishes.
2276
2352
  # @param function_id [String] Durable function ID, or its name within the project
2277
2353
  # @param [Hash] opts the optional parameters
2278
2354
  # @option opts [String] :x_volcano_execution_name Idempotency key for this execution. Generated when omitted. A repeat under a name that already names a running execution returns that execution and is not charged again. Letters, digits, &#x60;-&#x60;, &#x60;_&#x60; and &#x60;.&#x60;, up to 255 characters. Anything else is rejected with &#x60;400&#x60;.
@@ -2284,7 +2360,7 @@ module Volcano::Generated
2284
2360
  end
2285
2361
 
2286
2362
  # Start a durable execution from an application
2287
- # Starts an execution of a durable function using an application credential, and returns its handle. This is the durable counterpart of &#x60;POST /functions/{functionId}/invoke&#x60;, and it is the endpoint an application calls. Like that one, it is not project-scoped: an anon key, a service key and an auth user token each carry their own project. The project-scoped collection under &#x60;/projects/{id}/durable-functions/...&#x60; remains the owner&#39;s management surface. **With a service key:** any durable function in the project. **With an auth user token:** a durable function whose &#x60;visibility&#x60; is &#x60;authenticated&#x60; or &#x60;public&#x60;. **With an anon key:** requires the &#x60;functions.invoke&#x60; permission, and the function must have &#x60;visibility: public&#x60;. A &#x60;private&#x60; durable function answers every credential but a service key exactly as a missing one, with 404. Starting is all this endpoint does. Reading a result or stopping an execution requires the project owner&#39;s token, because an anon key is shared by everyone who loads the page and an execution is addressed by id alone. Send &#x60;X-Volcano-Execution-Name&#x60; to make the start idempotent: repeating a start with the same name returns the existing execution instead of beginning a second one. Each execution counts once against the project&#39;s durable execution allowance, however many times the start is retried under the same execution name, and the number in flight at once is capped by the plan. The operations the execution performs are counted against the durable operations allowance when it finishes.
2363
+ # Starts an execution of a durable function using an application credential, and returns its handle. This is the durable counterpart of &#x60;POST /functions/{functionId}/invoke&#x60;, and it is the endpoint an application calls. Like that one, it is not project-scoped: an anon key, a service key and an auth user token each carry their own project. The project-scoped collection under &#x60;/projects/{id}/durable-functions/...&#x60; remains the owner&#39;s management surface. **With a service key:** any durable function in the project. **With an auth user token:** a durable function whose &#x60;visibility&#x60; is &#x60;authenticated&#x60; or &#x60;public&#x60;. **With an anon key:** requires the &#x60;functions.invoke&#x60; permission, and the function must have &#x60;visibility: public&#x60;. A &#x60;private&#x60; durable function answers every credential but a service key exactly as a missing one, with 404. The start returns a &#x60;client_token&#x60;. An anon key, or a user who did not start the execution, sends it as &#x60;X-Volcano-Client-Token&#x60; to read the execution, stop it, and reach its messages. A service key scoped to a list without &#x60;*&#x60; sends it to read and stop the execution. An anon key is shared by everyone who loads the page, so the id alone never reaches an execution. Listing executions takes the project owner&#39;s token or a project access token. Send &#x60;X-Volcano-Execution-Name&#x60; to make the start idempotent: repeating a start with the same name returns the existing execution instead of beginning a second one. Each execution counts once against the project&#39;s durable execution allowance, however many times the start is retried under the same execution name, and the number in flight at once is capped by the plan. The operations the execution performs are counted against the durable operations allowance when it finishes.
2288
2364
  # @param function_id [String] Durable function ID, or its name within the project
2289
2365
  # @param [Hash] opts the optional parameters
2290
2366
  # @option opts [String] :x_volcano_execution_name Idempotency key for this execution. Generated when omitted. A repeat under a name that already names a running execution returns that execution and is not charged again. Letters, digits, &#x60;-&#x60;, &#x60;_&#x60; and &#x60;.&#x60;, up to 255 characters. Anything else is rejected with &#x60;400&#x60;.
@@ -2428,6 +2504,82 @@ module Volcano::Generated
2428
2504
  return data, status_code, headers
2429
2505
  end
2430
2506
 
2507
+ # Stop a durable execution from an application
2508
+ # Cancels a running execution with the credential that started it. Its completed steps are not undone. Access follows the same rules as reading the execution. The call is accepted rather than awaited: the response reports the execution as it was read back and may still say `running`. Poll `GET /durable-functions/{functionId}/executions/{executionId}` to see it settle into `stopped`. Stopping an execution that already finished is not an error: the response carries the state it settled in.
2509
+ # @param function_id [String] Durable function ID, or its name within the project
2510
+ # @param execution_id [String] Durable execution ID
2511
+ # @param [Hash] opts the optional parameters
2512
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
2513
+ # @return [DurableExecution]
2514
+ def stop_durable_execution_from_application(function_id, execution_id, opts = {})
2515
+ data, _status_code, _headers = stop_durable_execution_from_application_with_http_info(function_id, execution_id, opts)
2516
+ data
2517
+ end
2518
+
2519
+ # Stop a durable execution from an application
2520
+ # Cancels a running execution with the credential that started it. Its completed steps are not undone. Access follows the same rules as reading the execution. The call is accepted rather than awaited: the response reports the execution as it was read back and may still say &#x60;running&#x60;. Poll &#x60;GET /durable-functions/{functionId}/executions/{executionId}&#x60; to see it settle into &#x60;stopped&#x60;. Stopping an execution that already finished is not an error: the response carries the state it settled in.
2521
+ # @param function_id [String] Durable function ID, or its name within the project
2522
+ # @param execution_id [String] Durable execution ID
2523
+ # @param [Hash] opts the optional parameters
2524
+ # @option opts [String] :x_volcano_client_token The &#x60;client_token&#x60; the execution&#39;s start returned. Lets an anon key, or a user who did not start the execution, reach it, and a service key scoped to a list without &#x60;*&#x60; read and stop it.
2525
+ # @return [Array<(DurableExecution, Integer, Hash)>] DurableExecution data, response status code and response headers
2526
+ def stop_durable_execution_from_application_with_http_info(function_id, execution_id, opts = {})
2527
+ if @api_client.config.debugging
2528
+ @api_client.config.logger.debug 'Calling API: DurableFunctionsApi.stop_durable_execution_from_application ...'
2529
+ end
2530
+ # verify the required parameter 'function_id' is set
2531
+ if @api_client.config.client_side_validation && function_id.nil?
2532
+ fail ArgumentError, "Missing the required parameter 'function_id' when calling DurableFunctionsApi.stop_durable_execution_from_application"
2533
+ end
2534
+ # verify the required parameter 'execution_id' is set
2535
+ if @api_client.config.client_side_validation && execution_id.nil?
2536
+ fail ArgumentError, "Missing the required parameter 'execution_id' when calling DurableFunctionsApi.stop_durable_execution_from_application"
2537
+ end
2538
+ if @api_client.config.client_side_validation && !opts[:'x_volcano_client_token'].nil? && opts[:'x_volcano_client_token'].to_s.length > 128
2539
+ fail ArgumentError, 'invalid value for "opts[:"x_volcano_client_token"]" when calling DurableFunctionsApi.stop_durable_execution_from_application, the character length must be smaller than or equal to 128.'
2540
+ end
2541
+
2542
+ # resource path
2543
+ local_var_path = '/durable-functions/{functionId}/executions/{executionId}/stop'.sub('{' + 'functionId' + '}', CGI.escape(function_id.to_s)).sub('{' + 'executionId' + '}', CGI.escape(execution_id.to_s))
2544
+
2545
+ # query parameters
2546
+ query_params = opts[:query_params] || {}
2547
+
2548
+ # header parameters
2549
+ header_params = opts[:header_params] || {}
2550
+ # HTTP header 'Accept' (if needed)
2551
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
2552
+ header_params[:'X-Volcano-Client-Token'] = opts[:'x_volcano_client_token'] if !opts[:'x_volcano_client_token'].nil?
2553
+
2554
+ # form parameters
2555
+ form_params = opts[:form_params] || {}
2556
+
2557
+ # http body (model)
2558
+ post_body = opts[:debug_body]
2559
+
2560
+ # return_type
2561
+ return_type = opts[:debug_return_type] || 'DurableExecution'
2562
+
2563
+ # auth_names
2564
+ auth_names = opts[:debug_auth_names] || ['ServiceRoleKey', 'AuthUserAccessToken', 'AnonKey']
2565
+
2566
+ new_options = opts.merge(
2567
+ :operation => :"DurableFunctionsApi.stop_durable_execution_from_application",
2568
+ :header_params => header_params,
2569
+ :query_params => query_params,
2570
+ :form_params => form_params,
2571
+ :body => post_body,
2572
+ :auth_names => auth_names,
2573
+ :return_type => return_type
2574
+ )
2575
+
2576
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
2577
+ if @api_client.config.debugging
2578
+ @api_client.config.logger.debug "API called: DurableFunctionsApi#stop_durable_execution_from_application\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
2579
+ end
2580
+ return data, status_code, headers
2581
+ end
2582
+
2431
2583
  # Update a durable function scheduler
2432
2584
  # @param id [String] Project ID
2433
2585
  # @param function_id [String] Durable function ID, or its name within the project
@@ -27,7 +27,7 @@ module Volcano::Generated
27
27
  # Region the execution runs in. An execution is pinned to one region for its whole life because its checkpoints live there.
28
28
  attr_accessor :region
29
29
 
30
- # Whatever the function returned, verbatim. Absent while the execution is still running, absent when the result was too large to return and was checkpointed instead, and absent once the retention period has lapsed.
30
+ # Whatever the function returned, verbatim. Absent while the execution is still running, absent when the result was too large to return and was checkpointed instead, and absent once the retention period has lapsed. A result Volcano has just read can still be returned for up to five minutes after that.
31
31
  attr_accessor :result
32
32
 
33
33
  # `true` when the execution is terminal but its result is no longer retained, which distinguishes a discarded result from an empty one. Shortly after that the execution itself is dropped and reads answer `404`. A result that was checkpointed rather than returned leaves this unset, so it reads like a function that returned nothing.
@@ -40,7 +40,7 @@ module Volcano::Generated
40
40
  # Present once the execution has reached a terminal status.
41
41
  attr_accessor :completed_at
42
42
 
43
- # Lets a browser read and send the execution's messages. Returned only by the start that created the execution, never by a repeat under the same name or by a read. Send it as `X-Volcano-Client-Token`.
43
+ # Lets a browser read the execution, stop it, and read and send its messages, and a service key scoped to a list without `*` read and stop it. Returned only by the start whose input the execution runs, never by a repeat under the same name or by a read. Send it as `X-Volcano-Client-Token`.
44
44
  attr_accessor :client_token
45
45
 
46
46
  class EnumAttributeValidator
@@ -29,6 +29,7 @@ module Volcano
29
29
  require_relative 'generated_transport_logs'
30
30
  require_relative 'generated_transport_functions'
31
31
  require_relative 'generated_transport_durable'
32
+ require_relative 'generated_transport_durable_application'
32
33
  require_relative 'generated_transport_durable_messages'
33
34
  require_relative 'generated_transport_sandbox'
34
35
  require_relative 'generated_transport_storage'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Volcano
4
+ # Durable execution reads and stops on the application route, which take the
5
+ # credential a start takes and, where it needs one, the execution's client
6
+ # token.
7
+ class GeneratedTransport
8
+ def get_durable_execution_from_application(authorization:, function_id:, execution_id:, client_token:)
9
+ invoke do
10
+ apis = @api_factory.call(authorization)
11
+ data, status, headers = apis.durable.get_durable_execution_from_application_with_http_info(
12
+ function_id, execution_id, { x_volcano_client_token: client_token }.compact
13
+ )
14
+ response(data, status, headers)
15
+ end
16
+ end
17
+
18
+ def stop_durable_execution_from_application(authorization:, function_id:, execution_id:, client_token:)
19
+ invoke do
20
+ apis = @api_factory.call(authorization)
21
+ data, status, headers = apis.durable.stop_durable_execution_from_application_with_http_info(
22
+ function_id, execution_id, { x_volcano_client_token: client_token }.compact
23
+ )
24
+ response(data, status, headers)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -52,7 +52,8 @@ module Volcano
52
52
  headers: {
53
53
  'Authorization' => "Bearer #{authorization}",
54
54
  'Content-Type' => 'application/json',
55
- 'Accept' => 'application/json'
55
+ 'Accept' => 'application/json',
56
+ 'User-Agent' => UserAgent::VALUE
56
57
  },
57
58
  timeout: @timeout,
58
59
  followlocation: false
@@ -28,15 +28,29 @@ module Volcano
28
28
 
29
29
  Generated::ApiModelBase.singleton_class.prepend(ModelDeserialization)
30
30
 
31
- # Corrects generated content negotiation and private model lookup.
31
+ # Corrects generated content negotiation, private model lookup, and the user agent.
32
32
  class ApiClient < Generated::ApiClient
33
+ def initialize(...)
34
+ super
35
+ self.user_agent = UserAgent::VALUE
36
+ end
37
+
33
38
  def build_request(http_method, path, options = {})
39
+ PathSegments.check_request_path!(path, object_key: options[:object_key_route] == true)
34
40
  request = super
35
41
  request.options[:followlocation] = options.fetch(:follow_location, true)
36
42
  request.options[:params_encoding] = options.fetch(:params_encoding, request.options[:params_encoding])
37
43
  request
38
44
  end
39
45
 
46
+ # The generated client merges repeated "/", which would send "a//b" as a
47
+ # different object key; every other route has already been checked for
48
+ # empty segments.
49
+ def build_request_url(path, opts = {})
50
+ operation = opts[:operation]
51
+ "#{config.base_url(operation.is_a?(Symbol) ? operation : nil)}/#{path.delete_prefix('/')}"
52
+ end
53
+
40
54
  def select_header_content_type(content_types)
41
55
  if content_types.include?('multipart/form-data') && content_types.include?('application/json')
42
56
  return 'multipart/form-data'
@@ -126,9 +140,18 @@ module Volcano
126
140
  raise ArgumentError, 'bucket_name is required' if bucket_name.nil?
127
141
  raise ArgumentError, 'path is required' if path.nil?
128
142
 
129
- bucket = CGI.escapeURIComponent(bucket_name.to_s)
130
- object_path = CGI.escapeURIComponent(path.to_s).gsub('%2F', '/')
131
- api_client.call_api(method, "/storage/#{bucket}/#{object_path}#{suffix}", options)
143
+ # Storage object requests are built outside the generated operations, so
144
+ # they check the bucket name here.
145
+ bucket = PathSegments.check_bucket_name!(bucket_name.to_s)
146
+ object_path = storage_object_segments(path.to_s)
147
+ api_client.call_api(method, "/storage/#{bucket}/#{object_path}#{suffix}", options.merge(object_key_route: true))
148
+ end
149
+
150
+ # Separators stay literal so the object path keeps its folders.
151
+ def storage_object_segments(path)
152
+ raise ArgumentError, "path #{PathSegments::INVALID_SEGMENTS}" if PathSegments.invalid_storage_path?(path)
153
+
154
+ CGI.escapeURIComponent(PathSegments.bucket_relative_path(path)).gsub('%2F', '/')
132
155
  end
133
156
  end
134
157
 
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Volcano
4
+ # Path segment rules for generated request paths and storage object paths.
5
+ # libcurl and Hosting treat ".", "..", "%2e", and an encoded "/" as path
6
+ # structure, so these values are rejected before a URL is built. An empty
7
+ # segment changes which generated route matches; storage object keys may
8
+ # contain them, as in "folder/" or "a//b", so object paths keep them.
9
+ module PathSegments
10
+ INVALID_SEGMENTS = 'cannot be empty, start with "//", or contain "." or ".." segments'
11
+ INVALID_REQUEST_PATH = 'Request path cannot contain empty, ".", "..", or encoded "/" segments'
12
+ INVALID_BUCKET_NAME = 'bucket name must be 1-64 letters, numbers, "_", or "-"'
13
+ BUCKET_NAME = /\A[a-zA-Z0-9_-]{1,64}\z/
14
+ DOT_SEGMENTS = %w[. ..].freeze
15
+ ENCODED_DOT = /%2e/i
16
+ ENCODED_SLASH = /%2f/i
17
+ private_constant :BUCKET_NAME, :DOT_SEGMENTS, :ENCODED_DOT, :ENCODED_SLASH
18
+
19
+ # The OpenAPI BucketName pattern, anchored to the whole string; the
20
+ # generated client's ^...$ matches any one line of a multi-line value.
21
+ def self.check_bucket_name!(name)
22
+ return name if name.is_a?(String) && BUCKET_NAME.match?(name)
23
+
24
+ raise ArgumentError, INVALID_BUCKET_NAME
25
+ end
26
+
27
+ # Requires a value that stays a single path segment.
28
+ def self.check_identifier!(value, field)
29
+ return value unless DOT_SEGMENTS.include?(value) || value.include?('/')
30
+
31
+ raise ArgumentError, %(#{field} cannot contain "/" or be "." or "..")
32
+ end
33
+
34
+ # Hosting ignores one leading slash, so "/a.txt" and "a.txt" name the same object.
35
+ def self.bucket_relative_path(path)
36
+ path.delete_prefix('/')
37
+ end
38
+
39
+ def self.invalid_storage_path?(path)
40
+ relative = bucket_relative_path(path)
41
+ relative.empty? || relative.start_with?('/') || relative.split('/', -1).intersect?(DOT_SEGMENTS)
42
+ end
43
+
44
+ # Checks a generated route after its parameters are encoded into it and
45
+ # before a URL is built from it, so every operation shares one guard.
46
+ # Storage object routes end in an object key, which may hold empty segments.
47
+ def self.check_request_path!(path, object_key: false)
48
+ segments = path.delete_prefix('/').split('/', -1)
49
+ invalid = segments.any? { |segment| invalid_request_segment?(segment, allow_empty: object_key) }
50
+ raise ArgumentError, INVALID_REQUEST_PATH if invalid
51
+
52
+ path
53
+ end
54
+
55
+ def self.invalid_request_segment?(segment, allow_empty: false)
56
+ return !allow_empty if segment.empty?
57
+
58
+ DOT_SEGMENTS.include?(segment.gsub(ENCODED_DOT, '.')) || ENCODED_SLASH.match?(segment)
59
+ end
60
+ end
61
+ private_constant :PathSegments
62
+ end
@@ -101,7 +101,7 @@ module Volcano
101
101
  require 'async/websocket/client'
102
102
  # Use the HTTP/1.1 upgrade supported by the public API.
103
103
  endpoint = Async::HTTP::Endpoint.parse(address, protocol: Async::HTTP::Protocol::HTTP11)
104
- Async::WebSocket::Client.connect(endpoint)
104
+ Async::WebSocket::Client.connect(endpoint, headers: [['user-agent', UserAgent::VALUE]])
105
105
  end
106
106
 
107
107
  def realtime_secrets = [@client.anon_token, @client.current_session&.access_token]
@@ -39,6 +39,7 @@ module Volcano
39
39
  def upload(path, value, content_type: nil)
40
40
  mime_type = upload_content_type(content_type)
41
41
  path = storage_paths(path).fetch(0)
42
+ PathSegments.check_bucket_name!(@name)
42
43
  binding = @client.capture_session_binding
43
44
  @client.session_token
44
45
  content = upload_bytes(value).freeze
@@ -92,6 +93,7 @@ module Volcano
92
93
  private
93
94
 
94
95
  def storage_request(binding: @client.capture_session_binding)
96
+ PathSegments.check_bucket_name!(@name)
95
97
  @client.session_request(binding: binding) { |token| Transport.invoke { yield(token) } }
96
98
  end
97
99
 
@@ -59,6 +59,7 @@ module Volcano
59
59
  def storage_paths(paths)
60
60
  path_list = paths.is_a?(String) ? [paths] : paths.to_a
61
61
  raise ArgumentError, 'storage paths must be non-empty strings' unless valid_storage_paths?(path_list)
62
+ raise ArgumentError, "storage paths #{PathSegments::INVALID_SEGMENTS}" if invalid_storage_paths?(path_list)
62
63
 
63
64
  path_list.map { |path| path.dup.freeze }.freeze
64
65
  end
@@ -67,6 +68,10 @@ module Volcano
67
68
  !paths.empty? && paths.all? { |path| path.is_a?(String) && !path.empty? }
68
69
  end
69
70
 
71
+ def invalid_storage_paths?(paths)
72
+ paths.any? { |path| PathSegments.invalid_storage_path?(path) }
73
+ end
74
+
70
75
  def delete_path(path, binding)
71
76
  response = storage_request(binding: binding) do |token|
72
77
  @transport.delete_storage_object(
@@ -8,13 +8,13 @@ module Volcano
8
8
  # Local public URL construction for one storage bucket.
9
9
  class StorageBucket
10
10
  INVALID_PUBLIC_URL_ANON_KEY = 'Anon key must contain a project ID'
11
- INVALID_PUBLIC_URL_PATH = 'Public URL paths cannot contain dot segments'
12
11
  INVALID_STORAGE_PATH = 'storage path must be a non-empty string'
13
- private_constant :INVALID_PUBLIC_URL_ANON_KEY, :INVALID_PUBLIC_URL_PATH, :INVALID_STORAGE_PATH
12
+ private_constant :INVALID_PUBLIC_URL_ANON_KEY, :INVALID_STORAGE_PATH
14
13
 
15
14
  def get_public_url(path)
16
15
  object_path = public_url_path(path)
17
- segments = [project_id, @name, *public_url_path_segments(object_path)]
16
+ bucket = PathSegments.check_bucket_name!(@name)
17
+ segments = [project_id, bucket, *PathSegments.bucket_relative_path(object_path).split('/', -1)]
18
18
  "#{@api_url}/public/#{segments.map { |segment| encode_segment(segment) }.join('/')}".freeze
19
19
  end
20
20
 
@@ -22,7 +22,10 @@ module Volcano
22
22
 
23
23
  def project_id
24
24
  value = anon_key_payload['project_id']
25
- return value if value.is_a?(String) && !value.strip.empty?
25
+ if value.is_a?(String) && !value.strip.empty?
26
+ return PathSegments.check_identifier!(value,
27
+ 'Project ID in anon key')
28
+ end
26
29
 
27
30
  raise ArgumentError, INVALID_PUBLIC_URL_ANON_KEY
28
31
  end
@@ -44,17 +47,11 @@ module Volcano
44
47
  encoded + ('=' * (-encoded.length % 4))
45
48
  end
46
49
 
47
- def public_url_path_segments(path)
48
- segments = path.split('/', -1)
49
- raise ArgumentError, INVALID_PUBLIC_URL_PATH if segments.intersect?(%w[. ..])
50
-
51
- segments
52
- end
53
-
54
50
  def public_url_path(path)
55
- return path if path.is_a?(String) && !path.empty?
51
+ raise ArgumentError, INVALID_STORAGE_PATH unless path.is_a?(String) && !path.empty?
52
+ raise ArgumentError, "storage path #{PathSegments::INVALID_SEGMENTS}" if PathSegments.invalid_storage_path?(path)
56
53
 
57
- raise ArgumentError, INVALID_STORAGE_PATH
54
+ path
58
55
  end
59
56
 
60
57
  def encode_segment(segment)
@@ -10,7 +10,7 @@ module Volcano
10
10
  part_size: nil
11
11
  )
12
12
  request = UploadSessionRequest.new(
13
- path: path,
13
+ path: storage_paths(path).fetch(0),
14
14
  content_type: content_type,
15
15
  total_size: total_size,
16
16
  part_size: part_size
@@ -27,7 +27,7 @@ module Volcano
27
27
 
28
28
  def upload_part(path, session_id:, part_number:, data:)
29
29
  request = UploadPartRequest.new(
30
- path: path,
30
+ path: storage_paths(path).fetch(0),
31
31
  session_id: session_id,
32
32
  part_number: part_number,
33
33
  data: upload_bytes(data)
@@ -43,7 +43,7 @@ module Volcano
43
43
  end
44
44
 
45
45
  def complete_upload_session(path, session_id:)
46
- request = UploadSessionReference.new(path: path, session_id: session_id)
46
+ request = UploadSessionReference.new(path: storage_paths(path).fetch(0), session_id: session_id)
47
47
  response = storage_request do |token|
48
48
  @transport.complete_upload_session(
49
49
  authorization: token,
@@ -55,7 +55,7 @@ module Volcano
55
55
  end
56
56
 
57
57
  def get_upload_session(path, session_id:)
58
- request = UploadSessionReference.new(path: path, session_id: session_id)
58
+ request = UploadSessionReference.new(path: storage_paths(path).fetch(0), session_id: session_id)
59
59
  response = storage_request do |token|
60
60
  @transport.get_upload_session(
61
61
  authorization: token,
@@ -67,7 +67,7 @@ module Volcano
67
67
  end
68
68
 
69
69
  def abort_upload_session(path, session_id:)
70
- request = UploadSessionReference.new(path: path, session_id: session_id)
70
+ request = UploadSessionReference.new(path: storage_paths(path).fetch(0), session_id: session_id)
71
71
  response = storage_request do |token|
72
72
  @transport.abort_upload_session(
73
73
  authorization: token,
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbconfig'
4
+
5
+ module Volcano
6
+ # Identifies this SDK, its version, and its runtime to Volcano on every
7
+ # request, so the platform can count SDK usage by version.
8
+ module UserAgent
9
+ VALUE = "volcano-sdk-ruby/#{VERSION} (#{RUBY_ENGINE}/#{RUBY_VERSION}; " \
10
+ "#{RbConfig::CONFIG['host_os'].to_s[/\A[a-z]+/] || 'unknown'}/#{RbConfig::CONFIG['host_cpu']})".freeze
11
+ end
12
+ private_constant :UserAgent
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- VERSION = '0.35.1'
4
+ VERSION = '0.36.0'
5
5
  end
data/lib/volcano.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'volcano/version'
4
+ require_relative 'volcano/user_agent'
4
5
  require_relative 'volcano/connection_string'
5
6
  require_relative 'volcano/models'
6
7
  require_relative 'volcano/user'
@@ -19,6 +20,7 @@ require_relative 'volcano/errors'
19
20
  require_relative 'volcano/redaction'
20
21
  require_relative 'volcano/transport'
21
22
  require_relative 'volcano/immutable_request_value'
23
+ require_relative 'volcano/path_segments'
22
24
  require_relative 'volcano/generated_transport'
23
25
  require_relative 'volcano/auth_notification_dispatch'
24
26
  require_relative 'volcano/auth_session_binding'
data/sig/core_facades.rbs CHANGED
@@ -98,6 +98,8 @@ module Volcano
98
98
  attr_reader messages: DurableMessages
99
99
 
100
100
  def start: (String function_name, ?sdk_payload payload, ?execution_name: String?) -> DurableExecution
101
+ def get_from_application: (String function_name, String execution_id, ?client_token: String?) -> DurableExecution
102
+ def stop_from_application: (String function_name, String execution_id, ?client_token: String?) -> DurableExecution
101
103
  def get: (String project_id, String function_name, String execution_id) -> DurableExecution
102
104
  def list: (String project_id, String function_name, ?status: String?, ?page: Integer?, ?limit: Integer?) -> DurableExecutionPage
103
105
  def stop: (String project_id, String function_name, String execution_id) -> DurableExecution
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.35.1
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kong
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.30.1
46
+ version: 0.30.2
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.30.1
53
+ version: 0.30.2
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: base64
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -711,6 +711,7 @@ files:
711
711
  - lib/volcano/generated_transport_confirmation.rb
712
712
  - lib/volcano/generated_transport_database.rb
713
713
  - lib/volcano/generated_transport_durable.rb
714
+ - lib/volcano/generated_transport_durable_application.rb
714
715
  - lib/volcano/generated_transport_durable_messages.rb
715
716
  - lib/volcano/generated_transport_email_change.rb
716
717
  - lib/volcano/generated_transport_functions.rb
@@ -733,6 +734,7 @@ files:
733
734
  - lib/volcano/log_responses.rb
734
735
  - lib/volcano/logs.rb
735
736
  - lib/volcano/models.rb
737
+ - lib/volcano/path_segments.rb
736
738
  - lib/volcano/realtime.rb
737
739
  - lib/volcano/realtime/blocking_call.rb
738
740
  - lib/volcano/realtime/broadcast_delivery.rb
@@ -786,6 +788,7 @@ files:
786
788
  - lib/volcano/transport.rb
787
789
  - lib/volcano/transport_json.rb
788
790
  - lib/volcano/user.rb
791
+ - lib/volcano/user_agent.rb
789
792
  - lib/volcano/version.rb
790
793
  - sig/auth_credentials.rbs
791
794
  - sig/auth_oauth.rbs