@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
|
@@ -7,11 +7,11 @@ from projectname_sdk.utility.clean import (
|
|
|
7
7
|
clean_util, clean_add_util, clean_add_sensitive, make_clean_config, split_values)
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
# A context carrying only the
|
|
11
|
-
#
|
|
10
|
+
# A context carrying only the clean registry, which exists before the real
|
|
11
|
+
# options do.
|
|
12
12
|
class _CleanCtx:
|
|
13
13
|
def __init__(self, cleancfg):
|
|
14
|
-
self.
|
|
14
|
+
self.cleancfg = cleancfg
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -232,12 +232,11 @@ def make_options_util(ctx):
|
|
|
232
232
|
at = featureorder.index("test") + 1 if "test" in featureorder else 0
|
|
233
233
|
featureorder.insert(at, "station")
|
|
234
234
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
235
|
+
opts["__derived__"] = {"featureorder": featureorder}
|
|
236
|
+
|
|
237
|
+
# The registry stays MUTABLE, as features register what they resolve after
|
|
238
|
+
# construction, and sits beside the options: callers read those back.
|
|
239
|
+
ctx.cleancfg = cleancfg
|
|
241
240
|
|
|
242
241
|
# Again over the merged result: the config's own defaults can carry one.
|
|
243
242
|
_clean_add_options(cleanctx, {
|
|
@@ -33,6 +33,12 @@ import unittest
|
|
|
33
33
|
|
|
34
34
|
import pytest
|
|
35
35
|
|
|
36
|
+
try:
|
|
37
|
+
import requests # noqa: F401
|
|
38
|
+
HAVE_REQUESTS = True
|
|
39
|
+
except ImportError:
|
|
40
|
+
HAVE_REQUESTS = False
|
|
41
|
+
|
|
36
42
|
from projectname_sdk import ProjectNameSDK
|
|
37
43
|
from projectname_sdk.config import shared_config
|
|
38
44
|
from projectname_sdk.features import _has_feature
|
|
@@ -48,6 +54,10 @@ NOAUTH = "auth" not in shared_config().get("options", {})
|
|
|
48
54
|
placing = pytest.mark.skipif(
|
|
49
55
|
NOAUTH, reason="this SDK's config declares no auth, so it places no credential")
|
|
50
56
|
|
|
57
|
+
# The exchange goes through the SDK's default transport, which needs requests.
|
|
58
|
+
over_default_transport = pytest.mark.skipif(
|
|
59
|
+
not HAVE_REQUESTS, reason="the default transport needs the requests module")
|
|
60
|
+
|
|
51
61
|
|
|
52
62
|
def cred_header():
|
|
53
63
|
"""The header the credential travels in: the DEFAULT client's
|
|
@@ -449,8 +459,9 @@ if __name__ == "__main__":
|
|
|
449
459
|
|
|
450
460
|
# ---------------------------------------------------------------------
|
|
451
461
|
# Review-hardening pins (vendor-tag rollout, PR review): the exchange
|
|
452
|
-
# works with ORDINARY options (no custom transport
|
|
453
|
-
# carries the purchase), and an uncached miss retracts the
|
|
462
|
+
# works with ORDINARY options (no custom transport: the SDK's own default
|
|
463
|
+
# transport carries the purchase), and an uncached miss retracts the
|
|
464
|
+
# credential.
|
|
454
465
|
|
|
455
466
|
class _TokenEndpoint(http.server.BaseHTTPRequestHandler):
|
|
456
467
|
refresh_seen = None
|
|
@@ -476,10 +487,11 @@ class _TokenEndpoint(http.server.BaseHTTPRequestHandler):
|
|
|
476
487
|
@placing
|
|
477
488
|
class TestSecretsReviewPins(unittest.TestCase):
|
|
478
489
|
|
|
479
|
-
|
|
490
|
+
@over_default_transport
|
|
491
|
+
def test_exchange_uses_the_default_transport_and_marshals_the_body(self):
|
|
480
492
|
# A refresh token full of JSON-hostile characters must arrive at
|
|
481
|
-
# the endpoint as its literal value, through the
|
|
482
|
-
#
|
|
493
|
+
# the endpoint as its literal value, through the SDK's default
|
|
494
|
+
# transport - ordinary options carry no system.fetch for it.
|
|
483
495
|
tricky = 're"fresh\\to\nken'
|
|
484
496
|
_TokenEndpoint.refresh_seen = None
|
|
485
497
|
|
|
@@ -489,9 +501,9 @@ class TestSecretsReviewPins(unittest.TestCase):
|
|
|
489
501
|
try:
|
|
490
502
|
# NO system.fetch anywhere: with the seam set, the purchase
|
|
491
503
|
# rightly prefers it - the point of this pin is the OTHER
|
|
492
|
-
# case, ordinary options, where the
|
|
493
|
-
#
|
|
494
|
-
#
|
|
504
|
+
# case, ordinary options, where the default transport must
|
|
505
|
+
# carry the exchange. Only PreSpec runs, so no API call ever
|
|
506
|
+
# leaves; the one HTTP request is the purchase.
|
|
495
507
|
sdk = secrets_sdk({
|
|
496
508
|
"base": "http://127.0.0.1:%d/api" % srv.server_port,
|
|
497
509
|
"feature": {"secrets": {
|
|
@@ -548,7 +560,8 @@ class TestSecretsReviewPins(unittest.TestCase):
|
|
|
548
560
|
srv.shutdown()
|
|
549
561
|
srv.server_close()
|
|
550
562
|
|
|
551
|
-
# Real listeners and the
|
|
563
|
+
# Real listeners and the default transport: a stub follows nothing.
|
|
564
|
+
@over_default_transport
|
|
552
565
|
def test_a_redirect_answering_the_exchange_is_a_failure(self):
|
|
553
566
|
with _origins() as o:
|
|
554
567
|
answers = [[307, o["away"]], [308, o["away"]], [302, o["away"]],
|
|
@@ -577,6 +590,7 @@ class TestSecretsReviewPins(unittest.TestCase):
|
|
|
577
590
|
self.assertEqual([], allowed, "a redirect was not a failed exchange")
|
|
578
591
|
self.assertEqual(len(answers), refused)
|
|
579
592
|
|
|
593
|
+
@over_default_transport
|
|
580
594
|
def test_with_the_option_a_redirect_on_the_exchange_s_own_origin_is_followed(self):
|
|
581
595
|
with _origins() as o:
|
|
582
596
|
# Each case: the status, the Location, and the path the exchange is
|
|
@@ -367,6 +367,56 @@ class TestCacheFeature:
|
|
|
367
367
|
assert b["ctx"].response is sent[1]
|
|
368
368
|
assert h.client._cache["bypass"] == 2
|
|
369
369
|
|
|
370
|
+
def test_keys_on_the_request_headers(self):
|
|
371
|
+
server, calls = recording_server()
|
|
372
|
+
h = make_client([{"name": "cache", "options": {"ttl": 10000}}],
|
|
373
|
+
server=server)
|
|
374
|
+
h.op(op="load", path="/w/1", headers={"x-tenant": "tenant-a"})
|
|
375
|
+
h.op(op="load", path="/w/1", headers={"X-Tenant": "tenant-b"})
|
|
376
|
+
assert len(calls) == 2
|
|
377
|
+
h.op(op="load", path="/w/1", headers={"x-tenant": "tenant-b"})
|
|
378
|
+
assert len(calls) == 2
|
|
379
|
+
cache = [f for f in h.client.features if f.name == "cache"][0]
|
|
380
|
+
assert "tenant-" not in "\n".join(cache.store.keys())
|
|
381
|
+
|
|
382
|
+
def test_a_write_drops_its_collection(self):
|
|
383
|
+
server, calls = recording_server()
|
|
384
|
+
h = make_client([{"name": "cache", "options": {"ttl": 10000}}],
|
|
385
|
+
server=server)
|
|
386
|
+
paths = ["/w/1", "/w", "/w/1/part", "/other/1", "/w/2"]
|
|
387
|
+
for path in paths:
|
|
388
|
+
h.op(op="load", path=path)
|
|
389
|
+
h.op(op="update", method="PUT", path="/w/1")
|
|
390
|
+
for path in paths:
|
|
391
|
+
h.op(op="load", path=path)
|
|
392
|
+
assert len(calls) == 9
|
|
393
|
+
assert h.client._cache["hit"] == 2
|
|
394
|
+
|
|
395
|
+
def test_cache_control_prevents_storing(self):
|
|
396
|
+
for control in ["no-store", "private", "No-Cache", "max-age=60, private"]:
|
|
397
|
+
server, calls = recording_server(
|
|
398
|
+
lambda _n, _fd: make_response(200, {"ok": True}, {"Cache-Control": control}))
|
|
399
|
+
h = make_client([{"name": "cache", "options": {"ttl": 10000}}],
|
|
400
|
+
server=server)
|
|
401
|
+
h.op(op="load", path="/w")
|
|
402
|
+
h.op(op="load", path="/w")
|
|
403
|
+
assert len(calls) == 2, control
|
|
404
|
+
|
|
405
|
+
def test_max_age_caps_the_ttl(self):
|
|
406
|
+
clock = make_clock()
|
|
407
|
+
server, calls = recording_server(
|
|
408
|
+
lambda _n, _fd: make_response(200, {"ok": True}, {"cache-control": "max-age=1"}))
|
|
409
|
+
h = make_client([{"name": "cache",
|
|
410
|
+
"options": {"ttl": 10000, "now": clock.now}}],
|
|
411
|
+
server=server)
|
|
412
|
+
h.op(op="load", path="/w")
|
|
413
|
+
clock.advance(500)
|
|
414
|
+
h.op(op="load", path="/w")
|
|
415
|
+
assert len(calls) == 1
|
|
416
|
+
clock.advance(600)
|
|
417
|
+
h.op(op="load", path="/w")
|
|
418
|
+
assert len(calls) == 2
|
|
419
|
+
|
|
370
420
|
def test_inactive_cache_does_not_wrap(self):
|
|
371
421
|
server, calls = recording_server()
|
|
372
422
|
h = make_client([{"name": "cache", "options": {"active": False}}],
|
|
@@ -670,6 +720,29 @@ class TestAuditFeature:
|
|
|
670
720
|
assert len(h.client._audit["records"]) == 0
|
|
671
721
|
|
|
672
722
|
|
|
723
|
+
# --- one call, one id -------------------------------------------------------
|
|
724
|
+
@pytest.mark.skipif(not (has_feature("telemetry") and has_feature("debug")
|
|
725
|
+
and has_feature("audit")),
|
|
726
|
+
reason="telemetry, debug or audit not in this SDK")
|
|
727
|
+
class TestOneCallOneId:
|
|
728
|
+
|
|
729
|
+
def test_telemetry_debug_and_audit_carry_one_calls_context_id(self):
|
|
730
|
+
h = make_client([{"name": "telemetry"}, {"name": "debug"},
|
|
731
|
+
{"name": "audit"}])
|
|
732
|
+
h.op(op="load")
|
|
733
|
+
h.op(op="list")
|
|
734
|
+
|
|
735
|
+
def ids(recs):
|
|
736
|
+
return [rec.get("correlationId") for rec in recs]
|
|
737
|
+
|
|
738
|
+
calls = ids(h.client._audit["records"])
|
|
739
|
+
assert len(calls) == 2
|
|
740
|
+
assert all(isinstance(cid, str) and cid != "" for cid in calls), calls
|
|
741
|
+
assert calls[0] != calls[1]
|
|
742
|
+
assert ids(h.client._telemetry["spans"]) == calls
|
|
743
|
+
assert ids(h.client._debug["entries"]) == calls
|
|
744
|
+
|
|
745
|
+
|
|
673
746
|
# --- clienttrack ------------------------------------------------------------------
|
|
674
747
|
@pytest.mark.skipif(not has_feature("clienttrack"),
|
|
675
748
|
reason="clienttrack not in this SDK")
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import json
|
|
17
17
|
import os
|
|
18
18
|
import re
|
|
19
|
+
import time
|
|
19
20
|
|
|
20
21
|
import pytest
|
|
21
22
|
|
|
@@ -158,9 +159,25 @@ def _candidates(client):
|
|
|
158
159
|
return out
|
|
159
160
|
|
|
160
161
|
|
|
161
|
-
def _invoke(client, op, ctrl):
|
|
162
|
+
def _invoke(client, op, ctrl, args=None):
|
|
162
163
|
ent = getattr(client, op["accessor"])()
|
|
163
|
-
return getattr(ent, op["op"])({}, ctrl)
|
|
164
|
+
return getattr(ent, op["op"])(dict(args or {}), ctrl)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
ITEM_ARGS = {"id": "corpus-item"}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _usable_item(accessor):
|
|
171
|
+
"""A write of one entity (#ITEM) that completes when driven with ITEM_ARGS."""
|
|
172
|
+
for cand in _candidates(_client({})):
|
|
173
|
+
if cand["accessor"] != accessor or cand["op"] not in ("update", "patch", "remove"):
|
|
174
|
+
continue
|
|
175
|
+
try:
|
|
176
|
+
_invoke(_client({}), cand, {}, ITEM_ARGS)
|
|
177
|
+
except Exception:
|
|
178
|
+
continue
|
|
179
|
+
return cand
|
|
180
|
+
return None
|
|
164
181
|
|
|
165
182
|
|
|
166
183
|
def _usable_ops(want):
|
|
@@ -183,6 +200,48 @@ def _usable_ops(want):
|
|
|
183
200
|
return picked
|
|
184
201
|
|
|
185
202
|
|
|
203
|
+
READ_OPS = ("list", "load")
|
|
204
|
+
WRITE_OPS = ("create", "update", "patch", "remove")
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _usable_pair():
|
|
208
|
+
"""A read and a write of one entity (#READ, #WRITE), each driven as
|
|
209
|
+
_usable_ops drives an op."""
|
|
210
|
+
found = {}
|
|
211
|
+
for cand in _candidates(_client({})):
|
|
212
|
+
role = "read" if cand["op"] in READ_OPS else "write" if cand["op"] in WRITE_OPS else None
|
|
213
|
+
seen = found.setdefault(cand["accessor"], {})
|
|
214
|
+
if role is None or role in seen:
|
|
215
|
+
continue
|
|
216
|
+
try:
|
|
217
|
+
_invoke(_client({}), cand, {})
|
|
218
|
+
except Exception:
|
|
219
|
+
continue
|
|
220
|
+
seen[role] = cand
|
|
221
|
+
if "read" in seen and "write" in seen:
|
|
222
|
+
return seen
|
|
223
|
+
return None
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _step(client, op, step, ctrl):
|
|
227
|
+
"""One step: it may wait before its call, may add request headers for
|
|
228
|
+
its call, and may pass `args` as the operation's first argument."""
|
|
229
|
+
if step.get("wait") is not None:
|
|
230
|
+
time.sleep(step["wait"] / 1000.0)
|
|
231
|
+
options = client._rootctx.options
|
|
232
|
+
prior = options.get("headers")
|
|
233
|
+
if step.get("headers") is not None:
|
|
234
|
+
options["headers"] = dict(prior or {}, **step["headers"])
|
|
235
|
+
try:
|
|
236
|
+
return _invoke(client, op, ctrl, step.get("args"))
|
|
237
|
+
finally:
|
|
238
|
+
if step.get("headers") is not None:
|
|
239
|
+
if prior is None:
|
|
240
|
+
options.pop("headers", None)
|
|
241
|
+
else:
|
|
242
|
+
options["headers"] = prior
|
|
243
|
+
|
|
244
|
+
|
|
186
245
|
def _resolve(node, tokens):
|
|
187
246
|
"""Replace #OPn throughout a case, keys included."""
|
|
188
247
|
if isinstance(node, str):
|
|
@@ -315,6 +374,14 @@ class TestFeatureCorpus:
|
|
|
315
374
|
|
|
316
375
|
ops = _usable_ops(2)
|
|
317
376
|
by_key = {o["key"]: o for o in ops}
|
|
377
|
+
pair = _usable_pair()
|
|
378
|
+
if pair is not None:
|
|
379
|
+
by_key[pair["read"]["key"]] = pair["read"]
|
|
380
|
+
by_key[pair["write"]["key"]] = pair["write"]
|
|
381
|
+
pair["item"] = _usable_item(pair["read"]["accessor"])
|
|
382
|
+
if pair["item"] is not None:
|
|
383
|
+
by_key[pair["item"]["key"]] = pair["item"]
|
|
384
|
+
pair["other"] = next((o for o in ops if o["accessor"] != pair["read"]["accessor"]), None)
|
|
318
385
|
|
|
319
386
|
ran = 0
|
|
320
387
|
failed = []
|
|
@@ -326,6 +393,18 @@ class TestFeatureCorpus:
|
|
|
326
393
|
raw.get("name"), need, len(ops)))
|
|
327
394
|
continue
|
|
328
395
|
|
|
396
|
+
paired = re.search(r"#(READ|WRITE|ITEM|OTHER)\b", json.dumps(raw)) is not None
|
|
397
|
+
if paired and pair is None:
|
|
398
|
+
print('skip "{}": needs a read and a write of one entity, this SDK offers none'.format(
|
|
399
|
+
raw.get("name")))
|
|
400
|
+
continue
|
|
401
|
+
lacking = next((tok for tok, role in (("#ITEM", "item"), ("#OTHER", "other"))
|
|
402
|
+
if paired and pair[role] is None
|
|
403
|
+
and re.search(tok + r"\b", json.dumps(raw))), None)
|
|
404
|
+
if lacking is not None:
|
|
405
|
+
print('skip "{}": needs {}, which this SDK cannot drive'.format(raw.get("name"), lacking))
|
|
406
|
+
continue
|
|
407
|
+
|
|
329
408
|
missing = _missing_feature(raw, have)
|
|
330
409
|
if missing is not None:
|
|
331
410
|
print('skip "{}": needs the {} feature, which this SDK does not generate'.format(
|
|
@@ -335,6 +414,12 @@ class TestFeatureCorpus:
|
|
|
335
414
|
tokens = {}
|
|
336
415
|
for i in range(need):
|
|
337
416
|
tokens["#OP{}".format(i + 1)] = ops[i]["key"]
|
|
417
|
+
if paired:
|
|
418
|
+
tokens["#READ"] = pair["read"]["key"]
|
|
419
|
+
tokens["#WRITE"] = pair["write"]["key"]
|
|
420
|
+
for tok, role in (("#ITEM", "item"), ("#OTHER", "other")):
|
|
421
|
+
if pair[role] is not None:
|
|
422
|
+
tokens[tok] = pair[role]["key"]
|
|
338
423
|
kase = _resolve(raw, tokens)
|
|
339
424
|
label = kase.get("name")
|
|
340
425
|
ran += 1
|
|
@@ -350,7 +435,7 @@ class TestFeatureCorpus:
|
|
|
350
435
|
wanterr = step.get("err")
|
|
351
436
|
|
|
352
437
|
try:
|
|
353
|
-
|
|
438
|
+
_step(client, op, step, ctrl)
|
|
354
439
|
assert wanterr is None, \
|
|
355
440
|
"{}: {} was expected to fail, and did not".format(label, step["op"])
|
|
356
441
|
except AssertionError:
|
|
@@ -15,7 +15,7 @@ class ProjectNameContext
|
|
|
15
15
|
OPMAP_LOCK = Mutex.new
|
|
16
16
|
|
|
17
17
|
attr_accessor :id, :out, :client, :utility, :ctrl, :meta, :config,
|
|
18
|
-
:entopts, :options, :entity, :shared, :opmap,
|
|
18
|
+
:entopts, :options, :cleancfg, :entity, :shared, :opmap,
|
|
19
19
|
:data, :reqdata, :match, :reqmatch, :point,
|
|
20
20
|
:spec, :result, :response, :op, :unexpected_fired
|
|
21
21
|
|
|
@@ -53,6 +53,9 @@ class ProjectNameContext
|
|
|
53
53
|
o = ProjectNameHelpers.get_ctx_prop(ctxmap, "options")
|
|
54
54
|
@options = o.is_a?(Hash) ? o : basectx&.options
|
|
55
55
|
|
|
56
|
+
# The clean registry, beside the options rather than in them.
|
|
57
|
+
@cleancfg = ProjectNameHelpers.get_ctx_prop(ctxmap, "cleancfg") || basectx&.cleancfg
|
|
58
|
+
|
|
56
59
|
e = ProjectNameHelpers.get_ctx_prop(ctxmap, "entity")
|
|
57
60
|
@entity = e || basectx&.entity
|
|
58
61
|
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
require_relative 'base_feature'
|
|
13
13
|
|
|
14
14
|
class ProjectNameAuditFeature < ProjectNameBaseFeature
|
|
15
|
+
AUDIT_SEEN_KEY = "audit_seen"
|
|
16
|
+
|
|
15
17
|
def initialize
|
|
16
18
|
super
|
|
17
19
|
@version = "0.0.1"
|
|
@@ -21,7 +23,6 @@ class ProjectNameAuditFeature < ProjectNameBaseFeature
|
|
|
21
23
|
@client = nil
|
|
22
24
|
@options = {}
|
|
23
25
|
@seq = 0
|
|
24
|
-
@seen = {}
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def init(ctx, options)
|
|
@@ -29,7 +30,6 @@ class ProjectNameAuditFeature < ProjectNameBaseFeature
|
|
|
29
30
|
@options = options.is_a?(Hash) ? options : {}
|
|
30
31
|
@active = @options["active"] == true
|
|
31
32
|
@seq = 0
|
|
32
|
-
@seen = {}
|
|
33
33
|
|
|
34
34
|
return unless @active
|
|
35
35
|
|
|
@@ -53,9 +53,10 @@ class ProjectNameAuditFeature < ProjectNameBaseFeature
|
|
|
53
53
|
|
|
54
54
|
def _emit(ctx, outcome)
|
|
55
55
|
# One record per operation (PreDone + a following PreUnexpected on a
|
|
56
|
-
# non-2xx must not double-log).
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
# non-2xx must not double-log). The marker lives on the context, so it
|
|
57
|
+
# goes when the call does.
|
|
58
|
+
return if ctx.out[AUDIT_SEEN_KEY] == true
|
|
59
|
+
ctx.out[AUDIT_SEEN_KEY] = true
|
|
59
60
|
@seq += 1
|
|
60
61
|
|
|
61
62
|
record = ctx.utility.clean.call(ctx, {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# ProjectName SDK cache feature
|
|
2
2
|
#
|
|
3
|
-
# Response caching for safe (read) requests
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# 256, oldest evicted first) and every hit/miss/bypass is counted for
|
|
9
|
-
# inspection. Replayed responses expose a re-readable "json" body.
|
|
3
|
+
# Response caching for safe (read) requests, per client: see the features
|
|
4
|
+
# reference for the key, the write invalidation and the Cache-Control rules.
|
|
5
|
+
|
|
6
|
+
require 'openssl'
|
|
7
|
+
require 'securerandom'
|
|
10
8
|
|
|
11
9
|
require_relative 'base_feature'
|
|
12
10
|
require_relative '../utility/media'
|
|
13
11
|
|
|
14
12
|
class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
13
|
+
SAFE_METHODS = ["GET", "HEAD"].freeze
|
|
14
|
+
UNSTORED = ["no-store", "private", "no-cache"].freeze
|
|
15
|
+
MAX_AGE = /\Amax-age\s*=\s*"?(\d+)"?\z/
|
|
16
|
+
|
|
15
17
|
def initialize
|
|
16
18
|
super
|
|
17
19
|
@version = "0.0.1"
|
|
@@ -31,6 +33,7 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
31
33
|
return unless @active
|
|
32
34
|
|
|
33
35
|
@store = {}
|
|
36
|
+
@secret = SecureRandom.random_bytes(32)
|
|
34
37
|
|
|
35
38
|
feature = self
|
|
36
39
|
utility = ctx.utility
|
|
@@ -45,9 +48,17 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
45
48
|
method = ((fetchdef.is_a?(Hash) && fetchdef["method"]) || "GET").to_s.upcase
|
|
46
49
|
methods = @options["methods"] || ["GET"]
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
unless methods.include?(method)
|
|
52
|
+
return inner.call(ctx, url, fetchdef) if SAFE_METHODS.include?(method)
|
|
53
|
+
begin
|
|
54
|
+
return inner.call(ctx, url, fetchdef)
|
|
55
|
+
ensure
|
|
56
|
+
_invalidate(url)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
headers = fetchdef.is_a?(Hash) ? fetchdef["headers"] : nil
|
|
61
|
+
key = "#{method} #{url} #{_digest(headers)}"
|
|
51
62
|
now = _now
|
|
52
63
|
hit = @store[key]
|
|
53
64
|
|
|
@@ -66,9 +77,14 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
66
77
|
|
|
67
78
|
if err.nil? && _cacheable(res)
|
|
68
79
|
snapshot = _snapshot(res)
|
|
69
|
-
ttl = @options["ttl"].nil? ? 5000 : @options["ttl"]
|
|
80
|
+
ttl = self.class.lifetime(snapshot["headers"], @options["ttl"].nil? ? 5000 : @options["ttl"])
|
|
81
|
+
if ttl <= 0
|
|
82
|
+
_track("bypass")
|
|
83
|
+
return _replay(snapshot), nil
|
|
84
|
+
end
|
|
85
|
+
@store.delete(key)
|
|
70
86
|
_evict
|
|
71
|
-
@store[key] = { "expiry" => now + ttl, "snapshot" => snapshot }
|
|
87
|
+
@store[key] = { "expiry" => now + ttl, "scope" => self.class.scope(url), "snapshot" => snapshot }
|
|
72
88
|
_track("miss")
|
|
73
89
|
return _replay(snapshot), nil
|
|
74
90
|
end
|
|
@@ -77,6 +93,54 @@ class ProjectNameCacheFeature < ProjectNameBaseFeature
|
|
|
77
93
|
return res, err
|
|
78
94
|
end
|
|
79
95
|
|
|
96
|
+
def _digest(headers)
|
|
97
|
+
pairs = []
|
|
98
|
+
if headers.is_a?(Hash)
|
|
99
|
+
headers.each { |k, v| pairs << [k.to_s.downcase, v.to_s] unless v.nil? }
|
|
100
|
+
end
|
|
101
|
+
text = pairs.sort.map { |k, v| "#{k}:#{v}\n" }.join
|
|
102
|
+
OpenSSL::HMAC.hexdigest("SHA256", @secret, text)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def _invalidate(url)
|
|
106
|
+
path = self.class.scope(url)
|
|
107
|
+
collection = self.class.parent(path)
|
|
108
|
+
@store.delete_if do |_k, e|
|
|
109
|
+
self.class.under(e["scope"], path) || e["scope"] == collection
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# The configured ttl capped by the response's Cache-Control; zero when the
|
|
114
|
+
# response may not be stored.
|
|
115
|
+
def self.lifetime(headers, ttl)
|
|
116
|
+
control = ""
|
|
117
|
+
(headers || {}).each { |k, v| control = v.to_s if k.to_s.downcase == "cache-control" }
|
|
118
|
+
life = ttl
|
|
119
|
+
control.downcase.split(",").each do |part|
|
|
120
|
+
directive = part.strip
|
|
121
|
+
return 0 if UNSTORED.include?(directive)
|
|
122
|
+
age = MAX_AGE.match(directive)
|
|
123
|
+
life = [life, age[1].to_i * 1000].min unless age.nil?
|
|
124
|
+
end
|
|
125
|
+
life
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.scope(url)
|
|
129
|
+
url.to_s.split(/[?#]/, 2).first.to_s.sub(%r{/+\z}, "")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def self.parent(scope)
|
|
133
|
+
scheme = scope.index("://")
|
|
134
|
+
root = scheme.nil? ? 0 : scope.index("/", scheme + 3)
|
|
135
|
+
return scope if root.nil?
|
|
136
|
+
cut = scope.rindex("/") || 0
|
|
137
|
+
scope[0, [cut, root].max]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def self.under(scope, prefix)
|
|
141
|
+
scope == prefix || scope.start_with?(prefix + "/")
|
|
142
|
+
end
|
|
143
|
+
|
|
80
144
|
# A body the transport could not read as JSON passes through, for the operation to report.
|
|
81
145
|
def _cacheable(res)
|
|
82
146
|
return false unless res.is_a?(Hash)
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
# mutex is always the innermost lock so the three can never deadlock.
|
|
48
48
|
|
|
49
49
|
require 'json'
|
|
50
|
-
require 'net/http'
|
|
51
50
|
require 'uri'
|
|
52
51
|
|
|
53
52
|
require_relative 'base_feature'
|
|
54
53
|
require_relative '../utility/struct/voxgig_struct'
|
|
54
|
+
require_relative '../utility/fetcher'
|
|
55
55
|
require_relative 'secrets/voxgig_sekreto'
|
|
56
56
|
|
|
57
57
|
class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
@@ -236,6 +236,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
236
236
|
# provider ERROR refuses the request with the provider's own message;
|
|
237
237
|
# never an unauthenticated send.
|
|
238
238
|
err = resolve
|
|
239
|
+
return nil, err if err.is_a?(ProjectNameError)
|
|
239
240
|
unless err.nil?
|
|
240
241
|
return nil, ctx.make_error("secrets_provider", err.to_s)
|
|
241
242
|
end
|
|
@@ -454,27 +455,22 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
454
455
|
base = options["base"].is_a?(String) ? options["base"] : ""
|
|
455
456
|
url = base.sub(%r{/+\z}, "") + "/" + x["path"].sub(%r{\A/+}, "")
|
|
456
457
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
#
|
|
460
|
-
|
|
461
|
-
# and minimal on purpose: see the NOT-the-SDK-transport note below.
|
|
462
|
-
fetch = ProjectNameSecretsFeature.method(:raw_exchange_fetch) unless fetch.is_a?(Proc)
|
|
458
|
+
# The SDK's own transport, beneath every feature's wrapper: it holds the
|
|
459
|
+
# test feature's block and the GET-only guard, and the wrapped one would
|
|
460
|
+
# recurse on the first expiry.
|
|
461
|
+
fetch = ->(at, fd) { ProjectNameUtilities::Fetcher.call(@ctx, at, fd) }
|
|
463
462
|
|
|
464
463
|
# The body is MARSHALLED, never concatenated: a refresh token (or a
|
|
465
464
|
# configured request-field name) carrying a quote, backslash or newline
|
|
466
465
|
# must arrive as that literal value, not as malformed JSON.
|
|
467
|
-
#
|
|
468
|
-
# Deliberately NOT the SDK transport. The transport is what this
|
|
469
|
-
# feature wraps, and sending the token request back through it would
|
|
470
|
-
# recurse on the first expiry - and would route the exchange through
|
|
471
|
-
# the test mock, which knows nothing about it.
|
|
472
466
|
fetchdef = {
|
|
473
467
|
"method" => x["method"],
|
|
474
468
|
"headers" => { "content-type" => "application/json" },
|
|
475
469
|
"body" => JSON.generate({ x["request"] => @refresh }),
|
|
476
470
|
# Never followed by the client: a redirect would carry the refresh token on.
|
|
477
471
|
"redirect" => "manual",
|
|
472
|
+
# Its own bound, in milliseconds: the timeout feature's wrapper is above.
|
|
473
|
+
"timeout" => 30_000,
|
|
478
474
|
}
|
|
479
475
|
|
|
480
476
|
res, err = fetch.call(url, fetchdef)
|
|
@@ -490,6 +486,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
490
486
|
res, err = fetch.call(at, fetchdef)
|
|
491
487
|
end
|
|
492
488
|
|
|
489
|
+
raise err if err.is_a?(ProjectNameError)
|
|
493
490
|
unless err.nil?
|
|
494
491
|
raise VoxgigSekreto::SekretoError,
|
|
495
492
|
"secrets: token exchange failed: #{err} from #{url}"
|
|
@@ -599,56 +596,4 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
599
596
|
def _str(value, dflt)
|
|
600
597
|
value.is_a?(String) && !value.empty? ? value : dflt
|
|
601
598
|
end
|
|
602
|
-
|
|
603
|
-
# Token-exchange transport of last resort: plain net/http, answering the
|
|
604
|
-
# same [res, err] shape the system.fetch seam promises ("status" +
|
|
605
|
-
# "json"). It exists so an exchange works with ordinary SDK options -
|
|
606
|
-
# requiring a custom transport for the COMMON case would reject every
|
|
607
|
-
# live token purchase before a request was made.
|
|
608
|
-
def self.raw_exchange_fetch(fullurl, fetchdef)
|
|
609
|
-
uri = URI.parse(fullurl)
|
|
610
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
611
|
-
http.use_ssl = (uri.scheme == "https")
|
|
612
|
-
http.open_timeout = 30
|
|
613
|
-
http.read_timeout = 30
|
|
614
|
-
|
|
615
|
-
method_str = (fetchdef["method"] || "POST").to_s.upcase
|
|
616
|
-
klass = case method_str
|
|
617
|
-
when "PUT" then Net::HTTP::Put
|
|
618
|
-
when "PATCH" then Net::HTTP::Patch
|
|
619
|
-
when "GET" then Net::HTTP::Get
|
|
620
|
-
else Net::HTTP::Post
|
|
621
|
-
end
|
|
622
|
-
|
|
623
|
-
request = klass.new(uri)
|
|
624
|
-
(fetchdef["headers"] || {}).each do |k, v|
|
|
625
|
-
request[k] = v.to_s if v.is_a?(String)
|
|
626
|
-
end
|
|
627
|
-
body = fetchdef["body"]
|
|
628
|
-
request.body = body if body.is_a?(String)
|
|
629
|
-
|
|
630
|
-
# Net::HTTP#request follows no redirect: a 3xx is returned as its status.
|
|
631
|
-
resp = http.request(request)
|
|
632
|
-
raw = resp.body
|
|
633
|
-
|
|
634
|
-
# A non-2xx answer IS a response: hand back its status so the caller
|
|
635
|
-
# reports "token exchange failed: <status>" rather than a transport
|
|
636
|
-
# error.
|
|
637
|
-
resp_headers = {}
|
|
638
|
-
resp.each_header { |k, v| resp_headers[k.downcase] = v }
|
|
639
|
-
|
|
640
|
-
return {
|
|
641
|
-
"status" => resp.code.to_i,
|
|
642
|
-
"headers" => resp_headers,
|
|
643
|
-
"json" => -> {
|
|
644
|
-
begin
|
|
645
|
-
raw.nil? || raw.empty? ? nil : JSON.parse(raw)
|
|
646
|
-
rescue StandardError
|
|
647
|
-
nil
|
|
648
|
-
end
|
|
649
|
-
},
|
|
650
|
-
}, nil
|
|
651
|
-
rescue StandardError => e
|
|
652
|
-
return nil, e
|
|
653
|
-
end
|
|
654
599
|
end
|
|
@@ -42,6 +42,7 @@ class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
|
42
42
|
span = {
|
|
43
43
|
"traceId" => _id("trace"),
|
|
44
44
|
"spanId" => _id("span"),
|
|
45
|
+
"correlationId" => ctx.id,
|
|
45
46
|
"name" => "#{ctx.op ? ctx.op.entity : '_'}.#{ctx.op ? ctx.op.name : '_'}",
|
|
46
47
|
"start" => _now,
|
|
47
48
|
"end" => nil,
|