@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
|
@@ -169,12 +169,31 @@ class FeatureCorpusTest extends TestCase
|
|
|
169
169
|
return $out;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
private static function invoke($client, array $op, array $ctrl)
|
|
172
|
+
private static function invoke($client, array $op, array $ctrl, array $args = [])
|
|
173
173
|
{
|
|
174
174
|
$acc = $op['accessor'];
|
|
175
175
|
$ent = $client->$acc();
|
|
176
176
|
$fn = $op['op'];
|
|
177
|
-
return $ent->$fn(
|
|
177
|
+
return $ent->$fn($args, $ctrl);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private const ITEM_ARGS = ['id' => 'corpus-item'];
|
|
181
|
+
|
|
182
|
+
/** A write of one entity (#ITEM) that completes when driven with ITEM_ARGS. */
|
|
183
|
+
private static function usableItem(string $accessor): ?array
|
|
184
|
+
{
|
|
185
|
+
foreach (self::candidates(self::buildClient([])) as $cand) {
|
|
186
|
+
if ($cand['accessor'] !== $accessor || !in_array($cand['op'], ['update', 'patch', 'remove'], true)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
self::invoke(self::buildClient([]), $cand, [], self::ITEM_ARGS);
|
|
191
|
+
} catch (\Throwable $e) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
return $cand;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
178
197
|
}
|
|
179
198
|
|
|
180
199
|
/**
|
|
@@ -200,6 +219,51 @@ class FeatureCorpusTest extends TestCase
|
|
|
200
219
|
return $picked;
|
|
201
220
|
}
|
|
202
221
|
|
|
222
|
+
private const READ_OPS = ['list', 'load'];
|
|
223
|
+
private const WRITE_OPS = ['create', 'update', 'patch', 'remove'];
|
|
224
|
+
|
|
225
|
+
/** A read and a write of one entity (#READ, #WRITE), each driven as usableOps drives an op. */
|
|
226
|
+
private static function usablePair(): ?array
|
|
227
|
+
{
|
|
228
|
+
$found = [];
|
|
229
|
+
foreach (self::candidates(self::buildClient([])) as $cand) {
|
|
230
|
+
$role = in_array($cand['op'], self::READ_OPS, true) ? 'read'
|
|
231
|
+
: (in_array($cand['op'], self::WRITE_OPS, true) ? 'write' : null);
|
|
232
|
+
if (null === $role || isset($found[$cand['accessor']][$role])) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
self::invoke(self::buildClient([]), $cand, []);
|
|
237
|
+
} catch (\Throwable $e) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
$found[$cand['accessor']][$role] = $cand;
|
|
241
|
+
if (isset($found[$cand['accessor']]['read'], $found[$cand['accessor']]['write'])) {
|
|
242
|
+
return $found[$cand['accessor']];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** One step: it may wait, may add request headers, and may pass `args` as the first argument. */
|
|
249
|
+
private static function step($client, array $op, array $step, array $ctrl)
|
|
250
|
+
{
|
|
251
|
+
if (isset($step['wait'])) {
|
|
252
|
+
usleep((int)($step['wait'] * 1000));
|
|
253
|
+
}
|
|
254
|
+
$args = is_array($step['args'] ?? null) ? $step['args'] : [];
|
|
255
|
+
if (!isset($step['headers'])) {
|
|
256
|
+
return self::invoke($client, $op, $ctrl, $args);
|
|
257
|
+
}
|
|
258
|
+
$prior = $client->options;
|
|
259
|
+
$client->options['headers'] = array_merge($prior['headers'] ?? [], $step['headers']);
|
|
260
|
+
try {
|
|
261
|
+
return self::invoke($client, $op, $ctrl, $args);
|
|
262
|
+
} finally {
|
|
263
|
+
$client->options = $prior;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
203
267
|
/** Replace #OPn throughout a case, keys included. */
|
|
204
268
|
private static function resolve($node, array $tokens)
|
|
205
269
|
{
|
|
@@ -387,6 +451,21 @@ class FeatureCorpusTest extends TestCase
|
|
|
387
451
|
foreach ($ops as $o) {
|
|
388
452
|
$byKey[$o['key']] = $o;
|
|
389
453
|
}
|
|
454
|
+
$pair = self::usablePair();
|
|
455
|
+
foreach ($pair ?? [] as $o) {
|
|
456
|
+
$byKey[$o['key']] = $o;
|
|
457
|
+
}
|
|
458
|
+
$item = null === $pair ? null : self::usableItem($pair['read']['accessor']);
|
|
459
|
+
if (null !== $item) {
|
|
460
|
+
$byKey[$item['key']] = $item;
|
|
461
|
+
}
|
|
462
|
+
$other = null;
|
|
463
|
+
foreach (null === $pair ? [] : $ops as $o) {
|
|
464
|
+
if ($o['accessor'] !== $pair['read']['accessor']) {
|
|
465
|
+
$other = $o;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
390
469
|
|
|
391
470
|
$ran = 0;
|
|
392
471
|
foreach ($cases as $raw) {
|
|
@@ -397,6 +476,27 @@ class FeatureCorpusTest extends TestCase
|
|
|
397
476
|
continue;
|
|
398
477
|
}
|
|
399
478
|
|
|
479
|
+
$paired = 1 === preg_match('/#(READ|WRITE|ITEM|OTHER)\b/', json_encode($raw));
|
|
480
|
+
if ($paired && null === $pair) {
|
|
481
|
+
fwrite(STDERR, sprintf(
|
|
482
|
+
"skip \"%s\": needs a read and a write of one entity, this SDK offers none\n",
|
|
483
|
+
$raw['name'] ?? ''));
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
$lacking = null;
|
|
488
|
+
foreach (['#ITEM' => $item, '#OTHER' => $other] as $tok => $found) {
|
|
489
|
+
if ($paired && null === $found && 1 === preg_match('/' . $tok . '\b/', json_encode($raw))) {
|
|
490
|
+
$lacking = $tok;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (null !== $lacking) {
|
|
495
|
+
fwrite(STDERR, sprintf("skip \"%s\": needs %s, which this SDK cannot drive\n",
|
|
496
|
+
$raw['name'] ?? '', $lacking));
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
|
|
400
500
|
$missing = self::missingFeature($raw, $have);
|
|
401
501
|
if (null !== $missing) {
|
|
402
502
|
fwrite(STDERR, sprintf(
|
|
@@ -409,6 +509,16 @@ class FeatureCorpusTest extends TestCase
|
|
|
409
509
|
for ($i = 0; $i < $need; $i++) {
|
|
410
510
|
$tokens['#OP' . ($i + 1)] = $ops[$i]['key'];
|
|
411
511
|
}
|
|
512
|
+
if ($paired) {
|
|
513
|
+
$tokens['#READ'] = $pair['read']['key'];
|
|
514
|
+
$tokens['#WRITE'] = $pair['write']['key'];
|
|
515
|
+
if (null !== $item) {
|
|
516
|
+
$tokens['#ITEM'] = $item['key'];
|
|
517
|
+
}
|
|
518
|
+
if (null !== $other) {
|
|
519
|
+
$tokens['#OTHER'] = $other['key'];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
412
522
|
$kase = self::resolve($raw, $tokens);
|
|
413
523
|
$label = (string)($kase['name'] ?? '');
|
|
414
524
|
$ran++;
|
|
@@ -424,7 +534,7 @@ class FeatureCorpusTest extends TestCase
|
|
|
424
534
|
$wanterr = $step['err'] ?? null;
|
|
425
535
|
|
|
426
536
|
try {
|
|
427
|
-
self::
|
|
537
|
+
self::step($client, $op, $step, $ctrl);
|
|
428
538
|
$this->assertNull($wanterr,
|
|
429
539
|
"$label: {$step['op']} was expected to fail, and did not");
|
|
430
540
|
} catch (\PHPUnit\Framework\AssertionFailedError $e) {
|
|
@@ -763,6 +763,74 @@ class FeatureTest extends TestCase
|
|
|
763
763
|
$this->assertCount(3, $rec->calls);
|
|
764
764
|
}
|
|
765
765
|
|
|
766
|
+
public function test_cache_keys_on_the_request_headers(): void
|
|
767
|
+
{
|
|
768
|
+
$this->needs('cache');
|
|
769
|
+
$rec = new FtRecorder();
|
|
770
|
+
$h = new FtHarness([
|
|
771
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
772
|
+
], $rec->server());
|
|
773
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['x-tenant' => 'tenant-a']]);
|
|
774
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['X-Tenant' => 'tenant-b']]);
|
|
775
|
+
$this->assertCount(2, $rec->calls);
|
|
776
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['x-tenant' => 'tenant-b']]);
|
|
777
|
+
$this->assertCount(2, $rec->calls);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
public function test_cache_a_write_drops_its_collection(): void
|
|
781
|
+
{
|
|
782
|
+
$this->needs('cache');
|
|
783
|
+
$rec = new FtRecorder();
|
|
784
|
+
$h = new FtHarness([
|
|
785
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
786
|
+
], $rec->server());
|
|
787
|
+
$paths = ['/w/1', '/w', '/w/1/part', '/other/1', '/w/2'];
|
|
788
|
+
foreach ($paths as $p) {
|
|
789
|
+
$h->op(['op' => 'load', 'path' => $p]);
|
|
790
|
+
}
|
|
791
|
+
$h->op(['op' => 'update', 'method' => 'PUT', 'path' => '/w/1']);
|
|
792
|
+
foreach ($paths as $p) {
|
|
793
|
+
$h->op(['op' => 'load', 'path' => $p]);
|
|
794
|
+
}
|
|
795
|
+
$this->assertCount(9, $rec->calls);
|
|
796
|
+
$this->assertSame(2, $h->client->_cache['hit']);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
public function test_cache_control_prevents_storing(): void
|
|
800
|
+
{
|
|
801
|
+
$this->needs('cache');
|
|
802
|
+
foreach (['no-store', 'private', 'No-Cache', 'max-age=60, private'] as $control) {
|
|
803
|
+
$rec = new FtRecorder(function (int $_n) use ($control) {
|
|
804
|
+
return FtHarness::response(200, ['ok' => true], ['Cache-Control' => $control]);
|
|
805
|
+
});
|
|
806
|
+
$h = new FtHarness([
|
|
807
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
808
|
+
], $rec->server());
|
|
809
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
810
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
811
|
+
$this->assertCount(2, $rec->calls, $control);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
public function test_cache_max_age_caps_the_ttl(): void
|
|
816
|
+
{
|
|
817
|
+
$this->needs('cache');
|
|
818
|
+
$clock = new FtClock();
|
|
819
|
+
$rec = new FtRecorder(function (int $_n) {
|
|
820
|
+
return FtHarness::response(200, ['ok' => true], ['cache-control' => 'max-age=1']);
|
|
821
|
+
});
|
|
822
|
+
$h = new FtHarness([
|
|
823
|
+
['name' => 'cache', 'options' => ['ttl' => 10000, 'now' => $clock->now()]],
|
|
824
|
+
], $rec->server());
|
|
825
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
826
|
+
$clock->advance(500);
|
|
827
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
828
|
+
$this->assertCount(1, $rec->calls);
|
|
829
|
+
$clock->advance(600);
|
|
830
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
831
|
+
$this->assertCount(2, $rec->calls);
|
|
832
|
+
}
|
|
833
|
+
|
|
766
834
|
|
|
767
835
|
// --- idempotency ----------------------------------------------------------
|
|
768
836
|
|
|
@@ -1039,6 +1107,28 @@ class FeatureTest extends TestCase
|
|
|
1039
1107
|
}
|
|
1040
1108
|
|
|
1041
1109
|
|
|
1110
|
+
// --- one call, one id -----------------------------------------------------
|
|
1111
|
+
|
|
1112
|
+
public function test_telemetry_debug_and_audit_carry_one_calls_context_id(): void
|
|
1113
|
+
{
|
|
1114
|
+
$this->needs('telemetry', 'debug', 'audit');
|
|
1115
|
+
$h = new FtHarness([
|
|
1116
|
+
['name' => 'telemetry'], ['name' => 'debug'], ['name' => 'audit'],
|
|
1117
|
+
]);
|
|
1118
|
+
$h->op(['op' => 'load']);
|
|
1119
|
+
$h->op(['op' => 'list']);
|
|
1120
|
+
$calls = array_column($h->client->_audit['records'], 'correlationId');
|
|
1121
|
+
$this->assertCount(2, $calls);
|
|
1122
|
+
foreach ($calls as $id) {
|
|
1123
|
+
$this->assertIsString($id);
|
|
1124
|
+
$this->assertNotSame('', $id);
|
|
1125
|
+
}
|
|
1126
|
+
$this->assertNotSame($calls[0], $calls[1]);
|
|
1127
|
+
$this->assertSame($calls, array_column($h->client->_telemetry['spans'], 'correlationId'));
|
|
1128
|
+
$this->assertSame($calls, array_column($h->client->_debug['entries'], 'correlationId'));
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
|
|
1042
1132
|
// --- clienttrack ----------------------------------------------------------
|
|
1043
1133
|
|
|
1044
1134
|
public function test_clienttrack_stable_client_id_unique_request_ids_ua(): void
|
|
@@ -172,20 +172,13 @@ class ProjectNameClean
|
|
|
172
172
|
}));
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
// A context without
|
|
175
|
+
// A context without a registry (make_error is reached with a bare one)
|
|
176
176
|
// falls back to the schema defaults, so nothing leaves raw for want of a
|
|
177
177
|
// constructor.
|
|
178
178
|
private static function config_of(?ProjectNameContext $ctx): \stdClass
|
|
179
179
|
{
|
|
180
|
-
$
|
|
181
|
-
|
|
182
|
-
$derived = $ctx->options['__derived__']['clean'] ?? null;
|
|
183
|
-
}
|
|
184
|
-
if ($derived instanceof \stdClass) {
|
|
185
|
-
return $derived;
|
|
186
|
-
}
|
|
187
|
-
if (is_array($derived)) {
|
|
188
|
-
return (object)$derived;
|
|
180
|
+
if (null !== $ctx && $ctx->cleancfg instanceof \stdClass) {
|
|
181
|
+
return $ctx->cleancfg;
|
|
189
182
|
}
|
|
190
183
|
require_once __DIR__ . '/../schema.php';
|
|
191
184
|
return self::config(\Voxgig\Struct\Struct::getprop(ProjectNameSchema::optspec(), 'clean'));
|
|
@@ -166,12 +166,16 @@ class ProjectNameFetcher
|
|
|
166
166
|
$header_lines[] = 'User-Agent: ' . self::DEFAULT_USER_AGENT;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
170
|
+
$bound = $fetchdef['timeout'] ?? null;
|
|
171
|
+
$bound = is_numeric($bound) && 0 < $bound ? (int)$bound : 30000;
|
|
172
|
+
|
|
169
173
|
// Prefer cURL when available — its header capture is reliable across
|
|
170
174
|
// PHP versions, while file_get_contents + custom stream wrappers
|
|
171
175
|
// don't propagate $http_response_header for user-defined wrappers
|
|
172
176
|
// in PHP 8.3+.
|
|
173
177
|
if (function_exists('curl_init')) {
|
|
174
|
-
return self::curlFetch($fullurl, $method_str, $body_str, $header_lines);
|
|
178
|
+
return self::curlFetch($fullurl, $method_str, $body_str, $header_lines, $bound);
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
$opts = [
|
|
@@ -179,6 +183,7 @@ class ProjectNameFetcher
|
|
|
179
183
|
'method' => $method_str,
|
|
180
184
|
'ignore_errors' => true,
|
|
181
185
|
'follow_location' => 0,
|
|
186
|
+
'timeout' => $bound / 1000,
|
|
182
187
|
],
|
|
183
188
|
];
|
|
184
189
|
|
|
@@ -280,13 +285,13 @@ class ProjectNameFetcher
|
|
|
280
285
|
return [$decoded, null];
|
|
281
286
|
}
|
|
282
287
|
|
|
283
|
-
private static function curlFetch(string $fullurl, string $method, $body_str, array $header_lines): array
|
|
288
|
+
private static function curlFetch(string $fullurl, string $method, $body_str, array $header_lines, int $bound): array
|
|
284
289
|
{
|
|
285
290
|
$ch = self::curlHandle($fullurl);
|
|
286
291
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
287
292
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
288
293
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
|
289
|
-
curl_setopt($ch,
|
|
294
|
+
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $bound);
|
|
290
295
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
291
296
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
292
297
|
// '' offers every encoding this cURL decodes, and decodes it: a
|
|
@@ -60,9 +60,7 @@ class ProjectNameMakeOptions
|
|
|
60
60
|
$cfgclean = $block($cfgopts['clean'] ?? null);
|
|
61
61
|
$specclean = $block(\Voxgig\Struct\Struct::getprop($optspec, 'clean'));
|
|
62
62
|
$cleancfg = ProjectNameClean::config(array_merge($specclean, $cfgclean, $rawclean));
|
|
63
|
-
$cleanctx = new ProjectNameContext([
|
|
64
|
-
'options' => ['__derived__' => ['clean' => $cleancfg]],
|
|
65
|
-
], null);
|
|
63
|
+
$cleanctx = new ProjectNameContext(['cleancfg' => $cleancfg], null);
|
|
66
64
|
$rawopts = is_object($options) ? get_object_vars($options)
|
|
67
65
|
: (is_array($options) ? $options : []);
|
|
68
66
|
unset($rawopts['clean']);
|
|
@@ -314,10 +312,10 @@ class ProjectNameMakeOptions
|
|
|
314
312
|
unset($merged['clean']);
|
|
315
313
|
ProjectNameClean::add_options($cleanctx, $merged);
|
|
316
314
|
|
|
317
|
-
$opts['__derived__'] = [
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
315
|
+
$opts['__derived__'] = ['featureorder' => $featureorder];
|
|
316
|
+
|
|
317
|
+
// Beside the options, not in them: options_map hands them to callers.
|
|
318
|
+
$ctx->cleancfg = $cleancfg;
|
|
321
319
|
|
|
322
320
|
return $opts;
|
|
323
321
|
}
|
|
@@ -95,6 +95,10 @@ class ProjectNameContext:
|
|
|
95
95
|
else:
|
|
96
96
|
self.options = None
|
|
97
97
|
|
|
98
|
+
# The clean registry, beside the options rather than in them.
|
|
99
|
+
cc = get_ctx_prop(ctxmap, "cleancfg")
|
|
100
|
+
self.cleancfg = cc if cc is not None else getattr(basectx, "cleancfg", None)
|
|
101
|
+
|
|
98
102
|
# Entity
|
|
99
103
|
e = get_ctx_prop(ctxmap, "entity")
|
|
100
104
|
if e is not None:
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# ProjectName SDK cache feature
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import re
|
|
7
|
+
import secrets
|
|
4
8
|
import time
|
|
5
9
|
|
|
6
10
|
from projectname_sdk.feature.base_feature import ProjectNameBaseFeature
|
|
7
11
|
from projectname_sdk.utility.media import header_value, is_json_media
|
|
8
12
|
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# capture so both the current caller and later hits can read the JSON body
|
|
18
|
-
# repeatedly.
|
|
14
|
+
SAFE_METHODS = ("GET", "HEAD")
|
|
15
|
+
UNSTORED = ("no-store", "private", "no-cache")
|
|
16
|
+
MAX_AGE = re.compile(r'^max-age\s*=\s*"?(\d+)"?$')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Response caching for safe (read) requests, per client: see the features
|
|
20
|
+
# reference for the key, the write invalidation and the Cache-Control rules.
|
|
19
21
|
class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
20
22
|
def __init__(self):
|
|
21
23
|
super().__init__()
|
|
@@ -25,6 +27,7 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
|
25
27
|
self.client = None
|
|
26
28
|
self.options = {}
|
|
27
29
|
self.store = {}
|
|
30
|
+
self.secret = b""
|
|
28
31
|
|
|
29
32
|
def init(self, ctx, options):
|
|
30
33
|
self.client = ctx.client
|
|
@@ -39,6 +42,7 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
|
39
42
|
return
|
|
40
43
|
|
|
41
44
|
self.store = {}
|
|
45
|
+
self.secret = secrets.token_bytes(32)
|
|
42
46
|
|
|
43
47
|
utility = ctx.utility
|
|
44
48
|
inner = utility.fetcher
|
|
@@ -55,9 +59,15 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
|
55
59
|
methods = self.options.get("methods") or ["GET"]
|
|
56
60
|
|
|
57
61
|
if method not in methods:
|
|
58
|
-
|
|
62
|
+
if method in SAFE_METHODS:
|
|
63
|
+
return inner(ctx, url, fetchdef)
|
|
64
|
+
try:
|
|
65
|
+
return inner(ctx, url, fetchdef)
|
|
66
|
+
finally:
|
|
67
|
+
self._invalidate(url)
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
headers = fetchdef.get("headers") if isinstance(fetchdef, dict) else None
|
|
70
|
+
key = method + " " + url + " " + self._digest(headers)
|
|
61
71
|
now = self._now()
|
|
62
72
|
hit = self.store.get(key)
|
|
63
73
|
|
|
@@ -69,15 +79,36 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
|
69
79
|
|
|
70
80
|
if err is None and self._cacheable(res):
|
|
71
81
|
snapshot = self._snapshot(res)
|
|
72
|
-
ttl =
|
|
82
|
+
ttl = cache_lifetime(snapshot["headers"],
|
|
83
|
+
5000 if self.options.get("ttl") is None else self.options.get("ttl"))
|
|
84
|
+
if ttl <= 0:
|
|
85
|
+
self._track("bypass")
|
|
86
|
+
return self._replay(snapshot), None
|
|
87
|
+
self.store.pop(key, None)
|
|
73
88
|
self._evict()
|
|
74
|
-
self.store[key] = {"expiry": now + ttl, "snapshot": snapshot}
|
|
89
|
+
self.store[key] = {"expiry": now + ttl, "scope": url_scope(url), "snapshot": snapshot}
|
|
75
90
|
self._track("miss")
|
|
76
91
|
return self._replay(snapshot), None
|
|
77
92
|
|
|
78
93
|
self._track("bypass")
|
|
79
94
|
return res, err
|
|
80
95
|
|
|
96
|
+
def _digest(self, headers):
|
|
97
|
+
pairs = []
|
|
98
|
+
if isinstance(headers, dict):
|
|
99
|
+
for name, val in headers.items():
|
|
100
|
+
if val is not None:
|
|
101
|
+
pairs.append((str(name).lower(), val if isinstance(val, str) else str(val)))
|
|
102
|
+
text = "".join(name + ":" + val + "\n" for name, val in sorted(pairs))
|
|
103
|
+
return hmac.new(self.secret, text.encode("utf-8"), hashlib.sha256).hexdigest()
|
|
104
|
+
|
|
105
|
+
def _invalidate(self, url):
|
|
106
|
+
path = url_scope(url)
|
|
107
|
+
collection = url_parent(path)
|
|
108
|
+
for key in [k for k, e in self.store.items()
|
|
109
|
+
if scope_under(e["scope"], path) or e["scope"] == collection]:
|
|
110
|
+
del self.store[key]
|
|
111
|
+
|
|
81
112
|
# A body the transport could not read as JSON passes through, for the operation to report.
|
|
82
113
|
def _cacheable(self, res):
|
|
83
114
|
if not isinstance(res, dict) or res.get("unreadable") is True:
|
|
@@ -143,3 +174,38 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
|
|
|
143
174
|
track = {"hit": 0, "miss": 0, "bypass": 0}
|
|
144
175
|
client._cache = track
|
|
145
176
|
track[kind] += 1
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
# The configured ttl capped by the response's Cache-Control; zero when the
|
|
180
|
+
# response may not be stored.
|
|
181
|
+
def cache_lifetime(headers, ttl):
|
|
182
|
+
control = ""
|
|
183
|
+
for name, val in (headers or {}).items():
|
|
184
|
+
if str(name).lower() == "cache-control":
|
|
185
|
+
control = str(val)
|
|
186
|
+
life = ttl
|
|
187
|
+
for part in control.lower().split(","):
|
|
188
|
+
directive = part.strip()
|
|
189
|
+
if directive in UNSTORED:
|
|
190
|
+
return 0
|
|
191
|
+
age = MAX_AGE.match(directive)
|
|
192
|
+
if age is not None:
|
|
193
|
+
life = min(life, int(age.group(1)) * 1000)
|
|
194
|
+
return life
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def url_scope(url):
|
|
198
|
+
return re.split(r"[?#]", str(url), maxsplit=1)[0].rstrip("/")
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def url_parent(scope):
|
|
202
|
+
scheme = scope.find("://")
|
|
203
|
+
root = 0 if scheme < 0 else scope.find("/", scheme + 3)
|
|
204
|
+
if root < 0:
|
|
205
|
+
return scope
|
|
206
|
+
cut = scope.rfind("/")
|
|
207
|
+
return scope[:max(cut, root)]
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def scope_under(scope, prefix):
|
|
211
|
+
return scope == prefix or scope.startswith(prefix + "/")
|
|
@@ -46,6 +46,7 @@ class ProjectNameDebugFeature(ProjectNameBaseFeature):
|
|
|
46
46
|
|
|
47
47
|
entry = {
|
|
48
48
|
"op": opname,
|
|
49
|
+
"correlationId": ctx.id,
|
|
49
50
|
"method": spec.method if spec is not None else None,
|
|
50
51
|
"url": (spec.url or spec.path) if spec is not None else None,
|
|
51
52
|
"headers": self._redact(ctx, spec.headers if spec is not None else None),
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
import base64
|
|
5
5
|
import json
|
|
6
|
-
import urllib.error
|
|
7
6
|
import urllib.parse
|
|
8
|
-
import urllib.request
|
|
9
7
|
|
|
10
8
|
from projectname_sdk.utility.voxgig_struct import voxgig_struct as vs
|
|
11
9
|
from projectname_sdk.feature.base_feature import ProjectNameBaseFeature
|
|
12
10
|
from projectname_sdk.feature.secrets.voxgig_sekreto import Sekreto, envkey
|
|
11
|
+
from projectname_sdk.utility.fetcher import fetcher_util
|
|
12
|
+
from projectname_sdk.core.error import ProjectNameError
|
|
13
13
|
# The plugin DEFINITIONS the model selected for this feature, emitted by
|
|
14
14
|
# config generically from the catalogue's active `plugin.def` entries.
|
|
15
15
|
# Upstream sekreto's contract since the registry was retired: a kind not
|
|
@@ -335,21 +335,14 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
|
|
|
335
335
|
base = str(options.get("base") or "").rstrip("/")
|
|
336
336
|
url = base + "/" + str(x["path"]).lstrip("/")
|
|
337
337
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
# NOT-the-SDK-transport note below.
|
|
347
|
-
fetch = _raw_exchange_fetch
|
|
348
|
-
|
|
349
|
-
# Deliberately NOT the SDK transport. The transport is what this
|
|
350
|
-
# feature wraps, and sending the token request back through it
|
|
351
|
-
# would recurse on the first 401 - and would route the exchange
|
|
352
|
-
# through the test mock, which knows nothing about it.
|
|
338
|
+
# The SDK's own transport, beneath every feature's wrapper: it holds
|
|
339
|
+
# the test feature's block and the GET-only guard, and the wrapped
|
|
340
|
+
# one would recurse on the first 401.
|
|
341
|
+
rootctx = getattr(self._client, "_rootctx", None)
|
|
342
|
+
|
|
343
|
+
def fetch(at, fd):
|
|
344
|
+
return fetcher_util(rootctx, at, fd)
|
|
345
|
+
|
|
353
346
|
fetchdef = {
|
|
354
347
|
"method": x["method"],
|
|
355
348
|
"headers": {"content-type": "application/json"},
|
|
@@ -357,6 +350,9 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
|
|
|
357
350
|
# Never followed by the client: a redirect would carry the
|
|
358
351
|
# refresh token on.
|
|
359
352
|
"redirect": "manual",
|
|
353
|
+
# Seconds; its own bound, as the timeout feature's wrapper is
|
|
354
|
+
# above this call.
|
|
355
|
+
"timeout": 30,
|
|
360
356
|
}
|
|
361
357
|
|
|
362
358
|
res, err = fetch(url, fetchdef)
|
|
@@ -373,6 +369,8 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
|
|
|
373
369
|
res, err = fetch(at, fetchdef)
|
|
374
370
|
hops += 1
|
|
375
371
|
|
|
372
|
+
if isinstance(err, ProjectNameError):
|
|
373
|
+
raise err
|
|
376
374
|
if err is not None:
|
|
377
375
|
raise Exception(
|
|
378
376
|
"secrets: token exchange failed: " + str(err) + " from " + url)
|
|
@@ -527,52 +525,3 @@ def _moved(url, at, res):
|
|
|
527
525
|
except ValueError:
|
|
528
526
|
return None
|
|
529
527
|
return nxt if same else None
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
533
|
-
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
534
|
-
return None
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
# A 3xx then surfaces as HTTPError, the exchange's own failed answer.
|
|
538
|
-
_NO_REDIRECT = urllib.request.build_opener(_NoRedirect)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
def _raw_exchange_fetch(fullurl, fetchdef):
|
|
542
|
-
"""Token-exchange transport of last resort: stdlib urllib, answering
|
|
543
|
-
the same (res, err) shape the system.fetch seam promises. Exists so an
|
|
544
|
-
exchange works with ordinary SDK options - requiring a custom
|
|
545
|
-
transport for the COMMON case would reject every live token purchase
|
|
546
|
-
before a request was made."""
|
|
547
|
-
try:
|
|
548
|
-
body = fetchdef.get("body")
|
|
549
|
-
data = body.encode("utf-8") if isinstance(body, str) and body else None
|
|
550
|
-
req = urllib.request.Request(
|
|
551
|
-
fullurl,
|
|
552
|
-
data=data,
|
|
553
|
-
method=str(fetchdef.get("method") or "POST"),
|
|
554
|
-
)
|
|
555
|
-
for k, v in (fetchdef.get("headers") or {}).items():
|
|
556
|
-
if isinstance(v, str):
|
|
557
|
-
req.add_header(k, v)
|
|
558
|
-
with _NO_REDIRECT.open(req, timeout=30) as res:
|
|
559
|
-
raw = res.read()
|
|
560
|
-
status = res.status
|
|
561
|
-
headers = {k.lower(): v for k, v in res.headers.items()}
|
|
562
|
-
|
|
563
|
-
def _json():
|
|
564
|
-
try:
|
|
565
|
-
return json.loads(raw.decode("utf-8"))
|
|
566
|
-
except Exception:
|
|
567
|
-
return None
|
|
568
|
-
|
|
569
|
-
return {"status": status, "headers": headers, "json": _json}, None
|
|
570
|
-
except urllib.error.HTTPError as e:
|
|
571
|
-
# A non-2xx answer IS a response: hand back its status so the
|
|
572
|
-
# caller reports "token exchange failed: <status>" rather than a
|
|
573
|
-
# transport error.
|
|
574
|
-
headers = {k.lower(): v for k, v in (e.headers or {}).items()}
|
|
575
|
-
return {"status": e.code, "headers": headers,
|
|
576
|
-
"json": lambda: None}, None
|
|
577
|
-
except Exception as e:
|
|
578
|
-
return None, e
|
|
@@ -68,17 +68,11 @@ def _prop(obj, name):
|
|
|
68
68
|
return getattr(obj, name, None)
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
# The derived block make_options builds; a context without options
|
|
76
|
-
# (make_error is reached with a bare one) falls back to the schema defaults,
|
|
77
|
-
# so nothing leaves raw for want of a constructor.
|
|
71
|
+
# The registry make_options builds; a context without one (make_error is
|
|
72
|
+
# reached with a bare one) falls back to the schema defaults, so nothing
|
|
73
|
+
# leaves raw for want of a constructor.
|
|
78
74
|
def _clean_config(ctx):
|
|
79
|
-
|
|
80
|
-
derived = options.get("__derived__") if isinstance(options, dict) else None
|
|
81
|
-
cfg = derived.get("clean") if isinstance(derived, dict) else None
|
|
75
|
+
cfg = _prop(ctx, "cleancfg")
|
|
82
76
|
if isinstance(cfg, dict) and isinstance(cfg.get("values"), list):
|
|
83
77
|
return cfg
|
|
84
78
|
return make_clean_config(OPTSPEC.get("clean"))
|