@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
|
@@ -4,22 +4,21 @@ import (
|
|
|
4
4
|
"encoding/base64"
|
|
5
5
|
"encoding/json"
|
|
6
6
|
"fmt"
|
|
7
|
-
"io"
|
|
8
|
-
"net/http"
|
|
9
7
|
neturl "net/url"
|
|
10
8
|
"strconv"
|
|
11
9
|
"strings"
|
|
12
10
|
"sync"
|
|
13
|
-
"time"
|
|
14
11
|
|
|
15
12
|
"GOMODULE/core"
|
|
16
13
|
plugin "GOMODULE/feature/secrets/plugin"
|
|
17
14
|
sekreto "GOMODULE/feature/secrets/sekreto"
|
|
15
|
+
"GOMODULE/utility"
|
|
18
16
|
)
|
|
19
17
|
|
|
20
18
|
type SecretsFeature struct {
|
|
21
19
|
BaseFeature
|
|
22
20
|
client *core.ProjectNameSDK
|
|
21
|
+
rootctx *core.Context
|
|
23
22
|
options map[string]any
|
|
24
23
|
|
|
25
24
|
liveopts map[string]any
|
|
@@ -41,6 +40,9 @@ type SecretsFeature struct {
|
|
|
41
40
|
cred string
|
|
42
41
|
}
|
|
43
42
|
|
|
43
|
+
// Milliseconds the token purchase may take.
|
|
44
|
+
const secretsExchangeTimeout = 30000
|
|
45
|
+
|
|
44
46
|
type secretsExchange struct {
|
|
45
47
|
path string
|
|
46
48
|
method string
|
|
@@ -82,6 +84,7 @@ func (f *SecretsFeature) Sekreto() *sekreto.Sekreto {
|
|
|
82
84
|
|
|
83
85
|
func (f *SecretsFeature) Init(ctx *core.Context, options map[string]any) {
|
|
84
86
|
f.client = ctx.Client
|
|
87
|
+
f.rootctx = ctx
|
|
85
88
|
f.options = options
|
|
86
89
|
f.liveopts = ctx.Options
|
|
87
90
|
f.Active = foptBool(options, "active", false)
|
|
@@ -489,11 +492,15 @@ func (f *SecretsFeature) buyonce() (string, error) {
|
|
|
489
492
|
base = strings.TrimRight(base, "/")
|
|
490
493
|
url := base + "/" + strings.TrimLeft(x.path, "/")
|
|
491
494
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
// The SDK's own transport, beneath every feature's wrapper: it holds the
|
|
496
|
+
// test feature's block and the GET-only guard.
|
|
497
|
+
fetch := func(at string, fd map[string]any) (map[string]any, error) {
|
|
498
|
+
res, err := utility.Fetcher(f.rootctx, at, fd)
|
|
499
|
+
if nil != err {
|
|
500
|
+
return nil, err
|
|
501
|
+
}
|
|
502
|
+
out, _ := res.(map[string]any)
|
|
503
|
+
return out, nil
|
|
497
504
|
}
|
|
498
505
|
|
|
499
506
|
// The body is MARSHALLED, never concatenated: a refresh token (or a
|
|
@@ -510,6 +517,8 @@ func (f *SecretsFeature) buyonce() (string, error) {
|
|
|
510
517
|
"body": string(bodybytes),
|
|
511
518
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
512
519
|
"redirect": "manual",
|
|
520
|
+
// Its own bound: the timeout feature's wrapper is above this call.
|
|
521
|
+
"timeout": secretsExchangeTimeout,
|
|
513
522
|
}
|
|
514
523
|
|
|
515
524
|
res, err := fetch(url, fetchdef)
|
|
@@ -603,66 +612,3 @@ func secretsOrigin(u *neturl.URL) string {
|
|
|
603
612
|
}
|
|
604
613
|
return scheme + "://" + strings.ToLower(u.Hostname()) + ":" + port
|
|
605
614
|
}
|
|
606
|
-
|
|
607
|
-
// rawExchangeFetch is the token-exchange transport of last resort: plain
|
|
608
|
-
// net/http, same result shape the system.fetch seam promises ("status" +
|
|
609
|
-
// "json"). It exists so an exchange works with ordinary SDK options -
|
|
610
|
-
// requiring a custom transport for the COMMON case would reject every
|
|
611
|
-
// live token purchase before a request was made.
|
|
612
|
-
func rawExchangeFetch(fullurl string, fetchdef map[string]any) (map[string]any, error) {
|
|
613
|
-
method, _ := fetchdef["method"].(string)
|
|
614
|
-
if "" == method {
|
|
615
|
-
method = "POST"
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
var body io.Reader
|
|
619
|
-
if raw, is := fetchdef["body"].(string); is && "" != raw {
|
|
620
|
-
body = strings.NewReader(raw)
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
req, err := http.NewRequest(method, fullurl, body)
|
|
624
|
-
if nil != err {
|
|
625
|
-
return nil, err
|
|
626
|
-
}
|
|
627
|
-
if headers, is := fetchdef["headers"].(map[string]any); is {
|
|
628
|
-
for k, v := range headers {
|
|
629
|
-
if vs, is := v.(string); is {
|
|
630
|
-
req.Header.Set(k, vs)
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
client := &http.Client{
|
|
636
|
-
Timeout: 30 * time.Second,
|
|
637
|
-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
638
|
-
return http.ErrUseLastResponse
|
|
639
|
-
},
|
|
640
|
-
}
|
|
641
|
-
res, err := client.Do(req)
|
|
642
|
-
if nil != err {
|
|
643
|
-
return nil, err
|
|
644
|
-
}
|
|
645
|
-
defer res.Body.Close()
|
|
646
|
-
|
|
647
|
-
raw, err := io.ReadAll(res.Body)
|
|
648
|
-
if nil != err {
|
|
649
|
-
return nil, err
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
headers := map[string]any{}
|
|
653
|
-
for k := range res.Header {
|
|
654
|
-
headers[strings.ToLower(k)] = res.Header.Get(k)
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return map[string]any{
|
|
658
|
-
"status": res.StatusCode,
|
|
659
|
-
"headers": headers,
|
|
660
|
-
"json": func() any {
|
|
661
|
-
var out any
|
|
662
|
-
if nil != json.Unmarshal(raw, &out) {
|
|
663
|
-
return nil
|
|
664
|
-
}
|
|
665
|
-
return out
|
|
666
|
-
},
|
|
667
|
-
}, nil
|
|
668
|
-
}
|
|
@@ -9,6 +9,7 @@ import (
|
|
|
9
9
|
"sort"
|
|
10
10
|
"strings"
|
|
11
11
|
"testing"
|
|
12
|
+
"time"
|
|
12
13
|
|
|
13
14
|
sdk "GOMODULE"
|
|
14
15
|
)
|
|
@@ -185,6 +186,10 @@ func fcCandidates(client *sdk.ProjectNameSDK) []fcOp {
|
|
|
185
186
|
|
|
186
187
|
// fcInvoke performs one operation on a client, by entity name and method.
|
|
187
188
|
func fcInvoke(client *sdk.ProjectNameSDK, op fcOp, ctrl map[string]any) error {
|
|
189
|
+
return fcInvokeArgs(client, op, map[string]any{}, ctrl)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
func fcInvokeArgs(client *sdk.ProjectNameSDK, op fcOp, args map[string]any, ctrl map[string]any) error {
|
|
188
193
|
cv := reflect.ValueOf(client)
|
|
189
194
|
ct := cv.Type()
|
|
190
195
|
mapType := reflect.TypeOf(map[string]any{})
|
|
@@ -208,7 +213,7 @@ func fcInvoke(client *sdk.ProjectNameSDK, op fcOp, ctrl map[string]any) error {
|
|
|
208
213
|
return fmt.Errorf("no method %s on entity %s", op.method, op.accessor)
|
|
209
214
|
}
|
|
210
215
|
rets := om.Call([]reflect.Value{
|
|
211
|
-
reflect.ValueOf(
|
|
216
|
+
reflect.ValueOf(args),
|
|
212
217
|
reflect.ValueOf(ctrl),
|
|
213
218
|
})
|
|
214
219
|
if err, ok := rets[1].Interface().(error); ok && err != nil {
|
|
@@ -239,6 +244,96 @@ func fcUsableOps(want int) []fcOp {
|
|
|
239
244
|
return picked
|
|
240
245
|
}
|
|
241
246
|
|
|
247
|
+
// fcUsablePair finds a read and a write of one entity (#READ, #WRITE), each
|
|
248
|
+
// driven as fcUsableOps drives an op.
|
|
249
|
+
func fcUsablePair() (fcOp, fcOp, bool) {
|
|
250
|
+
reads := map[string]fcOp{}
|
|
251
|
+
writes := map[string]fcOp{}
|
|
252
|
+
for _, cand := range fcCandidates(fcClient(map[string]any{})) {
|
|
253
|
+
role := ""
|
|
254
|
+
switch strings.ToLower(cand.method) {
|
|
255
|
+
case "list", "load":
|
|
256
|
+
role = "read"
|
|
257
|
+
case "create", "update", "patch", "remove":
|
|
258
|
+
role = "write"
|
|
259
|
+
}
|
|
260
|
+
seen := reads
|
|
261
|
+
if role == "write" {
|
|
262
|
+
seen = writes
|
|
263
|
+
}
|
|
264
|
+
if _, done := seen[cand.accessor]; role == "" || done {
|
|
265
|
+
continue
|
|
266
|
+
}
|
|
267
|
+
if err := fcInvoke(fcClient(map[string]any{}), cand, map[string]any{}); err != nil {
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
seen[cand.accessor] = cand
|
|
271
|
+
read, okr := reads[cand.accessor]
|
|
272
|
+
write, okw := writes[cand.accessor]
|
|
273
|
+
if okr && okw {
|
|
274
|
+
return read, write, true
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return fcOp{}, fcOp{}, false
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// fcUsableItem finds a write of one entity (#ITEM) that completes when driven
|
|
281
|
+
// with fcItemArgs.
|
|
282
|
+
func fcUsableItem(entity string) (fcOp, bool) {
|
|
283
|
+
for _, cand := range fcCandidates(fcClient(map[string]any{})) {
|
|
284
|
+
switch strings.ToLower(cand.method) {
|
|
285
|
+
case "update", "patch", "remove":
|
|
286
|
+
default:
|
|
287
|
+
continue
|
|
288
|
+
}
|
|
289
|
+
if cand.accessor != entity {
|
|
290
|
+
continue
|
|
291
|
+
}
|
|
292
|
+
if err := fcInvokeArgs(fcClient(map[string]any{}), cand, fcItemArgs(), map[string]any{}); err == nil {
|
|
293
|
+
return cand, true
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return fcOp{}, false
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
func fcItemArgs() map[string]any {
|
|
300
|
+
return map[string]any{"id": "corpus-item"}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// fcStep runs one step: it may wait before its call, may add request headers
|
|
304
|
+
// for its call, and may pass `args` as the operation's first argument.
|
|
305
|
+
func fcStep(client *sdk.ProjectNameSDK, op fcOp, step map[string]any, ctrl map[string]any) error {
|
|
306
|
+
if wait, ok := fcNum(step["wait"]); ok {
|
|
307
|
+
time.Sleep(time.Duration(wait) * time.Millisecond)
|
|
308
|
+
}
|
|
309
|
+
options := client.GetRootCtx().Options
|
|
310
|
+
prior, had := options["headers"]
|
|
311
|
+
if extra, ok := step["headers"].(map[string]any); ok {
|
|
312
|
+
merged := map[string]any{}
|
|
313
|
+
if pm, ok := prior.(map[string]any); ok {
|
|
314
|
+
for k, v := range pm {
|
|
315
|
+
merged[k] = v
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
for k, v := range extra {
|
|
319
|
+
merged[k] = v
|
|
320
|
+
}
|
|
321
|
+
options["headers"] = merged
|
|
322
|
+
defer func() {
|
|
323
|
+
if had {
|
|
324
|
+
options["headers"] = prior
|
|
325
|
+
} else {
|
|
326
|
+
delete(options, "headers")
|
|
327
|
+
}
|
|
328
|
+
}()
|
|
329
|
+
}
|
|
330
|
+
args, _ := step["args"].(map[string]any)
|
|
331
|
+
if args == nil {
|
|
332
|
+
args = map[string]any{}
|
|
333
|
+
}
|
|
334
|
+
return fcInvokeArgs(client, op, args, ctrl)
|
|
335
|
+
}
|
|
336
|
+
|
|
242
337
|
// fcResolve replaces #OPn throughout a case, keys included.
|
|
243
338
|
func fcResolve(node any, tokens map[string]string) any {
|
|
244
339
|
switch v := node.(type) {
|
|
@@ -419,6 +514,16 @@ func fcMissingFeature(kase map[string]any, have map[string]bool) string {
|
|
|
419
514
|
return ""
|
|
420
515
|
}
|
|
421
516
|
|
|
517
|
+
// fcLacking names the first token a case uses that this SDK cannot drive.
|
|
518
|
+
func fcLacking(encoded string, have map[string]bool) string {
|
|
519
|
+
for _, tok := range []string{"#ITEM", "#OTHER"} {
|
|
520
|
+
if !have[tok] && strings.Contains(encoded, tok) {
|
|
521
|
+
return tok
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return ""
|
|
525
|
+
}
|
|
526
|
+
|
|
422
527
|
func TestFeatureCorpus(t *testing.T) {
|
|
423
528
|
spec := loadTestSpec(t)
|
|
424
529
|
|
|
@@ -429,6 +534,18 @@ func TestFeatureCorpus(t *testing.T) {
|
|
|
429
534
|
|
|
430
535
|
ops := fcUsableOps(2)
|
|
431
536
|
have := map[string]bool{}
|
|
537
|
+
pairRead, pairWrite, paired := fcUsablePair()
|
|
538
|
+
var pairItem, pairOther fcOp
|
|
539
|
+
hasItem, hasOther := false, false
|
|
540
|
+
if paired {
|
|
541
|
+
pairItem, hasItem = fcUsableItem(pairRead.accessor)
|
|
542
|
+
for _, o := range ops {
|
|
543
|
+
if o.accessor != pairRead.accessor {
|
|
544
|
+
pairOther, hasOther = o, true
|
|
545
|
+
break
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
432
549
|
|
|
433
550
|
// With every operation needing an argument there is nothing to drive:
|
|
434
551
|
// skip and say so, as the clean test does, rather than fail.
|
|
@@ -483,6 +600,20 @@ func TestFeatureCorpus(t *testing.T) {
|
|
|
483
600
|
continue
|
|
484
601
|
}
|
|
485
602
|
|
|
603
|
+
encoded, _ := json.Marshal(kase)
|
|
604
|
+
wantsPair := strings.Contains(string(encoded), "#READ") || strings.Contains(string(encoded), "#WRITE") ||
|
|
605
|
+
strings.Contains(string(encoded), "#ITEM") || strings.Contains(string(encoded), "#OTHER")
|
|
606
|
+
if wantsPair && !paired {
|
|
607
|
+
t.Logf("skip %q: needs a read and a write of one entity, this SDK offers none",
|
|
608
|
+
kase["name"])
|
|
609
|
+
continue
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if lacking := fcLacking(string(encoded), map[string]bool{"#ITEM": hasItem, "#OTHER": hasOther}); paired && lacking != "" {
|
|
613
|
+
t.Logf("skip %q: needs %s, which this SDK cannot drive", kase["name"], lacking)
|
|
614
|
+
continue
|
|
615
|
+
}
|
|
616
|
+
|
|
486
617
|
if missing := fcMissingFeature(kase, have); missing != "" {
|
|
487
618
|
t.Logf("skip %q: needs the %s feature, which this SDK does not generate",
|
|
488
619
|
kase["name"], missing)
|
|
@@ -493,12 +624,29 @@ func TestFeatureCorpus(t *testing.T) {
|
|
|
493
624
|
for i := 0; i < need; i++ {
|
|
494
625
|
tokens[fmt.Sprintf("#OP%d", i+1)] = ops[i].key
|
|
495
626
|
}
|
|
627
|
+
if wantsPair {
|
|
628
|
+
tokens["#READ"] = pairRead.key
|
|
629
|
+
tokens["#WRITE"] = pairWrite.key
|
|
630
|
+
if hasItem {
|
|
631
|
+
tokens["#ITEM"] = pairItem.key
|
|
632
|
+
}
|
|
633
|
+
if hasOther {
|
|
634
|
+
tokens["#OTHER"] = pairOther.key
|
|
635
|
+
}
|
|
636
|
+
}
|
|
496
637
|
resolved, _ := fcResolve(kase, tokens).(map[string]any)
|
|
497
638
|
|
|
498
639
|
byKey := map[string]fcOp{}
|
|
499
640
|
for _, o := range ops {
|
|
500
641
|
byKey[o.key] = o
|
|
501
642
|
}
|
|
643
|
+
if paired {
|
|
644
|
+
byKey[pairRead.key] = pairRead
|
|
645
|
+
byKey[pairWrite.key] = pairWrite
|
|
646
|
+
if hasItem {
|
|
647
|
+
byKey[pairItem.key] = pairItem
|
|
648
|
+
}
|
|
649
|
+
}
|
|
502
650
|
|
|
503
651
|
client := fcClient(resolved)
|
|
504
652
|
label, _ := resolved["name"].(string)
|
|
@@ -520,7 +668,7 @@ func TestFeatureCorpus(t *testing.T) {
|
|
|
520
668
|
ctrl = c
|
|
521
669
|
}
|
|
522
670
|
|
|
523
|
-
err :=
|
|
671
|
+
err := fcStep(client, op, step, ctrl)
|
|
524
672
|
wanterr, haserr := step["err"]
|
|
525
673
|
|
|
526
674
|
if !haserr {
|
|
@@ -645,6 +645,67 @@ func TestFeatureCache(t *testing.T) {
|
|
|
645
645
|
}
|
|
646
646
|
})
|
|
647
647
|
|
|
648
|
+
t.Run("keys-on-request-headers", func(t *testing.T) {
|
|
649
|
+
rec := &fhRecorder{}
|
|
650
|
+
h := fhMake(rec.fetch, fhF(feat.NewCacheFeature(), map[string]any{"ttl": 10000}))
|
|
651
|
+
h.op(fhOpSpec{op: "load", path: "/w/1", headers: map[string]any{"x-tenant": "tenant-a"}})
|
|
652
|
+
h.op(fhOpSpec{op: "load", path: "/w/1", headers: map[string]any{"X-Tenant": "tenant-b"}})
|
|
653
|
+
if len(rec.calls) != 2 {
|
|
654
|
+
t.Errorf("a second tenant was served the first tenant's entry: %d calls", len(rec.calls))
|
|
655
|
+
}
|
|
656
|
+
h.op(fhOpSpec{op: "load", path: "/w/1", headers: map[string]any{"x-tenant": "tenant-b"}})
|
|
657
|
+
if len(rec.calls) != 2 {
|
|
658
|
+
t.Errorf("the same headers did not share an entry: %d calls", len(rec.calls))
|
|
659
|
+
}
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
t.Run("a-write-drops-its-collection", func(t *testing.T) {
|
|
663
|
+
rec := &fhRecorder{}
|
|
664
|
+
h := fhMake(rec.fetch, fhF(feat.NewCacheFeature(), map[string]any{"ttl": 10000}))
|
|
665
|
+
paths := []string{"/w/1", "/w", "/w/1/part", "/other/1", "/w/2"}
|
|
666
|
+
for _, p := range paths {
|
|
667
|
+
h.op(fhOpSpec{op: "load", path: p})
|
|
668
|
+
}
|
|
669
|
+
h.op(fhOpSpec{op: "update", method: "PUT", path: "/w/1"})
|
|
670
|
+
for _, p := range paths {
|
|
671
|
+
h.op(fhOpSpec{op: "load", path: p})
|
|
672
|
+
}
|
|
673
|
+
if len(rec.calls) != 9 {
|
|
674
|
+
t.Errorf("expected the collection refetched and /other cached: %d calls", len(rec.calls))
|
|
675
|
+
}
|
|
676
|
+
})
|
|
677
|
+
|
|
678
|
+
t.Run("cache-control-prevents-storing", func(t *testing.T) {
|
|
679
|
+
for _, control := range []string{"no-store", "private", "No-Cache", "max-age=60, private"} {
|
|
680
|
+
rec := &fhRecorder{reply: func(_ int, _ map[string]any) (any, error) {
|
|
681
|
+
return fhResponse(200, map[string]any{"ok": true}, map[string]any{"Cache-Control": control}), nil
|
|
682
|
+
}}
|
|
683
|
+
h := fhMake(rec.fetch, fhF(feat.NewCacheFeature(), map[string]any{"ttl": 10000}))
|
|
684
|
+
h.op(fhOpSpec{op: "load", path: "/w"})
|
|
685
|
+
h.op(fhOpSpec{op: "load", path: "/w"})
|
|
686
|
+
if len(rec.calls) != 2 {
|
|
687
|
+
t.Errorf("%s was stored: %d calls", control, len(rec.calls))
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
t.Run("max-age-caps-the-ttl", func(t *testing.T) {
|
|
693
|
+
clock := &fhClock{}
|
|
694
|
+
rec := &fhRecorder{reply: func(_ int, _ map[string]any) (any, error) {
|
|
695
|
+
return fhResponse(200, map[string]any{"ok": true}, map[string]any{"cache-control": "max-age=1"}), nil
|
|
696
|
+
}}
|
|
697
|
+
h := fhMake(rec.fetch, fhF(feat.NewCacheFeature(),
|
|
698
|
+
map[string]any{"ttl": 10000, "now": clock.now}))
|
|
699
|
+
h.op(fhOpSpec{op: "load", path: "/w"})
|
|
700
|
+
clock.advance(500)
|
|
701
|
+
h.op(fhOpSpec{op: "load", path: "/w"})
|
|
702
|
+
clock.advance(600)
|
|
703
|
+
h.op(fhOpSpec{op: "load", path: "/w"})
|
|
704
|
+
if len(rec.calls) != 2 {
|
|
705
|
+
t.Errorf("expected max-age=1 to expire the entry before the ttl: %d calls", len(rec.calls))
|
|
706
|
+
}
|
|
707
|
+
})
|
|
708
|
+
|
|
648
709
|
t.Run("inactive-does-not-wrap", func(t *testing.T) {
|
|
649
710
|
rec := &fhRecorder{}
|
|
650
711
|
h := fhMake(rec.fetch, fhF(feat.NewCacheFeature(), map[string]any{"active": false}))
|
|
@@ -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");
|