@voxgig/sdkgen 4.50.0 → 4.51.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.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/cache.aontu +6 -4
- package/project/.sdk/model/target/lua.aontu +6 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
- package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
- package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
- package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
- package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
- package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
- package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
- package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
- package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
- package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
- package/project/.sdk/tm/c/core/context.c +1 -0
- package/project/.sdk/tm/c/core/sdk.h +7 -4
- package/project/.sdk/tm/c/feature/cache.c +243 -13
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/tests/feature_test.c +104 -0
- package/project/.sdk/tm/c/utility/clean.c +26 -33
- package/project/.sdk/tm/c/utility/make_options.c +9 -8
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
- package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +81 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +33 -0
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
- package/project/.sdk/tm/cpp/Makefile +5 -0
- package/project/.sdk/tm/cpp/core/types.hpp +11 -4
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
- package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +99 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
- package/project/.sdk/tm/csharp/core/Context.cs +4 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +76 -0
- package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
- package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +61 -0
- package/project/.sdk/tm/go/core/context.go +6 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +61 -0
- package/project/.sdk/tm/go/utility/clean.go +5 -7
- package/project/.sdk/tm/go/utility/fetcher.go +11 -0
- package/project/.sdk/tm/go/utility/make_options.go +5 -7
- package/project/.sdk/tm/java/core/Context.java +9 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
- package/project/.sdk/tm/java/utility/Clean.java +6 -10
- package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
- package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
- package/project/.sdk/tm/js/src/Context.js +4 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
- package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
- package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
- package/project/.sdk/tm/js/test/feature/harness.js +3 -3
- package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
- package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +59 -0
- package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
- package/project/.sdk/tm/lua/core/context.lua +6 -0
- package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/test/feature_test.lua +81 -0
- package/project/.sdk/tm/lua/utility/clean.lua +6 -9
- package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
- package/project/.sdk/tm/ocaml/sdk_features.ml +106 -8
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
- package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +35 -1
- package/project/.sdk/tm/perl/core/context.pm +3 -0
- package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
- package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/t/feature.t +66 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
- package/project/.sdk/tm/perl/utility/clean.pm +6 -8
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
- package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
- package/project/.sdk/tm/php/core/Context.php +4 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
- package/project/.sdk/tm/php/utility/Clean.php +3 -10
- package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
- package/project/.sdk/tm/py/pkg/core/context.py +4 -0
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
- package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
- package/project/.sdk/tm/py/test/test_feature.py +50 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
- package/project/.sdk/tm/rb/core/context.rb +4 -1
- package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
- package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +74 -0
- package/project/.sdk/tm/rb/utility/clean.rb +6 -7
- package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
- package/project/.sdk/tm/rust/core/context.rs +8 -0
- package/project/.sdk/tm/rust/feature/cache.rs +120 -3
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +100 -0
- package/project/.sdk/tm/rust/utility/clean.rs +35 -43
- package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
- package/project/.sdk/tm/scala/core/Context.scala +4 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +28 -0
- package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
- package/project/.sdk/tm/scala/utility/Make.scala +3 -1
- package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +55 -0
- package/project/.sdk/tm/ts/src/Context.ts +4 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
- package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
- package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
- package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
- package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
- package/project/.sdk/tm/zig/core/context.zig +5 -0
- package/project/.sdk/tm/zig/core/utility.zig +11 -9
- package/project/.sdk/tm/zig/feature/cache.zig +144 -13
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/test/feature_test.zig +65 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# ProjectName SDK cache feature
|
|
2
2
|
#
|
|
3
|
-
# Response caching for safe (read) requests
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# 256, oldest evicted first) and every hit/miss/bypass is counted for
|
|
9
|
-
# inspection. Replayed responses expose a re-readable "json" body.
|
|
3
|
+
# Response caching for safe (read) requests, per client: see the features
|
|
4
|
+
# reference for the key, the write invalidation and the Cache-Control rules.
|
|
5
|
+
|
|
6
|
+
require 'openssl'
|
|
7
|
+
require 'securerandom'
|
|
10
8
|
|
|
11
9
|
require_relative 'base_feature'
|
|
12
10
|
require_relative '../utility/media'
|
|
13
11
|
|
|
14
12
|
class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
13
|
+
SAFE_METHODS = ["GET", "HEAD"].freeze
|
|
14
|
+
UNSTORED = ["no-store", "private", "no-cache"].freeze
|
|
15
|
+
MAX_AGE = /\Amax-age\s*=\s*"?(\d+)"?\z/
|
|
16
|
+
|
|
15
17
|
def initialize
|
|
16
18
|
super
|
|
17
19
|
@version = "0.0.1"
|
|
@@ -31,6 +33,7 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
31
33
|
return unless @active
|
|
32
34
|
|
|
33
35
|
@store = {}
|
|
36
|
+
@secret = SecureRandom.random_bytes(32)
|
|
34
37
|
|
|
35
38
|
feature = self
|
|
36
39
|
utility = ctx.utility
|
|
@@ -45,9 +48,17 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
45
48
|
method = ((fetchdef.is_a?(Hash) && fetchdef["method"]) || "GET").to_s.upcase
|
|
46
49
|
methods = @options["methods"] || ["GET"]
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
unless methods.include?(method)
|
|
52
|
+
return inner.call(ctx, url, fetchdef) if SAFE_METHODS.include?(method)
|
|
53
|
+
begin
|
|
54
|
+
return inner.call(ctx, url, fetchdef)
|
|
55
|
+
ensure
|
|
56
|
+
_invalidate(url)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
headers = fetchdef.is_a?(Hash) ? fetchdef["headers"] : nil
|
|
61
|
+
key = "#{method} #{url} #{_digest(headers)}"
|
|
51
62
|
now = _now
|
|
52
63
|
hit = @store[key]
|
|
53
64
|
|
|
@@ -66,9 +77,14 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
66
77
|
|
|
67
78
|
if err.nil? && _cacheable(res)
|
|
68
79
|
snapshot = _snapshot(res)
|
|
69
|
-
ttl = @options["ttl"].nil? ? 5000 : @options["ttl"]
|
|
80
|
+
ttl = self.class.lifetime(snapshot["headers"], @options["ttl"].nil? ? 5000 : @options["ttl"])
|
|
81
|
+
if ttl <= 0
|
|
82
|
+
_track("bypass")
|
|
83
|
+
return _replay(snapshot), nil
|
|
84
|
+
end
|
|
85
|
+
@store.delete(key)
|
|
70
86
|
_evict
|
|
71
|
-
@store[key] = { "expiry" => now + ttl, "snapshot" => snapshot }
|
|
87
|
+
@store[key] = { "expiry" => now + ttl, "scope" => self.class.scope(url), "snapshot" => snapshot }
|
|
72
88
|
_track("miss")
|
|
73
89
|
return _replay(snapshot), nil
|
|
74
90
|
end
|
|
@@ -77,6 +93,54 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
77
93
|
return res, err
|
|
78
94
|
end
|
|
79
95
|
|
|
96
|
+
def _digest(headers)
|
|
97
|
+
pairs = []
|
|
98
|
+
if headers.is_a?(Hash)
|
|
99
|
+
headers.each { |k, v| pairs << [k.to_s.downcase, v.to_s] unless v.nil? }
|
|
100
|
+
end
|
|
101
|
+
text = pairs.sort.map { |k, v| "#{k}:#{v}\n" }.join
|
|
102
|
+
OpenSSL::HMAC.hexdigest("SHA256", @secret, text)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def _invalidate(url)
|
|
106
|
+
path = self.class.scope(url)
|
|
107
|
+
collection = self.class.parent(path)
|
|
108
|
+
@store.delete_if do |_k, e|
|
|
109
|
+
self.class.under(e["scope"], path) || e["scope"] == collection
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# The configured ttl capped by the response's Cache-Control; zero when the
|
|
114
|
+
# response may not be stored.
|
|
115
|
+
def self.lifetime(headers, ttl)
|
|
116
|
+
control = ""
|
|
117
|
+
(headers || {}).each { |k, v| control = v.to_s if k.to_s.downcase == "cache-control" }
|
|
118
|
+
life = ttl
|
|
119
|
+
control.downcase.split(",").each do |part|
|
|
120
|
+
directive = part.strip
|
|
121
|
+
return 0 if UNSTORED.include?(directive)
|
|
122
|
+
age = MAX_AGE.match(directive)
|
|
123
|
+
life = [life, age[1].to_i * 1000].min unless age.nil?
|
|
124
|
+
end
|
|
125
|
+
life
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.scope(url)
|
|
129
|
+
url.to_s.split(/[?#]/, 2).first.to_s.sub(%r{/+\z}, "")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def self.parent(scope)
|
|
133
|
+
scheme = scope.index("://")
|
|
134
|
+
root = scheme.nil? ? 0 : scope.index("/", scheme + 3)
|
|
135
|
+
return scope if root.nil?
|
|
136
|
+
cut = scope.rindex("/") || 0
|
|
137
|
+
scope[0, [cut, root].max]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def self.under(scope, prefix)
|
|
141
|
+
scope == prefix || scope.start_with?(prefix + "/")
|
|
142
|
+
end
|
|
143
|
+
|
|
80
144
|
# A body the transport could not read as JSON passes through, for the operation to report.
|
|
81
145
|
def _cacheable(res)
|
|
82
146
|
return false unless res.is_a?(Hash)
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
# mutex is always the innermost lock so the three can never deadlock.
|
|
48
48
|
|
|
49
49
|
require 'json'
|
|
50
|
-
require 'net/http'
|
|
51
50
|
require 'uri'
|
|
52
51
|
|
|
53
52
|
require_relative 'base_feature'
|
|
54
53
|
require_relative '../utility/struct/voxgig_struct'
|
|
54
|
+
require_relative '../utility/fetcher'
|
|
55
55
|
require_relative 'secrets/voxgig_sekreto'
|
|
56
56
|
|
|
57
57
|
class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
@@ -236,6 +236,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
236
236
|
# provider ERROR refuses the request with the provider's own message;
|
|
237
237
|
# never an unauthenticated send.
|
|
238
238
|
err = resolve
|
|
239
|
+
return nil, err if err.is_a?(ProjectNameError)
|
|
239
240
|
unless err.nil?
|
|
240
241
|
return nil, ctx.make_error("secrets_provider", err.to_s)
|
|
241
242
|
end
|
|
@@ -454,27 +455,22 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
454
455
|
base = options["base"].is_a?(String) ? options["base"] : ""
|
|
455
456
|
url = base.sub(%r{/+\z}, "") + "/" + x["path"].sub(%r{\A/+}, "")
|
|
456
457
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
#
|
|
460
|
-
|
|
461
|
-
# and minimal on purpose: see the NOT-the-SDK-transport note below.
|
|
462
|
-
fetch = ProjectNameSecretsFeature.method(:raw_exchange_fetch) unless fetch.is_a?(Proc)
|
|
458
|
+
# The SDK's own transport, beneath every feature's wrapper: it holds the
|
|
459
|
+
# test feature's block and the GET-only guard, and the wrapped one would
|
|
460
|
+
# recurse on the first expiry.
|
|
461
|
+
fetch = ->(at, fd) { ProjectNameUtilities::Fetcher.call(@ctx, at, fd) }
|
|
463
462
|
|
|
464
463
|
# The body is MARSHALLED, never concatenated: a refresh token (or a
|
|
465
464
|
# configured request-field name) carrying a quote, backslash or newline
|
|
466
465
|
# must arrive as that literal value, not as malformed JSON.
|
|
467
|
-
#
|
|
468
|
-
# Deliberately NOT the SDK transport. The transport is what this
|
|
469
|
-
# feature wraps, and sending the token request back through it would
|
|
470
|
-
# recurse on the first expiry - and would route the exchange through
|
|
471
|
-
# the test mock, which knows nothing about it.
|
|
472
466
|
fetchdef = {
|
|
473
467
|
"method" => x["method"],
|
|
474
468
|
"headers" => { "content-type" => "application/json" },
|
|
475
469
|
"body" => JSON.generate({ x["request"] => @refresh }),
|
|
476
470
|
# Never followed by the client: a redirect would carry the refresh token on.
|
|
477
471
|
"redirect" => "manual",
|
|
472
|
+
# Its own bound, in milliseconds: the timeout feature's wrapper is above.
|
|
473
|
+
"timeout" => 30_000,
|
|
478
474
|
}
|
|
479
475
|
|
|
480
476
|
res, err = fetch.call(url, fetchdef)
|
|
@@ -490,6 +486,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
490
486
|
res, err = fetch.call(at, fetchdef)
|
|
491
487
|
end
|
|
492
488
|
|
|
489
|
+
raise err if err.is_a?(ProjectNameError)
|
|
493
490
|
unless err.nil?
|
|
494
491
|
raise VoxgigSekreto::SekretoError,
|
|
495
492
|
"secrets: token exchange failed: #{err} from #{url}"
|
|
@@ -599,56 +596,4 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
599
596
|
def _str(value, dflt)
|
|
600
597
|
value.is_a?(String) && !value.empty? ? value : dflt
|
|
601
598
|
end
|
|
602
|
-
|
|
603
|
-
# Token-exchange transport of last resort: plain net/http, answering the
|
|
604
|
-
# same [res, err] shape the system.fetch seam promises ("status" +
|
|
605
|
-
# "json"). It exists so an exchange works with ordinary SDK options -
|
|
606
|
-
# requiring a custom transport for the COMMON case would reject every
|
|
607
|
-
# live token purchase before a request was made.
|
|
608
|
-
def self.raw_exchange_fetch(fullurl, fetchdef)
|
|
609
|
-
uri = URI.parse(fullurl)
|
|
610
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
611
|
-
http.use_ssl = (uri.scheme == "https")
|
|
612
|
-
http.open_timeout = 30
|
|
613
|
-
http.read_timeout = 30
|
|
614
|
-
|
|
615
|
-
method_str = (fetchdef["method"] || "POST").to_s.upcase
|
|
616
|
-
klass = case method_str
|
|
617
|
-
when "PUT" then Net::HTTP::Put
|
|
618
|
-
when "PATCH" then Net::HTTP::Patch
|
|
619
|
-
when "GET" then Net::HTTP::Get
|
|
620
|
-
else Net::HTTP::Post
|
|
621
|
-
end
|
|
622
|
-
|
|
623
|
-
request = klass.new(uri)
|
|
624
|
-
(fetchdef["headers"] || {}).each do |k, v|
|
|
625
|
-
request[k] = v.to_s if v.is_a?(String)
|
|
626
|
-
end
|
|
627
|
-
body = fetchdef["body"]
|
|
628
|
-
request.body = body if body.is_a?(String)
|
|
629
|
-
|
|
630
|
-
# Net::HTTP#request follows no redirect: a 3xx is returned as its status.
|
|
631
|
-
resp = http.request(request)
|
|
632
|
-
raw = resp.body
|
|
633
|
-
|
|
634
|
-
# A non-2xx answer IS a response: hand back its status so the caller
|
|
635
|
-
# reports "token exchange failed: <status>" rather than a transport
|
|
636
|
-
# error.
|
|
637
|
-
resp_headers = {}
|
|
638
|
-
resp.each_header { |k, v| resp_headers[k.downcase] = v }
|
|
639
|
-
|
|
640
|
-
return {
|
|
641
|
-
"status" => resp.code.to_i,
|
|
642
|
-
"headers" => resp_headers,
|
|
643
|
-
"json" => -> {
|
|
644
|
-
begin
|
|
645
|
-
raw.nil? || raw.empty? ? nil : JSON.parse(raw)
|
|
646
|
-
rescue StandardError
|
|
647
|
-
nil
|
|
648
|
-
end
|
|
649
|
-
},
|
|
650
|
-
}, nil
|
|
651
|
-
rescue StandardError => e
|
|
652
|
-
return nil, e
|
|
653
|
-
end
|
|
654
599
|
end
|
|
@@ -125,8 +125,24 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
125
125
|
out.sort_by { |o| [safe.fetch(o["op"], 2), o["key"]] }
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
def invoke(client, op, ctrl)
|
|
129
|
-
client.public_send(op["accessor"]).public_send(op["op"], {}, ctrl)
|
|
128
|
+
def invoke(client, op, ctrl, args = nil)
|
|
129
|
+
client.public_send(op["accessor"]).public_send(op["op"], (args || {}).dup, ctrl)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
ITEM_ARGS = { "id" => "corpus-item" }.freeze
|
|
133
|
+
|
|
134
|
+
# A write of one entity (#ITEM) that completes when driven with ITEM_ARGS.
|
|
135
|
+
def usable_item(accessor)
|
|
136
|
+
candidates(build_client({})).each do |cand|
|
|
137
|
+
next unless cand["accessor"] == accessor && %w[update patch remove].include?(cand["op"])
|
|
138
|
+
begin
|
|
139
|
+
invoke(build_client({}), cand, {}, ITEM_ARGS)
|
|
140
|
+
rescue StandardError
|
|
141
|
+
next
|
|
142
|
+
end
|
|
143
|
+
return cand
|
|
144
|
+
end
|
|
145
|
+
nil
|
|
130
146
|
end
|
|
131
147
|
|
|
132
148
|
# Pick operations by DRIVING them: an op is usable when it completes
|
|
@@ -147,6 +163,48 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
147
163
|
picked
|
|
148
164
|
end
|
|
149
165
|
|
|
166
|
+
READ_OPS = ["list", "load"].freeze
|
|
167
|
+
WRITE_OPS = ["create", "update", "patch", "remove"].freeze
|
|
168
|
+
|
|
169
|
+
# A read and a write of one entity (#READ, #WRITE), each driven as
|
|
170
|
+
# usable_ops drives an op.
|
|
171
|
+
def usable_pair
|
|
172
|
+
found = {}
|
|
173
|
+
candidates(build_client({})).each do |cand|
|
|
174
|
+
role = READ_OPS.include?(cand["op"]) ? "read" : (WRITE_OPS.include?(cand["op"]) ? "write" : nil)
|
|
175
|
+
seen = (found[cand["accessor"]] ||= {})
|
|
176
|
+
next if role.nil? || seen.key?(role)
|
|
177
|
+
begin
|
|
178
|
+
invoke(build_client({}), cand, {})
|
|
179
|
+
rescue StandardError
|
|
180
|
+
next
|
|
181
|
+
end
|
|
182
|
+
seen[role] = cand
|
|
183
|
+
return seen if seen.key?("read") && seen.key?("write")
|
|
184
|
+
end
|
|
185
|
+
nil
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# One step: it may wait before its call, may add request headers for its
|
|
189
|
+
# call, and may pass `args` as the operation's first argument.
|
|
190
|
+
def step_call(client, op, step, ctrl)
|
|
191
|
+
sleep(step["wait"] / 1000.0) unless step["wait"].nil?
|
|
192
|
+
return invoke(client, op, ctrl, step["args"]) if step["headers"].nil?
|
|
193
|
+
options = client.options
|
|
194
|
+
had = options.key?("headers")
|
|
195
|
+
prior = options["headers"]
|
|
196
|
+
options["headers"] = (prior || {}).merge(step["headers"])
|
|
197
|
+
begin
|
|
198
|
+
invoke(client, op, ctrl, step["args"])
|
|
199
|
+
ensure
|
|
200
|
+
if had
|
|
201
|
+
options["headers"] = prior
|
|
202
|
+
else
|
|
203
|
+
options.delete("headers")
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
150
208
|
# Replace #OPn throughout a case, keys included.
|
|
151
209
|
def resolve(node, tokens)
|
|
152
210
|
case node
|
|
@@ -286,6 +344,11 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
286
344
|
|
|
287
345
|
ops = usable_ops(2)
|
|
288
346
|
by_key = ops.each_with_object({}) { |o, h| h[o["key"]] = o }
|
|
347
|
+
pair = usable_pair
|
|
348
|
+
pair&.each_value { |o| by_key[o["key"]] = o }
|
|
349
|
+
item = pair && usable_item(pair["read"]["accessor"])
|
|
350
|
+
by_key[item["key"]] = item unless item.nil?
|
|
351
|
+
other = pair && ops.find { |o| o["accessor"] != pair["read"]["accessor"] }
|
|
289
352
|
|
|
290
353
|
ran = 0
|
|
291
354
|
cases.each do |raw|
|
|
@@ -295,6 +358,19 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
295
358
|
next
|
|
296
359
|
end
|
|
297
360
|
|
|
361
|
+
paired = JSON.generate(raw).match?(/#(READ|WRITE|ITEM|OTHER)\b/)
|
|
362
|
+
if paired && pair.nil?
|
|
363
|
+
puts "skip \"#{raw['name']}\": needs a read and a write of one entity, this SDK offers none"
|
|
364
|
+
next
|
|
365
|
+
end
|
|
366
|
+
lacking = [["#ITEM", item], ["#OTHER", other]].find do |tok, op|
|
|
367
|
+
paired && op.nil? && JSON.generate(raw).match?(/#{tok}\b/)
|
|
368
|
+
end
|
|
369
|
+
unless lacking.nil?
|
|
370
|
+
puts "skip \"#{raw['name']}\": needs #{lacking[0]}, which this SDK cannot drive"
|
|
371
|
+
next
|
|
372
|
+
end
|
|
373
|
+
|
|
298
374
|
missing = missing_feature(raw, have)
|
|
299
375
|
unless missing.nil?
|
|
300
376
|
puts "skip \"#{raw['name']}\": needs the #{missing} feature, " \
|
|
@@ -304,6 +380,12 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
304
380
|
|
|
305
381
|
tokens = {}
|
|
306
382
|
need.times { |i| tokens["#OP#{i + 1}"] = ops[i]["key"] }
|
|
383
|
+
if paired
|
|
384
|
+
tokens["#READ"] = pair["read"]["key"]
|
|
385
|
+
tokens["#WRITE"] = pair["write"]["key"]
|
|
386
|
+
tokens["#ITEM"] = item["key"] unless item.nil?
|
|
387
|
+
tokens["#OTHER"] = other["key"] unless other.nil?
|
|
388
|
+
end
|
|
307
389
|
kase = resolve(raw, tokens)
|
|
308
390
|
label = kase["name"].to_s
|
|
309
391
|
ran += 1
|
|
@@ -319,7 +401,7 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
319
401
|
wanterr = step["err"]
|
|
320
402
|
|
|
321
403
|
begin
|
|
322
|
-
|
|
404
|
+
step_call(client, op, step, ctrl)
|
|
323
405
|
assert_nil wanterr, "#{label}: #{step['op']} was expected to fail, and did not"
|
|
324
406
|
rescue Minitest::Assertion
|
|
325
407
|
raise
|
|
@@ -610,6 +610,58 @@ class FeatureTest < Minitest::Test
|
|
|
610
610
|
assert_equal 3, calls.length
|
|
611
611
|
end
|
|
612
612
|
|
|
613
|
+
def test_cache_keys_on_the_request_headers
|
|
614
|
+
skip_unless_feature("cache")
|
|
615
|
+
server, calls = H.recording_server
|
|
616
|
+
h = harness([fspec("cache", "ttl" => 10000)], server: server)
|
|
617
|
+
h.op(path: "/w/1", headers: { "x-tenant" => "tenant-a" })
|
|
618
|
+
h.op(path: "/w/1", headers: { "X-Tenant" => "tenant-b" })
|
|
619
|
+
assert_equal 2, calls.length
|
|
620
|
+
h.op(path: "/w/1", headers: { "x-tenant" => "tenant-b" })
|
|
621
|
+
assert_equal 2, calls.length
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
def test_cache_a_write_drops_its_collection
|
|
625
|
+
skip_unless_feature("cache")
|
|
626
|
+
server, calls = H.recording_server
|
|
627
|
+
h = harness([fspec("cache", "ttl" => 10000)], server: server)
|
|
628
|
+
paths = ["/w/1", "/w", "/w/1/part", "/other/1", "/w/2"]
|
|
629
|
+
paths.each { |p| h.op(path: p) }
|
|
630
|
+
h.op(opname: "update", method: "PUT", path: "/w/1")
|
|
631
|
+
paths.each { |p| h.op(path: p) }
|
|
632
|
+
assert_equal 9, calls.length
|
|
633
|
+
assert_equal 2, h.track(:@_cache)["hit"]
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
def test_cache_control_prevents_storing
|
|
637
|
+
skip_unless_feature("cache")
|
|
638
|
+
["no-store", "private", "No-Cache", "max-age=60, private"].each do |control|
|
|
639
|
+
server, calls = H.recording_server do |_n, _fd|
|
|
640
|
+
[H.make_response(200, { "ok" => true }, { "Cache-Control" => control }), nil]
|
|
641
|
+
end
|
|
642
|
+
h = harness([fspec("cache", "ttl" => 10000)], server: server)
|
|
643
|
+
h.op(path: "/w")
|
|
644
|
+
h.op(path: "/w")
|
|
645
|
+
assert_equal 2, calls.length, control
|
|
646
|
+
end
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
def test_cache_max_age_caps_the_ttl
|
|
650
|
+
skip_unless_feature("cache")
|
|
651
|
+
clock = H::Clock.new
|
|
652
|
+
server, calls = H.recording_server do |_n, _fd|
|
|
653
|
+
[H.make_response(200, { "ok" => true }, { "cache-control" => "max-age=1" }), nil]
|
|
654
|
+
end
|
|
655
|
+
h = harness([fspec("cache", "ttl" => 10000, "now" => clock.now)], server: server)
|
|
656
|
+
h.op(path: "/w")
|
|
657
|
+
clock.advance(500)
|
|
658
|
+
h.op(path: "/w")
|
|
659
|
+
assert_equal 1, calls.length
|
|
660
|
+
clock.advance(600)
|
|
661
|
+
h.op(path: "/w")
|
|
662
|
+
assert_equal 2, calls.length
|
|
663
|
+
end
|
|
664
|
+
|
|
613
665
|
def test_cache_inactive_does_not_wrap
|
|
614
666
|
skip_unless_feature("cache")
|
|
615
667
|
server, calls = H.recording_server
|
|
@@ -853,6 +905,28 @@ class FeatureTest < Minitest::Test
|
|
|
853
905
|
end
|
|
854
906
|
|
|
855
907
|
|
|
908
|
+
# === per-call state ===
|
|
909
|
+
|
|
910
|
+
def test_no_feature_keeps_a_context_past_its_call
|
|
911
|
+
skip_unless_feature("netsim")
|
|
912
|
+
names = %w[audit debug telemetry metrics cost].select { |n| H.has_feature?(n) }
|
|
913
|
+
skip "no feature here keeps per-call state" if names.empty?
|
|
914
|
+
h = harness([fspec("netsim", "failEvery" => 2, "failStatus" => 500)] +
|
|
915
|
+
names.map { |n| fspec(n) })
|
|
916
|
+
20.times { |i| h.op(path: "/w/#{i}") }
|
|
917
|
+
names.each do |n|
|
|
918
|
+
f = h.feature(n)
|
|
919
|
+
f.instance_variables.each do |iv|
|
|
920
|
+
table = f.instance_variable_get(iv)
|
|
921
|
+
next unless table.is_a?(Hash)
|
|
922
|
+
held = table.keys.count { |k| k.is_a?(ProjectNameContext) }
|
|
923
|
+
assert_equal 0, held, "#{n} #{iv} still holds #{held} context(s) after 20 calls"
|
|
924
|
+
end
|
|
925
|
+
end
|
|
926
|
+
assert_equal 20, h.track(:@_audit)["records"].length if names.include?("audit")
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
|
|
856
930
|
# === one call, one id ===
|
|
857
931
|
|
|
858
932
|
def test_telemetry_debug_and_audit_carry_one_calls_context_id
|
|
@@ -44,14 +44,13 @@ module ProjectNameUtilities
|
|
|
44
44
|
n.nil? || n.nan? || n.infinite? || n < 0 ? dflt : n.floor
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
# The
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
47
|
+
# The registry make_options builds; a context without one (make_error is
|
|
48
|
+
# reached with a bare one) falls back to the schema defaults, so nothing
|
|
49
|
+
# leaves raw for want of a constructor. A Hash stands in for a context
|
|
50
|
+
# before one exists (make_options).
|
|
51
51
|
def self.config(ctx)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return derived if derived.is_a?(Hash)
|
|
52
|
+
cfg = ctx.respond_to?(:cleancfg) ? ctx.cleancfg : (ctx.is_a?(Hash) ? ctx["cleancfg"] : nil)
|
|
53
|
+
return cfg if cfg.is_a?(Hash)
|
|
55
54
|
make_config(ProjectNameSchema::OPTSPEC["clean"])
|
|
56
55
|
end
|
|
57
56
|
|
|
@@ -189,6 +189,12 @@ module ProjectNameUtilities
|
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
http = ProjectNameUtilities.http_checkout(key, uri, proxy)
|
|
192
|
+
# A bound in milliseconds, for a caller beneath the timeout feature;
|
|
193
|
+
# a pooled connection goes back with Net::HTTP's own.
|
|
194
|
+
bound = fetchdef["timeout"]
|
|
195
|
+
bound = bound.is_a?(Numeric) && bound > 0 ? bound / 1000.0 : 60
|
|
196
|
+
http.read_timeout = bound
|
|
197
|
+
http.write_timeout = bound
|
|
192
198
|
begin
|
|
193
199
|
# Net::HTTP retries idempotent requests; an EOF can follow a committed POST.
|
|
194
200
|
resp = http.request(request) do |r|
|
|
@@ -68,7 +68,7 @@ module ProjectNameUtilities
|
|
|
68
68
|
cfgclean = cfgopts["clean"].is_a?(Hash) ? VoxgigStruct.clone(cfgopts["clean"]) : nil
|
|
69
69
|
cleancfg = CleanSupport.make_config(VoxgigStruct.merge(
|
|
70
70
|
[{}, ProjectNameSchema::OPTSPEC["clean"], cfgclean, opts["clean"]].select { |c| c.is_a?(Hash) }))
|
|
71
|
-
cleanctx = { "
|
|
71
|
+
cleanctx = { "cleancfg" => cleancfg }
|
|
72
72
|
CleanSupport.add_options(cleanctx, opts.reject { |k, _| k == "clean" })
|
|
73
73
|
[cfgopts, opts].each do |block|
|
|
74
74
|
CleanSupport.splitvalues(VoxgigStruct.getpath(block, "clean.values")).each do |raw|
|
|
@@ -194,10 +194,10 @@ module ProjectNameUtilities
|
|
|
194
194
|
# Again over the merged result: the config's own defaults can carry one.
|
|
195
195
|
CleanSupport.add_options(cleanctx, opts.reject { |k, _| k == "clean" })
|
|
196
196
|
|
|
197
|
-
opts["__derived__"] = {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
opts["__derived__"] = { "featureorder" => featureorder }
|
|
198
|
+
|
|
199
|
+
# Beside the options, not in them: options_map hands them to callers.
|
|
200
|
+
ctx.cleancfg = cleancfg
|
|
201
201
|
|
|
202
202
|
opts
|
|
203
203
|
}
|
|
@@ -32,6 +32,7 @@ pub struct CtxSpec {
|
|
|
32
32
|
pub config: Option<Value>,
|
|
33
33
|
pub entopts: Option<Value>,
|
|
34
34
|
pub options: Option<Value>,
|
|
35
|
+
pub cleancfg: Option<Value>,
|
|
35
36
|
pub entity: Option<Rc<dyn Entity>>,
|
|
36
37
|
pub shared: Option<Value>,
|
|
37
38
|
pub opmap: Option<OpMap>,
|
|
@@ -57,6 +58,8 @@ pub struct Context {
|
|
|
57
58
|
pub config: RefCell<Value>,
|
|
58
59
|
pub entopts: RefCell<Value>,
|
|
59
60
|
pub options: RefCell<Value>,
|
|
61
|
+
/// The clean registry, beside the options rather than in them.
|
|
62
|
+
pub cleancfg: RefCell<Value>,
|
|
60
63
|
pub opmap: RefCell<OpMap>,
|
|
61
64
|
pub response: RefCell<Option<Rc<RefCell<Response>>>>,
|
|
62
65
|
pub result: RefCell<Option<Rc<RefCell<SdkResult>>>>,
|
|
@@ -135,6 +138,10 @@ impl Context {
|
|
|
135
138
|
.options
|
|
136
139
|
.or_else(|| basectx.map(|b| b.options.borrow().clone()))
|
|
137
140
|
.unwrap_or(Value::Noval);
|
|
141
|
+
let cleancfg = ctxspec
|
|
142
|
+
.cleancfg
|
|
143
|
+
.or_else(|| basectx.map(|b| b.cleancfg.borrow().clone()))
|
|
144
|
+
.unwrap_or(Value::Noval);
|
|
138
145
|
let entity = ctxspec
|
|
139
146
|
.entity
|
|
140
147
|
.or_else(|| basectx.and_then(|b| b.entity.borrow().clone()));
|
|
@@ -212,6 +219,7 @@ impl Context {
|
|
|
212
219
|
config: RefCell::new(config),
|
|
213
220
|
entopts: RefCell::new(entopts),
|
|
214
221
|
options: RefCell::new(options),
|
|
222
|
+
cleancfg: RefCell::new(cleancfg),
|
|
215
223
|
opmap: RefCell::new(opmap),
|
|
216
224
|
response: RefCell::new(response),
|
|
217
225
|
result: RefCell::new(result),
|