@voxgig/sdkgen 4.49.1 → 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/debug.c +1 -0
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/feature/telemetry.c +1 -0
- package/project/.sdk/tm/c/tests/feature_test.c +142 -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 +83 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -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/debug.hpp +1 -0
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -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/DebugFeature.cs +1 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -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/debug.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +84 -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/debug_feature.go +3 -2
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +101 -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/DebugFeature.java +1 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +88 -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/debug/DebugFeature.js +1 -0
- 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/telemetry/TelemetryFeature.js +1 -0
- 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/feature.test.js +17 -0
- 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/DebugFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -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/debug_feature.lua +1 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
- package/project/.sdk/tm/lua/test/feature_test.lua +108 -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 +108 -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 +51 -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/debug_feature.pm +1 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
- package/project/.sdk/tm/perl/t/feature.t +86 -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/DebugFeature.php +1 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +90 -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/debug_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
- 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 +73 -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/debug_feature.rb +1 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +93 -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/debug.rs +1 -0
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +141 -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/DebugFeature.scala +1 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
- 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/DebugFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
- 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 +79 -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/debug/DebugFeature.ts +1 -0
- 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/telemetry/TelemetryFeature.ts +1 -0
- 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/feature.test.ts +17 -0
- 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/debug.zig +1 -0
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
- package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -151,15 +151,13 @@ func makeCleanConfig(cleanopts map[string]any) *cleanConfig {
|
|
|
151
151
|
return cfg
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
// The
|
|
155
|
-
//
|
|
154
|
+
// The registry makeOptions builds; a context without one (makeError is
|
|
155
|
+
// reached with a bare one) falls back to the schema defaults, so nothing
|
|
156
156
|
// leaves raw for want of a constructor.
|
|
157
157
|
func cleanConfigOf(ctx *core.Context) *cleanConfig {
|
|
158
|
-
if ctx != nil
|
|
159
|
-
if
|
|
160
|
-
|
|
161
|
-
return cfg
|
|
162
|
-
}
|
|
158
|
+
if ctx != nil {
|
|
159
|
+
if cfg, ok := ctx.CleanCfg.(*cleanConfig); ok {
|
|
160
|
+
return cfg
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
163
|
spec, _ := core.OPTSPEC["clean"].(map[string]any)
|
|
@@ -13,6 +13,7 @@ import (
|
|
|
13
13
|
"os"
|
|
14
14
|
"strings"
|
|
15
15
|
"sync"
|
|
16
|
+
"time"
|
|
16
17
|
|
|
17
18
|
vs "github.com/voxgig/struct"
|
|
18
19
|
|
|
@@ -49,6 +50,10 @@ func clientFor(ctx *core.Context, fetchdef map[string]any) *http.Client {
|
|
|
49
50
|
// A shallow copy shares the pooled Transport; only CheckRedirect differs.
|
|
50
51
|
policy := *client
|
|
51
52
|
policy.CheckRedirect = followRedirect(ctx)
|
|
53
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
54
|
+
if ms := core.ToInt(fetchdef["timeout"]); 0 < ms {
|
|
55
|
+
policy.Timeout = time.Duration(ms) * time.Millisecond
|
|
56
|
+
}
|
|
52
57
|
if redirect, ok := fetchdef["redirect"].(string); ok && redirect == "manual" {
|
|
53
58
|
policy.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
|
54
59
|
return http.ErrUseLastResponse
|
|
@@ -266,6 +271,12 @@ func decodeBody(body []byte, encoding string) ([]byte, error) {
|
|
|
266
271
|
return out, nil
|
|
267
272
|
}
|
|
268
273
|
|
|
274
|
+
// Fetcher is the SDK's own transport, for a feature that must send beneath
|
|
275
|
+
// the wrappers installed over it.
|
|
276
|
+
func Fetcher(ctx *core.Context, fullurl string, fetchdef map[string]any) (any, error) {
|
|
277
|
+
return fetcherUtil(ctx, fullurl, fetchdef)
|
|
278
|
+
}
|
|
279
|
+
|
|
269
280
|
func fetcherUtil(ctx *core.Context, fullurl string, fetchdef map[string]any) (any, error) {
|
|
270
281
|
if ctx.Client.Mode != "live" {
|
|
271
282
|
return nil, ctx.MakeError("fetch_mode_block",
|
|
@@ -87,9 +87,7 @@ func makeOptionsUtil(ctx *core.Context) (map[string]any, error) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
cleancfg := makeCleanConfig(cleanraw)
|
|
90
|
-
cleanctx := &core.Context{
|
|
91
|
-
"__derived__": map[string]any{"clean": cleancfg},
|
|
92
|
-
}}
|
|
90
|
+
cleanctx := &core.Context{CleanCfg: cleancfg}
|
|
93
91
|
cleanAddOptions(cleanctx, cleanOmit(opts, "clean"))
|
|
94
92
|
for _, block := range []map[string]any{cfgopts, opts} {
|
|
95
93
|
for _, s := range cleanSplit(vs.GetPath(block, []any{"clean", "values"})) {
|
|
@@ -246,10 +244,10 @@ func makeOptionsUtil(ctx *core.Context) (map[string]any, error) {
|
|
|
246
244
|
}
|
|
247
245
|
}
|
|
248
246
|
|
|
249
|
-
opts["__derived__"] = map[string]any{
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
opts["__derived__"] = map[string]any{"featureorder": featureorder}
|
|
248
|
+
|
|
249
|
+
// Beside the options, not in them: OptionsMap hands them to callers.
|
|
250
|
+
ctx.CleanCfg = cleancfg
|
|
253
251
|
|
|
254
252
|
// Again over the merged result: the config's own defaults can carry one.
|
|
255
253
|
cleanAddOptions(cleanctx, cleanOmit(opts, "clean", "__derived__"))
|
|
@@ -24,6 +24,8 @@ public class Context {
|
|
|
24
24
|
public Map<String, Object> config;
|
|
25
25
|
public Map<String, Object> entopts;
|
|
26
26
|
public Map<String, Object> options;
|
|
27
|
+
// The clean registry, beside the options rather than in them.
|
|
28
|
+
public Map<String, Object> cleancfg;
|
|
27
29
|
public Map<String, Operation> opmap;
|
|
28
30
|
public Response response;
|
|
29
31
|
public Result result;
|
|
@@ -124,6 +126,13 @@ public class Context {
|
|
|
124
126
|
if (this.options == null && basectx != null) {
|
|
125
127
|
this.options = basectx.options;
|
|
126
128
|
}
|
|
129
|
+
Object cc = Helpers.getCtxProp(ctxmap, "cleancfg");
|
|
130
|
+
if (cc instanceof Map) {
|
|
131
|
+
this.cleancfg = (Map<String, Object>) cc;
|
|
132
|
+
}
|
|
133
|
+
if (this.cleancfg == null && basectx != null) {
|
|
134
|
+
this.cleancfg = basectx.cleancfg;
|
|
135
|
+
}
|
|
127
136
|
|
|
128
137
|
// Entity
|
|
129
138
|
Object e = Helpers.getCtxProp(ctxmap, "entity");
|
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
package JAVAPACKAGE.feature;
|
|
2
2
|
|
|
3
|
+
import java.nio.charset.StandardCharsets;
|
|
4
|
+
import java.security.GeneralSecurityException;
|
|
5
|
+
import java.security.SecureRandom;
|
|
3
6
|
import java.util.ArrayList;
|
|
7
|
+
import java.util.Iterator;
|
|
4
8
|
import java.util.LinkedHashMap;
|
|
5
9
|
import java.util.List;
|
|
6
10
|
import java.util.Map;
|
|
7
11
|
import java.util.function.Supplier;
|
|
12
|
+
import java.util.regex.Matcher;
|
|
13
|
+
import java.util.regex.Pattern;
|
|
14
|
+
|
|
15
|
+
import javax.crypto.Mac;
|
|
16
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
8
17
|
|
|
9
18
|
import JAVAPACKAGE.core.Context;
|
|
10
19
|
import JAVAPACKAGE.core.SdkClient;
|
|
11
20
|
import JAVAPACKAGE.core.Utility;
|
|
12
21
|
import JAVAPACKAGE.utility.Media;
|
|
13
22
|
|
|
14
|
-
// Response caching for safe (read) requests
|
|
15
|
-
//
|
|
16
|
-
// same method+URL was fetched within `ttl` ms (default: 5000). Only
|
|
17
|
-
// successful (2xx) responses to cacheable methods (default: GET) are
|
|
18
|
-
// stored, keyed by method+URL. The cache is bounded (`max` entries, default
|
|
19
|
-
// 256, oldest evicted first) and every hit/miss/bypass is counted. Bodies
|
|
20
|
-
// are snapshotted on capture so both the current caller and later hits can
|
|
21
|
-
// re-read the JSON body repeatedly.
|
|
23
|
+
// Response caching for safe (read) requests, per client: see the features
|
|
24
|
+
// reference for the key, the write invalidation and the Cache-Control rules.
|
|
22
25
|
@SuppressWarnings({"unchecked"})
|
|
23
26
|
public class CacheFeature extends BaseFeature {
|
|
24
27
|
|
|
25
28
|
private SdkClient client;
|
|
26
29
|
private Map<String, Object> options;
|
|
27
30
|
private Map<String, CacheEntry> store;
|
|
28
|
-
private
|
|
31
|
+
private SecretKeySpec secret;
|
|
32
|
+
|
|
33
|
+
private static final List<String> SAFE_METHODS = List.of("GET", "HEAD");
|
|
34
|
+
private static final List<String> UNSTORED = List.of("no-store", "private", "no-cache");
|
|
35
|
+
private static final Pattern MAX_AGE = Pattern.compile("^max-age\\s*=\\s*\"?(\\d+)\"?$");
|
|
29
36
|
|
|
30
37
|
// Activity tracking (mirrors the ts client._cache record).
|
|
31
38
|
public int hit = 0;
|
|
@@ -34,6 +41,7 @@ public class CacheFeature extends BaseFeature {
|
|
|
34
41
|
|
|
35
42
|
private static final class CacheEntry {
|
|
36
43
|
long expiry;
|
|
44
|
+
String scope;
|
|
37
45
|
CacheSnapshot snapshot;
|
|
38
46
|
}
|
|
39
47
|
|
|
@@ -59,7 +67,9 @@ public class CacheFeature extends BaseFeature {
|
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
this.store = new LinkedHashMap<>();
|
|
62
|
-
|
|
70
|
+
byte[] key = new byte[32];
|
|
71
|
+
new SecureRandom().nextBytes(key);
|
|
72
|
+
this.secret = new SecretKeySpec(key, "HmacSHA256");
|
|
63
73
|
|
|
64
74
|
final Utility.FetcherFn inner = ctx.utility.fetcher;
|
|
65
75
|
|
|
@@ -88,10 +98,18 @@ public class CacheFeature extends BaseFeature {
|
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
100
|
if (!cacheable) {
|
|
91
|
-
|
|
101
|
+
if (SAFE_METHODS.contains(method)) {
|
|
102
|
+
return inner.fetch(ctx, url, fetchdef);
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
return inner.fetch(ctx, url, fetchdef);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
invalidate(url);
|
|
109
|
+
}
|
|
92
110
|
}
|
|
93
111
|
|
|
94
|
-
String key = method + " " + url;
|
|
112
|
+
String key = method + " " + url + " " + digest(fetchdef.get("headers"));
|
|
95
113
|
long now = FeatureOptions.foptNow(this.options).getAsLong();
|
|
96
114
|
|
|
97
115
|
CacheEntry hitEntry = this.store.get(key);
|
|
@@ -117,13 +135,18 @@ public class CacheFeature extends BaseFeature {
|
|
|
117
135
|
|
|
118
136
|
if (storable(res)) {
|
|
119
137
|
CacheSnapshot snapshot = snapshot(res);
|
|
120
|
-
|
|
138
|
+
long ttl = lifetime(snapshot.headers, FeatureOptions.foptInt(this.options, "ttl", 5000));
|
|
139
|
+
if (ttl <= 0) {
|
|
140
|
+
this.bypass++;
|
|
141
|
+
return replay(snapshot);
|
|
142
|
+
}
|
|
143
|
+
this.store.remove(key);
|
|
121
144
|
evict();
|
|
122
145
|
CacheEntry entry = new CacheEntry();
|
|
123
146
|
entry.expiry = now + ttl;
|
|
147
|
+
entry.scope = scope(url);
|
|
124
148
|
entry.snapshot = snapshot;
|
|
125
149
|
this.store.put(key, entry);
|
|
126
|
-
this.order.add(key);
|
|
127
150
|
this.miss++;
|
|
128
151
|
return replay(snapshot);
|
|
129
152
|
}
|
|
@@ -132,6 +155,88 @@ public class CacheFeature extends BaseFeature {
|
|
|
132
155
|
return res;
|
|
133
156
|
}
|
|
134
157
|
|
|
158
|
+
private String digest(Object headers) {
|
|
159
|
+
List<String[]> pairs = new ArrayList<>();
|
|
160
|
+
if (headers instanceof Map) {
|
|
161
|
+
for (Map.Entry<?, ?> h : ((Map<?, ?>) headers).entrySet()) {
|
|
162
|
+
if (h.getValue() != null) {
|
|
163
|
+
pairs.add(new String[] {String.valueOf(h.getKey()).toLowerCase(), String.valueOf(h.getValue())});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
pairs.sort((a, b) -> a[0].equals(b[0]) ? a[1].compareTo(b[1]) : a[0].compareTo(b[0]));
|
|
168
|
+
try {
|
|
169
|
+
Mac mac = Mac.getInstance("HmacSHA256");
|
|
170
|
+
mac.init(this.secret);
|
|
171
|
+
for (String[] p : pairs) {
|
|
172
|
+
mac.update((p[0] + ":" + p[1] + "\n").getBytes(StandardCharsets.UTF_8));
|
|
173
|
+
}
|
|
174
|
+
StringBuilder hex = new StringBuilder();
|
|
175
|
+
for (byte b : mac.doFinal()) {
|
|
176
|
+
hex.append(String.format("%02x", b));
|
|
177
|
+
}
|
|
178
|
+
return hex.toString();
|
|
179
|
+
}
|
|
180
|
+
catch (GeneralSecurityException err) {
|
|
181
|
+
throw new IllegalStateException(err);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private void invalidate(String url) {
|
|
186
|
+
String path = scope(url);
|
|
187
|
+
String collection = parent(path);
|
|
188
|
+
this.store.values().removeIf((e) -> under(e.scope, path) || e.scope.equals(collection));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// The configured ttl capped by the response's Cache-Control; zero when the
|
|
192
|
+
// response may not be stored.
|
|
193
|
+
private static long lifetime(Map<String, Object> headers, long ttl) {
|
|
194
|
+
String control = "";
|
|
195
|
+
for (Map.Entry<String, Object> h : headers.entrySet()) {
|
|
196
|
+
if ("cache-control".equals(h.getKey().toLowerCase())) {
|
|
197
|
+
control = String.valueOf(h.getValue()).toLowerCase();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
long life = ttl;
|
|
201
|
+
for (String part : control.split(",")) {
|
|
202
|
+
String directive = part.trim();
|
|
203
|
+
if (UNSTORED.contains(directive)) {
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
Matcher age = MAX_AGE.matcher(directive);
|
|
207
|
+
if (age.matches()) {
|
|
208
|
+
try {
|
|
209
|
+
life = Math.min(life, Long.parseLong(age.group(1)) * 1000);
|
|
210
|
+
}
|
|
211
|
+
catch (NumberFormatException err) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return life;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private static String scope(String url) {
|
|
220
|
+
String out = url.split("[?#]", 2)[0];
|
|
221
|
+
while (out.endsWith("/")) {
|
|
222
|
+
out = out.substring(0, out.length() - 1);
|
|
223
|
+
}
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private static String parent(String scope) {
|
|
228
|
+
int scheme = scope.indexOf("://");
|
|
229
|
+
int root = scheme < 0 ? 0 : scope.indexOf('/', scheme + 3);
|
|
230
|
+
if (root < 0) {
|
|
231
|
+
return scope;
|
|
232
|
+
}
|
|
233
|
+
return scope.substring(0, Math.max(scope.lastIndexOf('/'), root));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private static boolean under(String scope, String prefix) {
|
|
237
|
+
return scope.equals(prefix) || scope.startsWith(prefix + "/");
|
|
238
|
+
}
|
|
239
|
+
|
|
135
240
|
// A body the transport could not read as JSON passes through, for the operation to report.
|
|
136
241
|
private boolean storable(Object res) {
|
|
137
242
|
int status = FeatureOptions.fresStatus(res);
|
|
@@ -190,9 +295,10 @@ public class CacheFeature extends BaseFeature {
|
|
|
190
295
|
// evict drops oldest entries (FIFO) until the store is under `max`.
|
|
191
296
|
private void evict() {
|
|
192
297
|
int max = FeatureOptions.foptInt(this.options, "max", 256);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
298
|
+
Iterator<String> oldest = this.store.keySet().iterator();
|
|
299
|
+
while (this.store.size() >= max && oldest.hasNext()) {
|
|
300
|
+
oldest.next();
|
|
301
|
+
oldest.remove();
|
|
196
302
|
}
|
|
197
303
|
}
|
|
198
304
|
}
|
|
@@ -53,6 +53,7 @@ public class DebugFeature extends BaseFeature {
|
|
|
53
53
|
|
|
54
54
|
Map<String, Object> entry = new LinkedHashMap<>();
|
|
55
55
|
entry.put("op", entity + "." + opname);
|
|
56
|
+
entry.put("correlationId", ctx.id);
|
|
56
57
|
entry.put("start", FeatureOptions.foptNow(this.options).getAsLong());
|
|
57
58
|
if (ctx.spec != null) {
|
|
58
59
|
entry.put("method", ctx.spec.method);
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
package JAVAPACKAGE.feature;
|
|
2
2
|
|
|
3
|
-
import java.io.IOException;
|
|
4
3
|
import java.net.URI;
|
|
5
|
-
import java.net.http.HttpClient;
|
|
6
|
-
import java.net.http.HttpRequest;
|
|
7
|
-
import java.net.http.HttpResponse;
|
|
8
4
|
import java.nio.charset.StandardCharsets;
|
|
9
|
-
import java.time.Duration;
|
|
10
5
|
import java.util.ArrayList;
|
|
11
6
|
import java.util.Base64;
|
|
12
7
|
import java.util.Locale;
|
|
@@ -14,7 +9,6 @@ import java.util.LinkedHashMap;
|
|
|
14
9
|
import java.util.List;
|
|
15
10
|
import java.util.Map;
|
|
16
11
|
import java.util.concurrent.CountDownLatch;
|
|
17
|
-
import java.util.function.BiFunction;
|
|
18
12
|
import java.util.function.Supplier;
|
|
19
13
|
|
|
20
14
|
import JAVAPACKAGE.core.Config;
|
|
@@ -695,9 +689,6 @@ public class SecretsFeature extends BaseFeature {
|
|
|
695
689
|
}
|
|
696
690
|
String url = base + "/" + path;
|
|
697
691
|
|
|
698
|
-
Object sysRaw = opts.get("system");
|
|
699
|
-
Object fetchRaw = sysRaw instanceof Map
|
|
700
|
-
? ((Map<String, Object>) sysRaw).get("fetch") : null;
|
|
701
692
|
|
|
702
693
|
// The body is SERIALISED, never concatenated: a refresh token (or a
|
|
703
694
|
// configured request-field name) carrying a quote, backslash or
|
|
@@ -714,12 +705,11 @@ public class SecretsFeature extends BaseFeature {
|
|
|
714
705
|
fetchdef.put("body", Json.stringify(payload));
|
|
715
706
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
716
707
|
fetchdef.put("redirect", "manual");
|
|
708
|
+
// Its own bound, in milliseconds: the timeout feature's wrapper is above it.
|
|
709
|
+
fetchdef.put("timeout", 30000);
|
|
717
710
|
|
|
718
|
-
//
|
|
719
|
-
|
|
720
|
-
// recurse on the first expiry - and would route the exchange through
|
|
721
|
-
// the test mock, which knows nothing about it.
|
|
722
|
-
Object res = exchangeFetch(fetchRaw, url, fetchdef);
|
|
711
|
+
// Not the wrapped transport, which would recurse on the first expiry.
|
|
712
|
+
Object res = exchangeFetch(url, fetchdef);
|
|
723
713
|
|
|
724
714
|
// By option alone, and only while the exchange stays on its own origin.
|
|
725
715
|
String at = url;
|
|
@@ -729,7 +719,7 @@ public class SecretsFeature extends BaseFeature {
|
|
|
729
719
|
break;
|
|
730
720
|
}
|
|
731
721
|
at = next;
|
|
732
|
-
res = exchangeFetch(
|
|
722
|
+
res = exchangeFetch(at, fetchdef);
|
|
733
723
|
}
|
|
734
724
|
|
|
735
725
|
int status = FeatureOptions.fresStatus(res);
|
|
@@ -764,17 +754,10 @@ public class SecretsFeature extends BaseFeature {
|
|
|
764
754
|
return token;
|
|
765
755
|
}
|
|
766
756
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
.apply(url, fetchdef);
|
|
772
|
-
}
|
|
773
|
-
// No custom transport supplied - the ordinary case. makeOptions
|
|
774
|
-
// leaves system.fetch unset, so the exchange gets its own raw HTTP
|
|
775
|
-
// path: requiring a custom transport for the COMMON case would
|
|
776
|
-
// reject every live token purchase before a request was made.
|
|
777
|
-
return rawExchangeFetch(url, fetchdef);
|
|
757
|
+
// The SDK's own transport, beneath every feature's wrapper: it holds the
|
|
758
|
+
// test feature's block and the GET-only guard.
|
|
759
|
+
private Object exchangeFetch(String url, Map<String, Object> fetchdef) {
|
|
760
|
+
return Fetcher.fetcher(this.rootctx, url, fetchdef);
|
|
778
761
|
}
|
|
779
762
|
|
|
780
763
|
// Where a 307 or 308 points, when that is on the exchange's own origin. Any
|
|
@@ -809,72 +792,6 @@ public class SecretsFeature extends BaseFeature {
|
|
|
809
792
|
return scheme + "://" + host.toLowerCase(Locale.ROOT) + ":" + port;
|
|
810
793
|
}
|
|
811
794
|
|
|
812
|
-
// rawExchangeFetch is the token-exchange transport of last resort: plain
|
|
813
|
-
// java.net.http, in the same result shape the system.fetch seam promises
|
|
814
|
-
// ("status" + "json"). utility/Fetcher.defaultHttpFetch is
|
|
815
|
-
// package-private in JAVAPACKAGE.utility and unreachable from here, and
|
|
816
|
-
// reaching for it would put the exchange back on the SDK's own transport
|
|
817
|
-
// stack - which is the thing this must not use.
|
|
818
|
-
private static Map<String, Object> rawExchangeFetch(String fullurl,
|
|
819
|
-
Map<String, Object> fetchdef) {
|
|
820
|
-
|
|
821
|
-
Object methodRaw = fetchdef.get("method");
|
|
822
|
-
String method = methodRaw instanceof String && !"".equals(methodRaw)
|
|
823
|
-
? (String) methodRaw : "POST";
|
|
824
|
-
|
|
825
|
-
Object bodyRaw = fetchdef.get("body");
|
|
826
|
-
String body = bodyRaw instanceof String ? (String) bodyRaw : "";
|
|
827
|
-
|
|
828
|
-
HttpRequest.Builder reqb = HttpRequest.newBuilder(URI.create(fullurl))
|
|
829
|
-
.method(method, "".equals(body)
|
|
830
|
-
? HttpRequest.BodyPublishers.noBody()
|
|
831
|
-
: HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8));
|
|
832
|
-
|
|
833
|
-
Object headersRaw = fetchdef.get("headers");
|
|
834
|
-
if (headersRaw instanceof Map) {
|
|
835
|
-
for (Map.Entry<String, Object> h : ((Map<String, Object>) headersRaw).entrySet()) {
|
|
836
|
-
if (h.getValue() instanceof String) {
|
|
837
|
-
reqb.setHeader(h.getKey(), (String) h.getValue());
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
HttpResponse<String> resp;
|
|
843
|
-
try {
|
|
844
|
-
resp = HttpClient.newBuilder()
|
|
845
|
-
.connectTimeout(Duration.ofSeconds(30))
|
|
846
|
-
.followRedirects(HttpClient.Redirect.NEVER)
|
|
847
|
-
.build()
|
|
848
|
-
.send(reqb.build(), HttpResponse.BodyHandlers.ofString());
|
|
849
|
-
}
|
|
850
|
-
catch (IOException | InterruptedException e) {
|
|
851
|
-
if (e instanceof InterruptedException) {
|
|
852
|
-
Thread.currentThread().interrupt();
|
|
853
|
-
}
|
|
854
|
-
throw new Sekreto.SekretoError(
|
|
855
|
-
"secrets: token exchange transport failed: " + e.getMessage());
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
String text = resp.body() == null ? "" : resp.body();
|
|
859
|
-
Object parsed;
|
|
860
|
-
try {
|
|
861
|
-
parsed = "".equals(text) ? null : Json.parse(text);
|
|
862
|
-
}
|
|
863
|
-
catch (RuntimeException e) {
|
|
864
|
-
parsed = null;
|
|
865
|
-
}
|
|
866
|
-
final Object jsonBody = parsed;
|
|
867
|
-
|
|
868
|
-
Map<String, Object> out = new LinkedHashMap<>();
|
|
869
|
-
out.put("status", resp.statusCode());
|
|
870
|
-
Map<String, Object> rheaders = new LinkedHashMap<>();
|
|
871
|
-
resp.headers().firstValue("location").ifPresent((v) -> rheaders.put("location", v));
|
|
872
|
-
out.put("headers", rheaders);
|
|
873
|
-
out.put("json", (Supplier<Object>) () -> jsonBody);
|
|
874
|
-
out.put("body", text);
|
|
875
|
-
return out;
|
|
876
|
-
}
|
|
877
|
-
|
|
878
795
|
private static void awaitLatch(CountDownLatch latch) {
|
|
879
796
|
try {
|
|
880
797
|
latch.await();
|
|
@@ -61,6 +61,7 @@ public class TelemetryFeature extends BaseFeature {
|
|
|
61
61
|
Map<String, Object> span = new LinkedHashMap<>();
|
|
62
62
|
span.put("traceId", id("trace"));
|
|
63
63
|
span.put("spanId", id("span"));
|
|
64
|
+
span.put("correlationId", ctx.id);
|
|
64
65
|
span.put("name", entity + "." + opname);
|
|
65
66
|
span.put("start", FeatureOptions.foptNow(this.options).getAsLong());
|
|
66
67
|
ctx.out.put(TELEMETRY_SPAN_KEY, span);
|
|
@@ -203,9 +203,14 @@ public class FeatureCorpusTest {
|
|
|
203
203
|
|
|
204
204
|
private static Object invoke(ProjectNameSDK client, Op op, Map<String, Object> ctrl)
|
|
205
205
|
throws Exception {
|
|
206
|
+
return invoke(client, op, ctrl, new LinkedHashMap<String, Object>());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private static Object invoke(ProjectNameSDK client, Op op, Map<String, Object> ctrl,
|
|
210
|
+
Map<String, Object> args) throws Exception {
|
|
206
211
|
Object ent = op.accessor.invoke(client, new Object[] {null});
|
|
207
212
|
try {
|
|
208
|
-
return op.call.invoke(ent, new LinkedHashMap<String, Object>(), ctrl);
|
|
213
|
+
return op.call.invoke(ent, new LinkedHashMap<String, Object>(args), ctrl);
|
|
209
214
|
}
|
|
210
215
|
catch (java.lang.reflect.InvocationTargetException ite) {
|
|
211
216
|
// Unwrap: a reflective call reports the SDK's error as its cause, and a
|
|
@@ -241,6 +246,92 @@ public class FeatureCorpusTest {
|
|
|
241
246
|
return picked;
|
|
242
247
|
}
|
|
243
248
|
|
|
249
|
+
private static final List<String> READ_OPS = List.of("list", "load");
|
|
250
|
+
private static final List<String> WRITE_OPS = List.of("create", "update", "patch", "remove");
|
|
251
|
+
|
|
252
|
+
/** A read and a write of one entity (#READ, #WRITE), each driven as usableOps drives an op. */
|
|
253
|
+
private static Map<String, Op> usablePair() {
|
|
254
|
+
Map<String, Map<String, Op>> found = new LinkedHashMap<>();
|
|
255
|
+
for (Op cand : candidates(buildClient(Map.of()))) {
|
|
256
|
+
int dot = cand.key.indexOf('.');
|
|
257
|
+
String entity = cand.key.substring(0, dot);
|
|
258
|
+
String opname = cand.key.substring(dot + 1);
|
|
259
|
+
String role = READ_OPS.contains(opname) ? "read" : WRITE_OPS.contains(opname) ? "write" : null;
|
|
260
|
+
Map<String, Op> seen = found.computeIfAbsent(entity, (k) -> new LinkedHashMap<>());
|
|
261
|
+
if (null == role || seen.containsKey(role)) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
invoke(buildClient(Map.of()), cand, new LinkedHashMap<>());
|
|
266
|
+
}
|
|
267
|
+
catch (Exception e) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
seen.put(role, cand);
|
|
271
|
+
if (seen.containsKey("read") && seen.containsKey("write")) {
|
|
272
|
+
return seen;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private static final Map<String, Object> ITEM_ARGS = Map.of("id", "corpus-item");
|
|
279
|
+
|
|
280
|
+
private static String entityOf(Op op) {
|
|
281
|
+
return op.key.substring(0, op.key.indexOf('.'));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** A write of one entity (#ITEM) that completes when driven with ITEM_ARGS. */
|
|
285
|
+
private static Op usableItem(String entity) {
|
|
286
|
+
for (Op cand : candidates(buildClient(Map.of()))) {
|
|
287
|
+
String opname = cand.key.substring(cand.key.indexOf('.') + 1);
|
|
288
|
+
if (!entity.equals(entityOf(cand)) || !List.of("update", "patch", "remove").contains(opname)) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
invoke(buildClient(Map.of()), cand, new LinkedHashMap<>(), ITEM_ARGS);
|
|
293
|
+
}
|
|
294
|
+
catch (Exception e) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
return cand;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** One step: it may wait, may add request headers, and may pass `args` as the first argument. */
|
|
303
|
+
private static Object step(ProjectNameSDK client, Op op, Map<String, Object> step,
|
|
304
|
+
Map<String, Object> ctrl) throws Exception {
|
|
305
|
+
if (step.get("wait") instanceof Number) {
|
|
306
|
+
Thread.sleep(((Number) step.get("wait")).longValue());
|
|
307
|
+
}
|
|
308
|
+
Map<String, Object> args = step.get("args") instanceof Map
|
|
309
|
+
? (Map<String, Object>) step.get("args") : new LinkedHashMap<>();
|
|
310
|
+
if (!(step.get("headers") instanceof Map)) {
|
|
311
|
+
return invoke(client, op, ctrl, args);
|
|
312
|
+
}
|
|
313
|
+
Map<String, Object> options = client.getRootCtx().options;
|
|
314
|
+
boolean had = options.containsKey("headers");
|
|
315
|
+
Object prior = options.get("headers");
|
|
316
|
+
Map<String, Object> merged = new LinkedHashMap<>();
|
|
317
|
+
if (prior instanceof Map) {
|
|
318
|
+
merged.putAll((Map<String, Object>) prior);
|
|
319
|
+
}
|
|
320
|
+
merged.putAll((Map<String, Object>) step.get("headers"));
|
|
321
|
+
options.put("headers", merged);
|
|
322
|
+
try {
|
|
323
|
+
return invoke(client, op, ctrl, args);
|
|
324
|
+
}
|
|
325
|
+
finally {
|
|
326
|
+
if (had) {
|
|
327
|
+
options.put("headers", prior);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
options.remove("headers");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
244
335
|
/** Replace #OPn throughout a case, keys included. */
|
|
245
336
|
private static Object resolve(Object node, Map<String, String> tokens) {
|
|
246
337
|
if (node instanceof String) {
|
|
@@ -448,6 +539,23 @@ public class FeatureCorpusTest {
|
|
|
448
539
|
for (Op o : ops) {
|
|
449
540
|
byKey.put(o.key, o);
|
|
450
541
|
}
|
|
542
|
+
Map<String, Op> pair = usablePair();
|
|
543
|
+
if (null != pair) {
|
|
544
|
+
for (Op o : pair.values()) {
|
|
545
|
+
byKey.put(o.key, o);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
Op item = null == pair ? null : usableItem(entityOf(pair.get("read")));
|
|
549
|
+
if (null != item) {
|
|
550
|
+
byKey.put(item.key, item);
|
|
551
|
+
}
|
|
552
|
+
Op other = null;
|
|
553
|
+
for (Op o : null == pair ? List.<Op>of() : ops) {
|
|
554
|
+
if (!entityOf(o).equals(entityOf(pair.get("read")))) {
|
|
555
|
+
other = o;
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
451
559
|
|
|
452
560
|
int ran = 0;
|
|
453
561
|
for (Object rawCase : cases) {
|
|
@@ -460,6 +568,27 @@ public class FeatureCorpusTest {
|
|
|
460
568
|
continue;
|
|
461
569
|
}
|
|
462
570
|
|
|
571
|
+
boolean paired = java.util.regex.Pattern.compile("#(READ|WRITE|ITEM|OTHER)\\b")
|
|
572
|
+
.matcher(String.valueOf(rawCase)).find();
|
|
573
|
+
if (paired && null == pair) {
|
|
574
|
+
System.err.println(String.format(
|
|
575
|
+
"skip \"%s\": needs a read and a write of one entity, this SDK offers none", rawName));
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
String lacking = null;
|
|
580
|
+
if (paired && null == item && String.valueOf(rawCase).matches("(?s).*#ITEM\\b.*")) {
|
|
581
|
+
lacking = "#ITEM";
|
|
582
|
+
}
|
|
583
|
+
else if (paired && null == other && String.valueOf(rawCase).matches("(?s).*#OTHER\\b.*")) {
|
|
584
|
+
lacking = "#OTHER";
|
|
585
|
+
}
|
|
586
|
+
if (null != lacking) {
|
|
587
|
+
System.err.println(String.format(
|
|
588
|
+
"skip \"%s\": needs %s, which this SDK cannot drive", rawName, lacking));
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
|
|
463
592
|
String missing = missingFeature(rawCase, have);
|
|
464
593
|
if (null != missing) {
|
|
465
594
|
System.err.println(String.format(
|
|
@@ -472,6 +601,16 @@ public class FeatureCorpusTest {
|
|
|
472
601
|
for (int i = 0; i < need; i++) {
|
|
473
602
|
tokens.put("#OP" + (i + 1), ops.get(i).key);
|
|
474
603
|
}
|
|
604
|
+
if (paired) {
|
|
605
|
+
tokens.put("#READ", pair.get("read").key);
|
|
606
|
+
tokens.put("#WRITE", pair.get("write").key);
|
|
607
|
+
if (null != item) {
|
|
608
|
+
tokens.put("#ITEM", item.key);
|
|
609
|
+
}
|
|
610
|
+
if (null != other) {
|
|
611
|
+
tokens.put("#OTHER", other.key);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
475
614
|
Map<String, Object> kase = (Map<String, Object>) resolve(rawCase, tokens);
|
|
476
615
|
String label = String.valueOf(kase.get("name"));
|
|
477
616
|
ran++;
|
|
@@ -492,7 +631,7 @@ public class FeatureCorpusTest {
|
|
|
492
631
|
Object wanterr = step.get("err");
|
|
493
632
|
|
|
494
633
|
try {
|
|
495
|
-
|
|
634
|
+
step(client, op, step, ctrl);
|
|
496
635
|
if (null != wanterr) {
|
|
497
636
|
fail(label + ": " + step.get("op") + " was expected to fail, and did not");
|
|
498
637
|
}
|