@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
|
@@ -59,12 +59,9 @@
|
|
|
59
59
|
// fails). Conflating the last two is the failure this library exists
|
|
60
60
|
// to prevent.
|
|
61
61
|
//
|
|
62
|
-
// * The exchange
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
// when a plugin group is active, the SDK's own client (utility/http.c)
|
|
66
|
-
// when none is (see Config_c; the generated kinds.mk beside it is what
|
|
67
|
-
// links libcurl on the same condition).
|
|
62
|
+
// * The exchange goes through fetcher_util, the SDK's own transport
|
|
63
|
+
// beneath every feature's wrapper: options.system.fetch when supplied,
|
|
64
|
+
// else the SDK's own client (utility/http.c).
|
|
68
65
|
//
|
|
69
66
|
// * sek_new is documented NOT REENTRANT (a file-scope slot for the
|
|
70
67
|
// duration of the call). It runs once, in the client constructor,
|
|
@@ -85,13 +82,6 @@
|
|
|
85
82
|
#include <stdlib.h>
|
|
86
83
|
#include <string.h>
|
|
87
84
|
|
|
88
|
-
// The exchange transport of last resort, defined in the GENERATED
|
|
89
|
-
// feature/secrets/kinds.c (Config_c) - libcurl when a plugin group is
|
|
90
|
-
// active, the SDK's own client otherwise. Prototyped here rather than in
|
|
91
|
-
// sdk.h because core/ must not know a gated feature's internals.
|
|
92
|
-
voxgig_value* secrets_rawfetch(Context* ctx, const char* url,
|
|
93
|
-
voxgig_value* fetchdef, PNError** err);
|
|
94
|
-
|
|
95
85
|
typedef struct {
|
|
96
86
|
const char* path;
|
|
97
87
|
const char* method;
|
|
@@ -120,6 +110,8 @@ typedef struct {
|
|
|
120
110
|
// The LIVE options map (root ctx options): read for `apikey` and `auth`,
|
|
121
111
|
// never written.
|
|
122
112
|
voxgig_value* liveopts;
|
|
113
|
+
// The client's clean registry, which a resolved value joins.
|
|
114
|
+
voxgig_value* cleancfg;
|
|
123
115
|
|
|
124
116
|
// What prepare_auth was generated from: the config declares auth only
|
|
125
117
|
// where it places a credential, and Basic only where it composes one.
|
|
@@ -144,6 +136,9 @@ typedef struct {
|
|
|
144
136
|
|
|
145
137
|
SecretsExchange* exchange;
|
|
146
138
|
char* refresh;
|
|
139
|
+
// The transport's refusal of the last purchase, which the gate answers
|
|
140
|
+
// in place of a resolution error.
|
|
141
|
+
PNError* refused;
|
|
147
142
|
|
|
148
143
|
SecretsTrack track;
|
|
149
144
|
} SecretsFeature;
|
|
@@ -345,7 +340,7 @@ static void secrets_reauth(SecretsFeature* f, voxgig_value* fetchdef) {
|
|
|
345
340
|
snprintf(pair, n, "%s:%s", f->cred, secret);
|
|
346
341
|
value = clean_base64(pair);
|
|
347
342
|
free(pair);
|
|
348
|
-
if (NULL != value)
|
|
343
|
+
if (NULL != value) clean_add_cfg(f->cleancfg, value);
|
|
349
344
|
} else {
|
|
350
345
|
value = strdup(f->cred);
|
|
351
346
|
}
|
|
@@ -375,7 +370,7 @@ static void secrets_reauth(SecretsFeature* f, voxgig_value* fetchdef) {
|
|
|
375
370
|
static void secrets_setcred(SecretsFeature* f, const char* value) {
|
|
376
371
|
free(f->cred);
|
|
377
372
|
f->cred = strdup(NULL == value ? "" : value);
|
|
378
|
-
if ('\0' != f->cred[0])
|
|
373
|
+
if ('\0' != f->cred[0]) clean_add_cfg(f->cleancfg, f->cred);
|
|
379
374
|
}
|
|
380
375
|
|
|
381
376
|
// ---- the exchange -----------------------------------------------------------
|
|
@@ -449,25 +444,23 @@ static char* secrets_moved(sek_pool* pool, const char* url, const char* at, voxg
|
|
|
449
444
|
return secrets_origin(next, to, sizeof(to), NULL) && 0 == strcmp(own, to) ? next : NULL;
|
|
450
445
|
}
|
|
451
446
|
|
|
452
|
-
// One request of the exchange
|
|
453
|
-
//
|
|
454
|
-
|
|
447
|
+
// One request of the exchange, through the SDK's own transport beneath every
|
|
448
|
+
// feature's wrapper: it holds the test feature's block and the GET-only
|
|
449
|
+
// guard, and its refusal is kept for the gate. A pool-owned message on failure.
|
|
450
|
+
static const char* secrets_send(SecretsFeature* f, Context* ctx,
|
|
455
451
|
const char* url, voxgig_value* fetchdef, voxgig_value** res) {
|
|
456
|
-
if (voxgig_is_func(sys_fetch)) {
|
|
457
|
-
*res = call_vfn(sys_fetch, clist(2, v_str(url), v_share(fetchdef)));
|
|
458
|
-
const char* emsg = get_str(*res, "__err__");
|
|
459
|
-
return NULL == emsg ? NULL : sek_strdup(f->pool, emsg);
|
|
460
|
-
}
|
|
461
452
|
PNError* ferr = NULL;
|
|
462
|
-
*res =
|
|
463
|
-
|
|
464
|
-
|
|
453
|
+
*res = fetcher_util(NULL, ctx, url, fetchdef, &ferr);
|
|
454
|
+
if (NULL == ferr) return NULL;
|
|
455
|
+
f->refused = ferr;
|
|
456
|
+
return sek_strdup(f->pool, ferr->msg ? ferr->msg : "secrets: transport failed");
|
|
465
457
|
}
|
|
466
458
|
|
|
467
459
|
// Buy an access token with the refresh token. Answers sekreto-style: a
|
|
468
460
|
// pool-owned message, or NULL for success with the token in f->cred.
|
|
469
461
|
static const char* secrets_buy(SecretsFeature* f, Context* ctx) {
|
|
470
462
|
SecretsExchange* x = f->exchange;
|
|
463
|
+
f->refused = NULL;
|
|
471
464
|
|
|
472
465
|
// TEST MODE BUYS NOTHING. The test feature replaces the transport so no
|
|
473
466
|
// request leaves the process; an exchange here would be the one HTTP
|
|
@@ -518,15 +511,8 @@ static const char* secrets_buy(SecretsFeature* f, Context* ctx) {
|
|
|
518
511
|
"body", v_str(bodytext),
|
|
519
512
|
"redirect", v_str("manual"));
|
|
520
513
|
|
|
521
|
-
// Deliberately NOT the SDK transport. The transport is what this feature
|
|
522
|
-
// wraps, and sending the token request back through it would recurse on
|
|
523
|
-
// the first expiry - and would route the exchange through the test mock,
|
|
524
|
-
// which knows nothing about it. options.system.fetch when the caller
|
|
525
|
-
// supplied one (the seam every live c request already uses), else the
|
|
526
|
-
// bundled transport of last resort from the generated kinds.c.
|
|
527
|
-
voxgig_value* sys_fetch = getpath2(options, "system", "fetch");
|
|
528
514
|
voxgig_value* res = NULL;
|
|
529
|
-
const char* sent = secrets_send(f, ctx,
|
|
515
|
+
const char* sent = secrets_send(f, ctx, url, fetchdef, &res);
|
|
530
516
|
if (NULL != sent) return sent;
|
|
531
517
|
|
|
532
518
|
// By option alone, and only while the exchange stays on its own origin.
|
|
@@ -535,7 +521,7 @@ static const char* secrets_buy(SecretsFeature* f, Context* ctx) {
|
|
|
535
521
|
char* next = secrets_moved(f->pool, url, at, res);
|
|
536
522
|
if (NULL == next) break;
|
|
537
523
|
at = next;
|
|
538
|
-
sent = secrets_send(f, ctx,
|
|
524
|
+
sent = secrets_send(f, ctx, at, fetchdef, &res);
|
|
539
525
|
if (NULL != sent) return sent;
|
|
540
526
|
}
|
|
541
527
|
|
|
@@ -612,7 +598,7 @@ static const char* secrets_resolve(SecretsFeature* f, Context* ctx) {
|
|
|
612
598
|
// say whether it does.
|
|
613
599
|
free(f->refresh);
|
|
614
600
|
f->refresh = strdup(found ? found : "");
|
|
615
|
-
if ('\0' != f->refresh[0])
|
|
601
|
+
if ('\0' != f->refresh[0]) clean_add_cfg(f->cleancfg, f->refresh);
|
|
616
602
|
|
|
617
603
|
if ('\0' == f->cred[0]) {
|
|
618
604
|
// A starting access token supplied as the OPTION: read from the frozen
|
|
@@ -655,7 +641,8 @@ static voxgig_value* secrets_fetch(Fetcher* self, Context* ctx, const char* url,
|
|
|
655
641
|
const char* rerr = secrets_resolve(f, ctx);
|
|
656
642
|
if (NULL != rerr) {
|
|
657
643
|
f->track.refused++;
|
|
658
|
-
*err = context_make_error(ctx, "secrets_resolve", rerr);
|
|
644
|
+
*err = NULL != f->refused ? f->refused : context_make_error(ctx, "secrets_resolve", rerr);
|
|
645
|
+
f->refused = NULL;
|
|
659
646
|
return NULL;
|
|
660
647
|
}
|
|
661
648
|
|
|
@@ -701,6 +688,7 @@ static voxgig_value* secrets_fetch(Fetcher* self, Context* ctx, const char* url,
|
|
|
701
688
|
// The purchase failed: answer with the API's own refusal rather
|
|
702
689
|
// than this one. The caller asked for data, and the refusal is
|
|
703
690
|
// the more useful of the two - the exchange error is a symptom.
|
|
691
|
+
f->refused = NULL;
|
|
704
692
|
free(used);
|
|
705
693
|
return out;
|
|
706
694
|
}
|
|
@@ -733,6 +721,7 @@ static void secrets_init(Feature* fb, Context* ctx, voxgig_value* options) {
|
|
|
733
721
|
|
|
734
722
|
f->client = ctx->client;
|
|
735
723
|
f->liveopts = ctx->options;
|
|
724
|
+
f->cleancfg = ctx->cleancfg;
|
|
736
725
|
|
|
737
726
|
voxgig_value* declared = NULL == ctx->config ? NULL : getpath2(ctx->config, "options", "auth");
|
|
738
727
|
f->declared = voxgig_is_map(declared);
|
|
@@ -802,7 +791,7 @@ static void secrets_init(Feature* fb, Context* ctx, voxgig_value* options) {
|
|
|
802
791
|
} else {
|
|
803
792
|
explicit = get_str(xopts, "refresh");
|
|
804
793
|
}
|
|
805
|
-
if (NULL != explicit && '\0' != explicit[0])
|
|
794
|
+
if (NULL != explicit && '\0' != explicit[0]) clean_add_cfg(f->cleancfg, explicit);
|
|
806
795
|
|
|
807
796
|
size_t cap = 4;
|
|
808
797
|
size_t count = 0;
|
|
@@ -501,6 +501,105 @@ static void test_cache_inactive_does_not_wrap(void) {
|
|
|
501
501
|
CHECK_INT_EQ(rec_count(calls), 2, "cache inactive: 2 calls");
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
+
uint64_t feature_cache_siphash24(const uint8_t key[16], const uint8_t* in, size_t len);
|
|
505
|
+
|
|
506
|
+
// The reference vectors of the SipHash paper: key 00..0f, message 00..len-1.
|
|
507
|
+
static void test_cache_siphash_matches_the_reference_vectors(void) {
|
|
508
|
+
if (!fh_present("cache")) return;
|
|
509
|
+
static const struct { size_t len; uint64_t want; } vectors[] = {
|
|
510
|
+
{0, 0x726fdb47dd0e0e31ULL},
|
|
511
|
+
{1, 0x74f839c593dc67fdULL},
|
|
512
|
+
{2, 0x0d6c8009d9a94f5aULL},
|
|
513
|
+
{3, 0x85676696d7fb7e2dULL},
|
|
514
|
+
{4, 0xcf2794e0277187b7ULL},
|
|
515
|
+
{5, 0x18765564cd99a68dULL},
|
|
516
|
+
{6, 0xcbc9466e58fee3ceULL},
|
|
517
|
+
{7, 0xab0200f58b01d137ULL},
|
|
518
|
+
{8, 0x93f5f5799a932462ULL},
|
|
519
|
+
{15, 0xa129ca6149be45e5ULL},
|
|
520
|
+
{16, 0x3f2acc7f57c29bdbULL},
|
|
521
|
+
{63, 0x958a324ceb064572ULL}
|
|
522
|
+
};
|
|
523
|
+
uint8_t key[16], msg[64];
|
|
524
|
+
for (int i = 0; i < 16; i++) key[i] = (uint8_t)i;
|
|
525
|
+
for (int i = 0; i < 64; i++) msg[i] = (uint8_t)i;
|
|
526
|
+
for (size_t i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
|
|
527
|
+
CHECK(feature_cache_siphash24(key, msg, vectors[i].len) == vectors[i].want, "cache: siphash reference vector");
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
static voxgig_value* rep_control(void* ud, int64_t n, voxgig_value* fd, Context* ctx, PNError** e) {
|
|
532
|
+
(void)n; (void)fd; (void)ctx; *e = NULL;
|
|
533
|
+
return fh_response(200, cmap(1, "ok", v_bool(true)),
|
|
534
|
+
cmap(1, "Cache-Control", v_str((const char*)ud)));
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
static FhOpSpec op_load_headers(const char* path, voxgig_value* headers) {
|
|
538
|
+
FhOpSpec o = op_load_path(path); o.headers = headers; return o;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
static void test_cache_keys_on_request_headers(void) {
|
|
542
|
+
if (!fh_present("cache")) return;
|
|
543
|
+
voxgig_value* calls;
|
|
544
|
+
Fetcher* srv = fh_recorder(NULL, NULL, &calls);
|
|
545
|
+
Feature* f = feature_cache_new();
|
|
546
|
+
FhFeat feats[] = {{f, cmap(1, "ttl", v_num(10000))}};
|
|
547
|
+
FhHarness h = fh_make(srv, feats, 1);
|
|
548
|
+
fh_op(&h, op_load_headers("/w/1", cmap(1, "x-tenant", v_str("tenant-a"))));
|
|
549
|
+
fh_op(&h, op_load_headers("/w/1", cmap(1, "X-Tenant", v_str("tenant-b"))));
|
|
550
|
+
CHECK_INT_EQ(rec_count(calls), 2, "cache tenant header: 2 calls");
|
|
551
|
+
fh_op(&h, op_load_headers("/w/1", cmap(1, "x-tenant", v_str("tenant-b"))));
|
|
552
|
+
CHECK_INT_EQ(rec_count(calls), 2, "cache same headers: still 2 calls");
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
static void test_cache_a_write_drops_its_collection(void) {
|
|
556
|
+
if (!fh_present("cache")) return;
|
|
557
|
+
voxgig_value* calls;
|
|
558
|
+
Fetcher* srv = fh_recorder(NULL, NULL, &calls);
|
|
559
|
+
Feature* f = feature_cache_new();
|
|
560
|
+
FhFeat feats[] = {{f, cmap(1, "ttl", v_num(10000))}};
|
|
561
|
+
FhHarness h = fh_make(srv, feats, 1);
|
|
562
|
+
const char* paths[] = {"/w/1", "/w", "/w/1/part", "/other/1", "/w/2"};
|
|
563
|
+
for (int i = 0; i < 5; i++) fh_op(&h, op_load_path(paths[i]));
|
|
564
|
+
FhOpSpec w; memset(&w, 0, sizeof(w)); w.op = "update"; w.method = "PUT"; w.path = "/w/1";
|
|
565
|
+
fh_op(&h, w);
|
|
566
|
+
for (int i = 0; i < 5; i++) fh_op(&h, op_load_path(paths[i]));
|
|
567
|
+
CHECK_INT_EQ(rec_count(calls), 9, "cache write: collection refetched");
|
|
568
|
+
CHECK_INT_EQ(fh_track_int(f, "hit"), 2, "cache write: other entity cached");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
static void test_cache_control_prevents_storing(void) {
|
|
572
|
+
if (!fh_present("cache")) return;
|
|
573
|
+
const char* controls[] = {"no-store", "private", "No-Cache", "max-age=60, private"};
|
|
574
|
+
for (int i = 0; i < 4; i++) {
|
|
575
|
+
voxgig_value* calls;
|
|
576
|
+
Fetcher* srv = fh_recorder(rep_control, (void*)controls[i], &calls);
|
|
577
|
+
Feature* f = feature_cache_new();
|
|
578
|
+
FhFeat feats[] = {{f, cmap(1, "ttl", v_num(10000))}};
|
|
579
|
+
FhHarness h = fh_make(srv, feats, 1);
|
|
580
|
+
fh_op(&h, op_load_path("/w"));
|
|
581
|
+
fh_op(&h, op_load_path("/w"));
|
|
582
|
+
CHECK_INT_EQ(rec_count(calls), 2, controls[i]);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
static void test_cache_max_age_caps_the_ttl(void) {
|
|
587
|
+
if (!fh_present("cache")) return;
|
|
588
|
+
FhClock clock = fh_clock_new();
|
|
589
|
+
voxgig_value* calls;
|
|
590
|
+
Fetcher* srv = fh_recorder(rep_control, (void*)"max-age=1", &calls);
|
|
591
|
+
Feature* f = feature_cache_new();
|
|
592
|
+
FhFeat feats[] = {{f, cmap(2, "ttl", v_num(10000), "now", fh_now_fn(&clock))}};
|
|
593
|
+
FhHarness h = fh_make(srv, feats, 1);
|
|
594
|
+
fh_op(&h, op_load_path("/w"));
|
|
595
|
+
fh_advance(&clock, 500);
|
|
596
|
+
fh_op(&h, op_load_path("/w"));
|
|
597
|
+
CHECK_INT_EQ(rec_count(calls), 1, "cache max-age: a hit inside max-age");
|
|
598
|
+
fh_advance(&clock, 600);
|
|
599
|
+
fh_op(&h, op_load_path("/w"));
|
|
600
|
+
CHECK_INT_EQ(rec_count(calls), 2, "cache max-age: expired before the ttl");
|
|
601
|
+
}
|
|
602
|
+
|
|
504
603
|
// =============================================================================
|
|
505
604
|
// idempotency
|
|
506
605
|
// =============================================================================
|
|
@@ -1216,6 +1315,11 @@ int main(void) {
|
|
|
1216
1315
|
RUN(test_cache_refetches_after_ttl);
|
|
1217
1316
|
RUN(test_cache_evicts_oldest_past_max);
|
|
1218
1317
|
RUN(test_cache_inactive_does_not_wrap);
|
|
1318
|
+
RUN(test_cache_keys_on_request_headers);
|
|
1319
|
+
RUN(test_cache_a_write_drops_its_collection);
|
|
1320
|
+
RUN(test_cache_control_prevents_storing);
|
|
1321
|
+
RUN(test_cache_max_age_caps_the_ttl);
|
|
1322
|
+
RUN(test_cache_siphash_matches_the_reference_vectors);
|
|
1219
1323
|
// idempotency
|
|
1220
1324
|
RUN(test_idempotency_adds_key_to_mutating_ops);
|
|
1221
1325
|
RUN(test_idempotency_adds_key_by_http_method);
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
// sensitive KEY name is masked whatever it holds. Inside the pipeline data
|
|
8
8
|
// stays raw, so a hook can still read the header it must add to.
|
|
9
9
|
//
|
|
10
|
-
// The registry is the `values` list of the
|
|
11
|
-
//
|
|
12
|
-
// pointer, so a feature registering a value
|
|
13
|
-
// every context reads.
|
|
10
|
+
// The registry is the `values` list of the clean block that make_options
|
|
11
|
+
// builds and holds on the context as `cleancfg`, beside the options rather
|
|
12
|
+
// than in them. Nodes are shared by pointer, so a feature registering a value
|
|
13
|
+
// later reaches the same list every context reads.
|
|
14
14
|
|
|
15
15
|
#include "sdk.h"
|
|
16
16
|
|
|
@@ -142,16 +142,12 @@ voxgig_value* clean_make_config(voxgig_value* cleanopts) {
|
|
|
142
142
|
"min", v_int(min));
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
return getpath2(options, "__derived__", "clean");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// A context without options (make_error is reached with a bare one) falls
|
|
145
|
+
// A context without a registry (make_error is reached with a bare one) falls
|
|
150
146
|
// back to the schema defaults, so nothing leaves raw for want of a
|
|
151
147
|
// constructor.
|
|
152
148
|
static voxgig_value* config_block(Context* ctx) {
|
|
153
|
-
voxgig_value*
|
|
154
|
-
if (voxgig_is_map(
|
|
149
|
+
voxgig_value* cfg = ctx ? ctx->cleancfg : NULL;
|
|
150
|
+
if (voxgig_is_map(cfg)) return cfg;
|
|
155
151
|
return clean_make_config(getp(shared_optspec(), "clean"));
|
|
156
152
|
}
|
|
157
153
|
|
|
@@ -227,12 +223,11 @@ static int longest_first(const void* a, const void* b) {
|
|
|
227
223
|
return la < lb ? 1 : (la > lb ? -1 : 0);
|
|
228
224
|
}
|
|
229
225
|
|
|
230
|
-
// Register a secret value
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
void
|
|
226
|
+
// Register a secret value in a clean registry. Idempotent; shorter than
|
|
227
|
+
// `min` is not a secret the SDK can mask without blanking ordinary text.
|
|
228
|
+
// Anything but a registry map registers nothing.
|
|
229
|
+
void clean_add_cfg(voxgig_value* block, const char* value) {
|
|
234
230
|
if (!value) return;
|
|
235
|
-
voxgig_value* block = derived_block(options);
|
|
236
231
|
if (!voxgig_is_map(block)) return;
|
|
237
232
|
int64_t min = count(getp(block, "min"), 4);
|
|
238
233
|
if (min < 1) min = 1;
|
|
@@ -267,10 +262,10 @@ void clean_add_opts(voxgig_value* options, const char* value) {
|
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
264
|
|
|
270
|
-
// Register a secret value the context's
|
|
265
|
+
// Register a secret value the context's registry will mask from now on.
|
|
271
266
|
void clean_add_util(Context* ctx, const char* value) {
|
|
272
267
|
if (!ctx) return;
|
|
273
|
-
|
|
268
|
+
clean_add_cfg(ctx->cleancfg, value);
|
|
274
269
|
}
|
|
275
270
|
|
|
276
271
|
static char* mask_value(const CleanCfg* cfg, const char* value) {
|
|
@@ -507,10 +502,9 @@ char* clean_str(Context* ctx, const char* val) {
|
|
|
507
502
|
return clean_string(&cfg, val);
|
|
508
503
|
}
|
|
509
504
|
|
|
510
|
-
// Clean a value against
|
|
511
|
-
//
|
|
512
|
-
voxgig_value*
|
|
513
|
-
voxgig_value* block = derived_block(options);
|
|
505
|
+
// Clean a value against a registry rather than a context, for a feature
|
|
506
|
+
// that holds the registry but no context.
|
|
507
|
+
voxgig_value* clean_cfg(voxgig_value* block, voxgig_value* val) {
|
|
514
508
|
if (!voxgig_is_map(block)) return val;
|
|
515
509
|
CleanCfg cfg;
|
|
516
510
|
read_cfg(block, &cfg);
|
|
@@ -549,17 +543,17 @@ typedef struct {
|
|
|
549
543
|
size_t cap;
|
|
550
544
|
} Visited;
|
|
551
545
|
|
|
552
|
-
static void add_sensitive(const CleanCfg* cfg, voxgig_value*
|
|
546
|
+
static void add_sensitive(const CleanCfg* cfg, voxgig_value* block, voxgig_value* val,
|
|
553
547
|
bool under, size_t depth, Visited* seen) {
|
|
554
548
|
if (!val || CLEAN_MAXDEPTH <= depth) return;
|
|
555
549
|
if (voxgig_is_string(val)) {
|
|
556
|
-
if (under)
|
|
550
|
+
if (under) clean_add_cfg(block, voxgig_as_string(val));
|
|
557
551
|
return;
|
|
558
552
|
}
|
|
559
553
|
if (voxgig_is_number(val)) {
|
|
560
554
|
if (under) {
|
|
561
555
|
char* text = voxgig_stringify(val, -1);
|
|
562
|
-
|
|
556
|
+
clean_add_cfg(block, text);
|
|
563
557
|
free(text);
|
|
564
558
|
}
|
|
565
559
|
return;
|
|
@@ -579,33 +573,32 @@ static void add_sensitive(const CleanCfg* cfg, voxgig_value* options, voxgig_val
|
|
|
579
573
|
if (voxgig_is_list(val)) {
|
|
580
574
|
voxgig_list* l = voxgig_as_list(val);
|
|
581
575
|
for (size_t i = 0; i < l->len; i++) {
|
|
582
|
-
add_sensitive(cfg,
|
|
576
|
+
add_sensitive(cfg, block, l->items[i], under, depth + 1, seen);
|
|
583
577
|
}
|
|
584
578
|
} else {
|
|
585
579
|
voxgig_map* m = voxgig_as_map(val);
|
|
586
580
|
for (size_t i = 0; i < m->len; i++) {
|
|
587
581
|
bool sub = under || sensitive_key(cfg, m->entries[i].key);
|
|
588
|
-
add_sensitive(cfg,
|
|
582
|
+
add_sensitive(cfg, block, m->entries[i].value, sub, depth + 1, seen);
|
|
589
583
|
}
|
|
590
584
|
}
|
|
591
585
|
}
|
|
592
586
|
|
|
593
587
|
// Every scalar under a sensitive name, at any depth and of any shape, is
|
|
594
|
-
// registered
|
|
595
|
-
//
|
|
596
|
-
void
|
|
597
|
-
voxgig_value* block = derived_block(options);
|
|
588
|
+
// registered in `block`: a credential mistyped as a map or a number is
|
|
589
|
+
// still a credential.
|
|
590
|
+
void clean_add_sensitive_cfg(voxgig_value* block, voxgig_value* val) {
|
|
598
591
|
if (!voxgig_is_map(block)) return;
|
|
599
592
|
CleanCfg cfg;
|
|
600
593
|
read_cfg(block, &cfg);
|
|
601
594
|
Visited seen = { NULL, 0, 0 };
|
|
602
|
-
add_sensitive(&cfg,
|
|
595
|
+
add_sensitive(&cfg, block, val, false, 0, &seen);
|
|
603
596
|
free((void*)seen.ptrs);
|
|
604
597
|
}
|
|
605
598
|
|
|
606
599
|
void clean_add_sensitive_util(Context* ctx, voxgig_value* val) {
|
|
607
600
|
if (!ctx) return;
|
|
608
|
-
|
|
601
|
+
clean_add_sensitive_cfg(ctx->cleancfg, val);
|
|
609
602
|
}
|
|
610
603
|
|
|
611
604
|
// Whether a named value is a secret: by its name, or by a registered value
|
|
@@ -216,20 +216,19 @@ voxgig_value* make_options_util(Context* ctx, PNError** err) {
|
|
|
216
216
|
voxgig_value* optspec = shared_optspec();
|
|
217
217
|
|
|
218
218
|
/* The secret registry exists BEFORE validation, fed from the raw input.
|
|
219
|
-
* Its block is shared by pointer: what is registered
|
|
220
|
-
*
|
|
219
|
+
* Its block is shared by pointer: what is registered here is what the
|
|
220
|
+
* context's `cleancfg` carries out below. */
|
|
221
221
|
voxgig_value* cleancfg = clean_make_config(voxgig_merge(
|
|
222
222
|
clist(4, v_map(), voxgig_clone(getp(optspec, "clean")),
|
|
223
223
|
mo_clean_block(cfgopts), mo_clean_block(opts)),
|
|
224
224
|
VOXGIG_MAXDEPTH));
|
|
225
|
-
|
|
226
|
-
clean_add_sensitive_opts(cleanopts, mo_without(opts, "clean", NULL));
|
|
225
|
+
clean_add_sensitive_cfg(cleancfg, mo_without(opts, "clean", NULL));
|
|
227
226
|
voxgig_value* valueblocks[2] = { cfgopts, opts };
|
|
228
227
|
for (int b = 0; b < 2; b++) {
|
|
229
228
|
voxgig_list* rawvals =
|
|
230
229
|
voxgig_as_list(clean_split_values(getpath2(valueblocks[b], "clean", "values")));
|
|
231
230
|
for (size_t i = 0; i < rawvals->len; i++) {
|
|
232
|
-
|
|
231
|
+
clean_add_cfg(cleancfg, voxgig_as_string(rawvals->items[i]));
|
|
233
232
|
}
|
|
234
233
|
}
|
|
235
234
|
|
|
@@ -304,11 +303,13 @@ voxgig_value* make_options_util(Context* ctx, PNError** err) {
|
|
|
304
303
|
}
|
|
305
304
|
}
|
|
306
305
|
|
|
307
|
-
setp(opts, "__derived__",
|
|
308
|
-
|
|
306
|
+
setp(opts, "__derived__", cmap(1, "featureorder", feature_order));
|
|
307
|
+
|
|
308
|
+
// Beside the options, not in them: options_map hands them to callers.
|
|
309
|
+
ctx->cleancfg = v_share(cleancfg);
|
|
309
310
|
|
|
310
311
|
// Again over the merged result: the config's own defaults can carry one.
|
|
311
|
-
|
|
312
|
+
clean_add_sensitive_cfg(cleancfg, mo_without(opts, "clean", "__derived__"));
|
|
312
313
|
|
|
313
314
|
return opts;
|
|
314
315
|
}
|
|
@@ -252,15 +252,10 @@
|
|
|
252
252
|
base0 (let [b (vs/getprop options "base")] (if (string? b) b ""))
|
|
253
253
|
base (str/replace base0 #"/+$" "")
|
|
254
254
|
url (str base "/" (str/replace (:path x) #"^/+" ""))
|
|
255
|
-
|
|
256
|
-
;;
|
|
257
|
-
;;
|
|
258
|
-
|
|
259
|
-
;; purchase through the test mock, which knows nothing about it.
|
|
260
|
-
;; `system.fetch` is honoured because that is the seam a caller
|
|
261
|
-
;; uses to supply a transport at all; otherwise core's own raw
|
|
262
|
-
;; HTTP path, which returns the same [res err] shape.
|
|
263
|
-
fetch (if (vs/isfunc sysfetch) sysfetch core/default-http-fetch)
|
|
255
|
+
;; The SDK's own transport, beneath every feature's wrapper: it
|
|
256
|
+
;; holds the test feature's block and the GET-only guard, and the
|
|
257
|
+
;; wrapped one would recurse on the first expiry.
|
|
258
|
+
fetch (fn [at fd] (core/u-fetcher (st fa :rootctx) at fd))
|
|
264
259
|
;; The body is MARSHALLED, never concatenated: a refresh token (or
|
|
265
260
|
;; a configured request-field name) carrying a quote, backslash or
|
|
266
261
|
;; newline must arrive as that literal value, not as broken JSON.
|
|
@@ -269,7 +264,9 @@
|
|
|
269
264
|
fetchdef (vs/jm "method" (:method x)
|
|
270
265
|
"headers" (vs/jm "content-type" "application/json")
|
|
271
266
|
"body" body
|
|
272
|
-
"redirect" "manual"
|
|
267
|
+
"redirect" "manual"
|
|
268
|
+
;; Its own bound, in milliseconds: the timeout feature's wrapper is above it.
|
|
269
|
+
"timeout" 30000)
|
|
273
270
|
;; By option alone, and only while the exchange stays on its own origin.
|
|
274
271
|
[res err] (loop [at url
|
|
275
272
|
answer (fetch url fetchdef)
|
|
@@ -281,6 +278,8 @@
|
|
|
281
278
|
(recur next (fetch next fetchdef) (inc hops))
|
|
282
279
|
answer)))]
|
|
283
280
|
|
|
281
|
+
(when (core/sdk-error? err)
|
|
282
|
+
(core/sdk-throw err))
|
|
284
283
|
(when (some? err)
|
|
285
284
|
(throw (sekreto/sekretoerror
|
|
286
285
|
(str "secrets: token exchange failed: " (core/err-msg err) " from " url))))
|
|
@@ -480,8 +479,11 @@
|
|
|
480
479
|
;; provider ERROR refuses the request with the provider's own message,
|
|
481
480
|
;; and never an unauthenticated send.
|
|
482
481
|
(let [failed (resolve! fa)]
|
|
483
|
-
(
|
|
482
|
+
(cond
|
|
483
|
+
(core/sdk-error? (core/ex->sdk failed)) [nil (core/ex->sdk failed)]
|
|
484
|
+
(some? failed)
|
|
484
485
|
[nil (core/ctx-error ctx ERROR-CODE (str "secrets: " (core/err-msg failed)))]
|
|
486
|
+
:else
|
|
485
487
|
(do
|
|
486
488
|
(let [token (credential fa)]
|
|
487
489
|
(when (seq token) (reauth! fa fetchdef token)))
|
|
@@ -513,6 +515,7 @@
|
|
|
513
515
|
(let [options (if (vs/ismap options) options (vs/jm))]
|
|
514
516
|
(swap! fa assoc
|
|
515
517
|
:client (core/oget ctx :client)
|
|
518
|
+
:rootctx ctx
|
|
516
519
|
:options options
|
|
517
520
|
:liveopts (core/oget ctx :options)
|
|
518
521
|
:active (= true (vs/getprop options "active")))
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
(defmethod print-method ::options [a ^java.io.Writer w]
|
|
23
23
|
(let [opts (deref a)]
|
|
24
24
|
(.write w (str "#sdk/options "
|
|
25
|
-
(vs/jsonify (core/u-clean (atom {
|
|
25
|
+
(vs/jsonify (core/u-clean (or (:ctx (meta a)) (atom {})) opts) (vs/jm "indent" 0))))))
|
|
26
26
|
|
|
27
27
|
(defn make-sdk [options]
|
|
28
28
|
(let [options (or options (vs/jm))
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
(vs/jm "client" client "utility" utility "config" cfg "options" options "shared" (vs/jm)) nil)
|
|
38
38
|
validated ((core/uget rootctx :make-options) rootctx)]
|
|
39
39
|
(reset! (:root-ctx client) rootctx)
|
|
40
|
+
;; The options print cleans against the registry the root context holds.
|
|
41
|
+
(alter-meta! (:options client) assoc :ctx rootctx)
|
|
40
42
|
(reset! (:options client) validated)
|
|
41
43
|
(when (= true (vs/getpath validated "feature.test.active"))
|
|
42
44
|
(reset! (:mode client) "test"))
|
|
@@ -354,6 +354,8 @@
|
|
|
354
354
|
config (let [c (cprop "config")] (if (vs/ismap c) c (bget :config)))
|
|
355
355
|
entopts (let [e (cprop "entopts")] (if (vs/ismap e) e (bget :entopts)))
|
|
356
356
|
options (let [o (cprop "options")] (if (vs/ismap o) o (bget :options)))
|
|
357
|
+
;; The clean registry, beside the options rather than in them.
|
|
358
|
+
cleancfg (or (cprop "cleancfg") (bget :cleancfg))
|
|
357
359
|
entity (or (cprop "entity") (bget :entity))
|
|
358
360
|
shared (let [s (cprop "shared")] (if (vs/ismap s) s (bget :shared)))
|
|
359
361
|
opmap (or (cprop "opmap") (bget :opmap) (atom {}))
|
|
@@ -369,7 +371,8 @@
|
|
|
369
371
|
ctx (atom {:id (str "C" (+ 10000000 (rand-int 89999999)))
|
|
370
372
|
:out (atom (vs/jm))
|
|
371
373
|
:client client :utility utility :ctrl ctrl :meta meta
|
|
372
|
-
:config config :entopts entopts :options options :
|
|
374
|
+
:config config :entopts entopts :options options :cleancfg cleancfg
|
|
375
|
+
:entity entity
|
|
373
376
|
:shared shared :opmap opmap
|
|
374
377
|
:data (dmap "data") :reqdata (dmap "reqdata")
|
|
375
378
|
:match (dmap "match") :reqmatch (dmap "reqmatch")
|
|
@@ -491,8 +494,8 @@
|
|
|
491
494
|
(let [n (try (long (Math/floor (Double/parseDouble (str v)))) (catch Exception _ nil))]
|
|
492
495
|
(if (and n (<= 0 n)) n dflt)))
|
|
493
496
|
|
|
494
|
-
;; The
|
|
495
|
-
;;
|
|
497
|
+
;; The clean registry: a java.util.Map, held on the context as :cleancfg,
|
|
498
|
+
;; whose `values` list can be replaced after make-options - features
|
|
496
499
|
;; register what they resolve later. Concurrent, so a clean or a request
|
|
497
500
|
;; copying the options reads it without the lock and sees the last put.
|
|
498
501
|
(defn make-clean-config [cleanopts]
|
|
@@ -507,12 +510,11 @@
|
|
|
507
510
|
(.put "hint" (count-opt (o "hint") 0))
|
|
508
511
|
(.put "min" (max 1 (count-opt (o "min") 4))))))
|
|
509
512
|
|
|
510
|
-
;; A context without
|
|
511
|
-
;; the schema defaults.
|
|
513
|
+
;; A context without a registry (make-error accepts a bare one) still masks
|
|
514
|
+
;; by the schema defaults.
|
|
512
515
|
(defn- clean-config [ctx]
|
|
513
|
-
(let [
|
|
514
|
-
|
|
515
|
-
(if (vs/ismap derived) derived (make-clean-config (vs/getprop @optspec-parsed "clean")))))
|
|
516
|
+
(let [cfg (when (instance? clojure.lang.IDeref ctx) (oget ctx :cleancfg))]
|
|
517
|
+
(if (vs/ismap cfg) cfg (make-clean-config (vs/getprop @optspec-parsed "clean")))))
|
|
516
518
|
|
|
517
519
|
;; The encoded forms a value travels in.
|
|
518
520
|
(defn- clean-forms [^String value]
|
|
@@ -1875,7 +1877,7 @@
|
|
|
1875
1877
|
(when (vs/ismap src)
|
|
1876
1878
|
(doseq [k (vs/keysof src)] (.put ^java.util.Map out k (vs/getprop src k)))))
|
|
1877
1879
|
out))
|
|
1878
|
-
cleanctx (atom {:
|
|
1880
|
+
cleanctx (atom {:cleancfg cleancfg})
|
|
1879
1881
|
_ (clean-add-options cleanctx (omit-keys opts0 ["clean"]))
|
|
1880
1882
|
_ (doseq [raw (concat (splitvalues (vs/getpath cfgopts "clean.values"))
|
|
1881
1883
|
(splitvalues (vs/getpath opts0 "clean.values")))]
|
|
@@ -1938,10 +1940,12 @@
|
|
|
1938
1940
|
(when (some #(= % "test") names) (.add ^java.util.List order "test"))
|
|
1939
1941
|
(doseq [n names] (when (not= n "test") (.add ^java.util.List order n)))
|
|
1940
1942
|
order))
|
|
1941
|
-
derived (vs/jm "
|
|
1943
|
+
derived (vs/jm "featureorder" feature-order)]
|
|
1942
1944
|
(.put ^java.util.Map opts "__derived__" derived)
|
|
1945
|
+
;; Beside the options, not in them: options-map hands them to callers.
|
|
1946
|
+
(oset! ctx :cleancfg cleancfg)
|
|
1943
1947
|
;; Again over the merged result: the config's own defaults can carry one.
|
|
1944
|
-
(clean-add-options
|
|
1948
|
+
(clean-add-options cleanctx (omit-keys opts ["clean" "__derived__"]))
|
|
1945
1949
|
opts))))
|
|
1946
1950
|
|
|
1947
1951
|
;; ---------------------------------------------------------------------------
|
|
@@ -2013,6 +2017,10 @@
|
|
|
2013
2017
|
(let [builder (HttpRequest/newBuilder (URI/create fullurl))
|
|
2014
2018
|
has-ua (atom false)]
|
|
2015
2019
|
(.method builder (str/upper-case method-str) (body-publisher fetchdef))
|
|
2020
|
+
;; A bound in milliseconds, for a caller beneath the timeout feature.
|
|
2021
|
+
(let [bound (vs/getprop fetchdef "timeout")]
|
|
2022
|
+
(when (and (number? bound) (pos? bound))
|
|
2023
|
+
(.timeout builder (java.time.Duration/ofMillis (long bound)))))
|
|
2016
2024
|
(doseq [item (or (vs/items headers) [])]
|
|
2017
2025
|
(let [k (vs/getprop item 0) v (vs/getprop item 1)]
|
|
2018
2026
|
(when (string? v)
|