@voxgig/sdkgen 4.48.0 → 4.49.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/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +9 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/secrets.aontu +3 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
- package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
- package/project/.sdk/tm/c/feature/cache.c +16 -1
- package/project/.sdk/tm/c/feature/secrets.c +149 -18
- package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
- package/project/.sdk/tm/c/tests/feature_test.c +31 -0
- package/project/.sdk/tm/c/utility/make_spec.c +1 -1
- package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
- package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
- package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
- package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
- package/project/.sdk/tm/cpp/core/types.hpp +1 -11
- package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
- package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
- package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
- package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
- package/project/.sdk/tm/csharp/core/Control.cs +0 -5
- package/project/.sdk/tm/csharp/core/Point.cs +6 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
- package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
- package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
- package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
- package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
- package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
- package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
- package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
- package/project/.sdk/tm/go/core/target.go +8 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
- package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
- package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/media.go +2 -2
- package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
- package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
- package/project/.sdk/tm/java/core/Control.java +0 -5
- package/project/.sdk/tm/java/core/Point.java +7 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
- package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
- package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
- package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
- package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
- package/project/.sdk/tm/java/utility/Media.java +2 -2
- package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
- package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
- package/project/.sdk/tm/js/src/Point.js +2 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
- package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
- package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
- package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
- package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
- package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
- package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
- package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
- package/project/.sdk/tm/lua/utility/clean.lua +1 -0
- package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
- package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
- package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
- package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
- package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
- package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
- package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
- package/project/.sdk/tm/perl/t/feature.t +24 -0
- package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
- package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
- package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
- package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
- package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
- package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
- package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
- package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
- package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
- package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
- package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
- package/project/.sdk/tm/py/test/test_feature.py +18 -0
- package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
- package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
- package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
- package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
- package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
- package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
- package/project/.sdk/tm/rust/feature/cache.rs +15 -1
- package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
- package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
- package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
- package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
- package/project/.sdk/tm/scala/core/Control.scala +0 -5
- package/project/.sdk/tm/scala/core/Point.scala +3 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
- package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
- package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
- package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
- package/project/.sdk/tm/ts/src/Point.ts +3 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/zig/core/utility.zig +47 -4
- package/project/.sdk/tm/zig/feature/cache.zig +15 -1
- package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
- package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
- package/project/sdkgen-package.json +1 -1
- package/src/utility.ts +12 -1
|
@@ -64,6 +64,7 @@ local helpers = require("core.helpers")
|
|
|
64
64
|
local BaseFeature = require("feature.base_feature")
|
|
65
65
|
local sekreto = require("feature.secrets.sekreto")
|
|
66
66
|
local tls = require("utility.tls")
|
|
67
|
+
local base64 = require("utility.clean").base64
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
local SecretsFeature = {}
|
|
@@ -82,6 +83,34 @@ setmetatable(SecretsFeature, { __index = BaseFeature })
|
|
|
82
83
|
local NOTAPROVIDER = "sekreto: not a provider or a provider spec: "
|
|
83
84
|
|
|
84
85
|
|
|
86
|
+
local REDIRECT_MAX = 5
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
local function origin(u)
|
|
90
|
+
local parsed = require("socket.url").parse(u) or {}
|
|
91
|
+
local scheme = string.lower(parsed.scheme or "")
|
|
92
|
+
return scheme .. "://" .. string.lower(parsed.host or "") .. ":" ..
|
|
93
|
+
tostring(parsed.port or (scheme == "https" and 443 or 80))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
-- Where a redirect keeping method and body (307 or 308) points, on the
|
|
98
|
+
-- exchange's own origin. Any other would drop the body or leave the origin.
|
|
99
|
+
local function moved(url, at, res)
|
|
100
|
+
local status = type(res) == "table" and helpers.to_int(vs.getprop(res, "status")) or -1
|
|
101
|
+
local headers = type(res) == "table" and vs.getprop(res, "headers") or nil
|
|
102
|
+
local location = type(headers) == "table" and headers["location"] or nil
|
|
103
|
+
if (status ~= 307 and status ~= 308) or type(location) ~= "string" or location == "" then
|
|
104
|
+
return nil
|
|
105
|
+
end
|
|
106
|
+
local ok, next = pcall(function()
|
|
107
|
+
local resolved = require("socket.url").absolute(at, (string.gsub(location, "%s", "")))
|
|
108
|
+
return origin(resolved) == origin(url) and resolved or nil
|
|
109
|
+
end)
|
|
110
|
+
return ok and next or nil
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
|
|
85
114
|
local function optstr(map, key, dflt)
|
|
86
115
|
local v = map ~= nil and map[key] or nil
|
|
87
116
|
if type(v) == "string" and v ~= "" then
|
|
@@ -139,6 +168,11 @@ function SecretsFeature.new()
|
|
|
139
168
|
-- read for `apikey` and for the `auth` suppression, never written.
|
|
140
169
|
self._liveopts = nil
|
|
141
170
|
|
|
171
|
+
-- What prepare_auth was generated from: the config declares auth only
|
|
172
|
+
-- where it places a credential, and Basic only where it composes one.
|
|
173
|
+
self._declared = false
|
|
174
|
+
self._basic = false
|
|
175
|
+
|
|
142
176
|
self._secretname = "apikey"
|
|
143
177
|
self._cache = true
|
|
144
178
|
self._sek = nil
|
|
@@ -180,6 +214,10 @@ function SecretsFeature:init(ctx, options)
|
|
|
180
214
|
self._rootctx = ctx
|
|
181
215
|
self.active = (self.options["active"] == true)
|
|
182
216
|
|
|
217
|
+
local declared = vs.getpath(ctx.config, "options.auth")
|
|
218
|
+
self._declared = type(declared) == "table"
|
|
219
|
+
self._basic = self._declared and declared["basic"] == true
|
|
220
|
+
|
|
183
221
|
if not self.active then
|
|
184
222
|
return
|
|
185
223
|
end
|
|
@@ -207,6 +245,7 @@ function SecretsFeature:init(ctx, options)
|
|
|
207
245
|
response = optstr(xopts, "response", "access_token"),
|
|
208
246
|
statuses = statuses,
|
|
209
247
|
retries = optnum(xopts, "retries", 1),
|
|
248
|
+
redirect = xopts["redirect"] == "same-origin" and "same-origin" or "refuse",
|
|
210
249
|
}
|
|
211
250
|
end
|
|
212
251
|
|
|
@@ -363,8 +402,15 @@ function SecretsFeature:_resolve()
|
|
|
363
402
|
end
|
|
364
403
|
|
|
365
404
|
|
|
405
|
+
-- prepare_auth's decision: auth the config declares, not suppressed by
|
|
406
|
+
-- clearing `options.auth`.
|
|
407
|
+
function SecretsFeature:_authon()
|
|
408
|
+
return self._declared and type(self._liveopts["auth"]) == "table"
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
|
|
366
412
|
function SecretsFeature:_resolve_once()
|
|
367
|
-
if self._sek == nil then
|
|
413
|
+
if self._sek == nil or not self:_authon() then
|
|
368
414
|
return nil
|
|
369
415
|
end
|
|
370
416
|
|
|
@@ -450,12 +496,9 @@ end
|
|
|
450
496
|
-- fetchdef, because the header was built before this request left and it
|
|
451
497
|
-- carries the token that just failed.
|
|
452
498
|
function SecretsFeature:_with_refresh(ctx, fullurl, fetchdef, inner)
|
|
453
|
-
-- A
|
|
454
|
-
--
|
|
455
|
-
|
|
456
|
-
-- cannot be fixed by buying one - retrying would transmit exactly the
|
|
457
|
-
-- credential the caller suppressed.
|
|
458
|
-
if self._liveopts["auth"] == nil then
|
|
499
|
+
-- A refusal of an unauthenticated request is not an expired token, and
|
|
500
|
+
-- retrying would transmit the credential that auth off withholds.
|
|
501
|
+
if not self:_authon() then
|
|
459
502
|
return inner(ctx, fullurl, fetchdef)
|
|
460
503
|
end
|
|
461
504
|
|
|
@@ -527,11 +570,11 @@ function SecretsFeature:_reauth(fetchdef, token)
|
|
|
527
570
|
-- stores no nil, and validate then fills the default), so the only
|
|
528
571
|
-- expressible suppression is clearing `client.options.auth` after
|
|
529
572
|
-- construction; this is the live table, so it is honoured here too.
|
|
530
|
-
|
|
531
|
-
if type(auth) ~= "table" then
|
|
573
|
+
if not self:_authon() then
|
|
532
574
|
headers["authorization"] = nil
|
|
533
575
|
return
|
|
534
576
|
end
|
|
577
|
+
local auth = self._liveopts["auth"]
|
|
535
578
|
|
|
536
579
|
-- The header prepare_auth writes: auth.name, lower-cased.
|
|
537
580
|
local name = auth["name"]
|
|
@@ -540,16 +583,33 @@ function SecretsFeature:_reauth(fetchdef, token)
|
|
|
540
583
|
end
|
|
541
584
|
name = string.lower(name)
|
|
542
585
|
|
|
586
|
+
local value = token
|
|
587
|
+
if self._basic and auth["basic"] == true then
|
|
588
|
+
value = self:_pair(token)
|
|
589
|
+
end
|
|
590
|
+
|
|
543
591
|
local prefix = auth["prefix"]
|
|
544
592
|
if type(prefix) ~= "string" then
|
|
545
593
|
prefix = ""
|
|
546
594
|
end
|
|
547
595
|
|
|
548
596
|
if prefix == "" then
|
|
549
|
-
headers[name] =
|
|
597
|
+
headers[name] = value
|
|
550
598
|
else
|
|
551
|
-
headers[name] = prefix .. " " ..
|
|
599
|
+
headers[name] = prefix .. " " .. value
|
|
600
|
+
end
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
-- Under Basic the token is the key half, as apikey is: prepare_auth's pair.
|
|
605
|
+
function SecretsFeature:_pair(token)
|
|
606
|
+
local secret = self._liveopts["secret"]
|
|
607
|
+
if type(secret) ~= "string" then
|
|
608
|
+
secret = ""
|
|
552
609
|
end
|
|
610
|
+
local pair = base64(token .. ":" .. secret)
|
|
611
|
+
self:_register(pair)
|
|
612
|
+
return pair
|
|
553
613
|
end
|
|
554
614
|
|
|
555
615
|
|
|
@@ -613,7 +673,7 @@ local function raw_exchange_fetch(fullurl, fetchdef)
|
|
|
613
673
|
end
|
|
614
674
|
|
|
615
675
|
local chunks = {}
|
|
616
|
-
local res, code = http.request({
|
|
676
|
+
local res, code, rawheaders = http.request({
|
|
617
677
|
url = fullurl,
|
|
618
678
|
method = fetchdef["method"] or "POST",
|
|
619
679
|
headers = headers,
|
|
@@ -628,9 +688,14 @@ local function raw_exchange_fetch(fullurl, fetchdef)
|
|
|
628
688
|
end
|
|
629
689
|
|
|
630
690
|
local raw = table.concat(chunks)
|
|
691
|
+
local resheaders = {}
|
|
692
|
+
for k, v in pairs(type(rawheaders) == "table" and rawheaders or {}) do
|
|
693
|
+
resheaders[string.lower(k)] = v
|
|
694
|
+
end
|
|
631
695
|
|
|
632
696
|
return {
|
|
633
697
|
status = code,
|
|
698
|
+
headers = resheaders,
|
|
634
699
|
json = function()
|
|
635
700
|
if #raw == 0 then
|
|
636
701
|
return nil
|
|
@@ -676,13 +741,25 @@ function SecretsFeature:_buy_once()
|
|
|
676
741
|
-- The body is ENCODED, never concatenated: a refresh token (or a
|
|
677
742
|
-- configured request-field name) carrying a quote, backslash or newline
|
|
678
743
|
-- must arrive as that literal value, not as malformed JSON.
|
|
679
|
-
local
|
|
744
|
+
local fetchdef = {
|
|
680
745
|
method = x.method,
|
|
681
746
|
headers = { ["content-type"] = "application/json" },
|
|
682
747
|
body = json.encode({ [x.request] = self._refresh }),
|
|
683
|
-
-- Never followed: a redirect would carry the refresh token on.
|
|
748
|
+
-- Never followed by the client: a redirect would carry the refresh token on.
|
|
684
749
|
redirect = "manual",
|
|
685
|
-
}
|
|
750
|
+
}
|
|
751
|
+
local res, err = fetch(url, fetchdef)
|
|
752
|
+
|
|
753
|
+
-- By option alone, and only while the exchange stays on its own origin.
|
|
754
|
+
local at = url
|
|
755
|
+
for _ = 1, x.redirect == "same-origin" and REDIRECT_MAX or 0 do
|
|
756
|
+
local next = err == nil and moved(url, at, res) or nil
|
|
757
|
+
if next == nil then
|
|
758
|
+
break
|
|
759
|
+
end
|
|
760
|
+
at = next
|
|
761
|
+
res, err = fetch(at, fetchdef)
|
|
762
|
+
end
|
|
686
763
|
|
|
687
764
|
if err ~= nil then
|
|
688
765
|
return nil, sekreto.SekretoError(
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
local sdk = require("project-name-_sdk")
|
|
39
39
|
local SecretsFeature = require("feature.secrets_feature")
|
|
40
40
|
local sekreto = require("feature.secrets.sekreto")
|
|
41
|
+
local base64 = require("utility.clean").base64
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
-- The header the credential travels in: the DEFAULT client's auth.name,
|
|
@@ -53,6 +54,17 @@ local CREDHEADER = (function()
|
|
|
53
54
|
end)()
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
-- The form prepare_auth writes, from the DEFAULT client's auth: under Basic
|
|
58
|
+
-- the token is the key half of the encoded pair, and a prefix is
|
|
59
|
+
-- space-joined.
|
|
60
|
+
local CREDFORM = (function()
|
|
61
|
+
local auth = sdk.test(nil, nil):options_map().auth
|
|
62
|
+
auth = type(auth) == "table" and auth or {}
|
|
63
|
+
local prefix = type(auth.prefix) == "string" and auth.prefix or ""
|
|
64
|
+
return { prefix = prefix, basic = auth.basic == true }
|
|
65
|
+
end)()
|
|
66
|
+
|
|
67
|
+
|
|
56
68
|
-- ---------------------------------------------------------------------
|
|
57
69
|
-- The recording transport: system.fetch for a LIVE client, scripting one
|
|
58
70
|
-- status per API call (the last repeating) and a token endpoint for the
|
|
@@ -78,8 +90,10 @@ local function make_wire(script)
|
|
|
78
90
|
w.fetch = function(url, fetchdef)
|
|
79
91
|
local headers = type(fetchdef) == "table" and fetchdef.headers or {}
|
|
80
92
|
local auth = headers[CREDHEADER]
|
|
93
|
+
local values = {}
|
|
94
|
+
for _, v in pairs(headers) do values[#values + 1] = tostring(v) end
|
|
81
95
|
w.calls[#w.calls + 1] = {
|
|
82
|
-
url = url, auth = auth, has = auth ~= nil,
|
|
96
|
+
url = url, auth = auth, has = auth ~= nil, values = table.concat(values, "\n"),
|
|
83
97
|
body = fetchdef.body, method = fetchdef.method, redirect = fetchdef.redirect,
|
|
84
98
|
}
|
|
85
99
|
|
|
@@ -126,14 +140,22 @@ end
|
|
|
126
140
|
-- ---------------------------------------------------------------------
|
|
127
141
|
-- Support.
|
|
128
142
|
|
|
129
|
-
-- The
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
-- The header value prepare_auth writes for a token.
|
|
144
|
+
local function credential(token, secret)
|
|
145
|
+
local value = token
|
|
146
|
+
if CREDFORM.basic then
|
|
147
|
+
value = base64(token .. ":" .. (secret or ""))
|
|
148
|
+
end
|
|
149
|
+
if CREDFORM.prefix == "" then
|
|
150
|
+
return value
|
|
151
|
+
end
|
|
152
|
+
return CREDFORM.prefix .. " " .. value
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
local function assert_credential(header, token, secret)
|
|
157
|
+
assert.are.equal(credential(token, secret), header,
|
|
158
|
+
"expected the " .. CREDHEADER .. " header to carry " .. token)
|
|
137
159
|
end
|
|
138
160
|
|
|
139
161
|
|
|
@@ -342,6 +364,17 @@ describe("secrets", function()
|
|
|
342
364
|
"the options map must stay unwritten")
|
|
343
365
|
end)
|
|
344
366
|
|
|
367
|
+
it("a resolved key is placed as prepare_auth places it, the secret kept", function()
|
|
368
|
+
local w = make_wire()
|
|
369
|
+
local client = secrets_client(w, {
|
|
370
|
+
secret = "PASS01",
|
|
371
|
+
feature = chain({ memory("CHAIN05") }),
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
drive_entity_op(client, w)
|
|
375
|
+
assert_credential(w.api()[1].auth, "CHAIN05", "PASS01")
|
|
376
|
+
end)
|
|
377
|
+
|
|
345
378
|
it("custom provider objects are accepted verbatim", function()
|
|
346
379
|
local asked = {}
|
|
347
380
|
local w = make_wire()
|
|
@@ -822,6 +855,17 @@ describe("secrets", function()
|
|
|
822
855
|
assert.are.equal(2, #w.token())
|
|
823
856
|
end)
|
|
824
857
|
|
|
858
|
+
it("a token bought on a refusal is placed as prepare_auth places it", function()
|
|
859
|
+
local w = make_wire({ apistatus = { 401, 200 } })
|
|
860
|
+
local client = exchange_client(w, nil, { secret = "PASS01" })
|
|
861
|
+
local res = client:direct({ path = "/probe" })
|
|
862
|
+
assert.is_true(res.ok, tostring(res.err))
|
|
863
|
+
|
|
864
|
+
assert.are.equal(2, #w.api(), "expected the refused request and one retry")
|
|
865
|
+
assert_credential(w.api()[1].auth, "ACCESS01", "PASS01")
|
|
866
|
+
assert_credential(w.api()[2].auth, "ACCESS02", "PASS01")
|
|
867
|
+
end)
|
|
868
|
+
|
|
825
869
|
it("a second refusal surfaces rather than spinning", function()
|
|
826
870
|
local w = make_wire({ apistatus = { 401 } })
|
|
827
871
|
local client = exchange_client(w)
|
|
@@ -876,6 +920,8 @@ describe("secrets", function()
|
|
|
876
920
|
local other = assert(socket.bind("127.0.0.1", 0))
|
|
877
921
|
if LOCATION == "OTHER" then
|
|
878
922
|
LOCATION = "http://127.0.0.1:" .. select(2, other:getsockname()) .. "/api/auth/token"
|
|
923
|
+
elseif LOCATION == "ORIGIN" then
|
|
924
|
+
LOCATION = "http://127.0.0.1:" .. select(2, api:getsockname()) .. "/api/moved/token"
|
|
879
925
|
end
|
|
880
926
|
io.stdout:write(select(2, api:getsockname()), "\t", LOCATION, "\n")
|
|
881
927
|
io.stdout:flush()
|
|
@@ -908,50 +954,60 @@ describe("secrets", function()
|
|
|
908
954
|
end
|
|
909
955
|
]]
|
|
910
956
|
|
|
911
|
-
--
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
957
|
+
-- One exchange against the two listeners, the origin answering it with
|
|
958
|
+
-- `status` and `location`: the result, the base, the location as served
|
|
959
|
+
-- and every request the listeners got.
|
|
960
|
+
local function against_origins(status, location, xextra)
|
|
915
961
|
local first = 0
|
|
916
962
|
while arg and arg[first - 1] ~= nil do first = first - 1 end
|
|
917
963
|
local lua = arg and first < 0 and arg[first] or "lua"
|
|
918
964
|
|
|
965
|
+
local script = os.tmpname()
|
|
966
|
+
local f = assert(io.open(script, "w"))
|
|
967
|
+
f:write(string.format("package.path = %q\npackage.cpath = %q\nSTATUS = %d\nLOCATION = %q\n",
|
|
968
|
+
package.path, package.cpath, status, location), origins_server)
|
|
969
|
+
f:close()
|
|
970
|
+
local child = assert(io.popen(string.format("%q %q", lua, script)))
|
|
971
|
+
local port, served = string.match(assert(child:read("*l")), "^(%d+)\t(.*)$")
|
|
972
|
+
local base = "http://127.0.0.1:" .. port .. "/api"
|
|
973
|
+
|
|
974
|
+
local exchange = { active = true, refresh = "REFRESH01" }
|
|
975
|
+
for k, v in pairs(xextra or {}) do exchange[k] = v end
|
|
976
|
+
local client = secrets_client(nil, {
|
|
977
|
+
base = base,
|
|
978
|
+
feature = { secrets = { active = true, name = "refresh_token", exchange = exchange } },
|
|
979
|
+
})
|
|
980
|
+
local res = client:direct({ path = "/thing" })
|
|
981
|
+
|
|
982
|
+
local stop = require("socket").connect("127.0.0.1", tonumber(port))
|
|
983
|
+
if stop then
|
|
984
|
+
stop:send("GET /stop HTTP/1.0\r\n\r\n")
|
|
985
|
+
stop:close()
|
|
986
|
+
end
|
|
987
|
+
local seen = {}
|
|
988
|
+
for line in child:lines() do
|
|
989
|
+
local where, method, path, body = string.match(line, "^(%S+)\t(%S*)\t(%S*)\t(.*)$")
|
|
990
|
+
seen[#seen + 1] = { where = where, method = method, path = path, body = body }
|
|
991
|
+
end
|
|
992
|
+
child:close()
|
|
993
|
+
os.remove(script)
|
|
994
|
+
return res, base, served, seen
|
|
995
|
+
end
|
|
996
|
+
|
|
997
|
+
-- Real listeners and the feature's own transport: a stub follows nothing.
|
|
998
|
+
local has_socket = pcall(require, "socket.http")
|
|
999
|
+
;(has_socket and it or pending)("a redirect answering the exchange is a failure, and nothing follows it",
|
|
1000
|
+
function()
|
|
919
1001
|
local refused, leaked, failures = 0, 0, {}
|
|
920
1002
|
for _, case in ipairs({ { 307, "OTHER" }, { 308, "OTHER" }, { 302, "OTHER" },
|
|
921
1003
|
{ 307, "/api/moved/token" } }) do
|
|
922
|
-
local
|
|
923
|
-
local f = assert(io.open(script, "w"))
|
|
924
|
-
f:write(string.format("package.path = %q\npackage.cpath = %q\nSTATUS = %d\nLOCATION = %q\n",
|
|
925
|
-
package.path, package.cpath, case[1], case[2]), origins_server)
|
|
926
|
-
f:close()
|
|
927
|
-
local child = assert(io.popen(string.format("%q %q", lua, script)))
|
|
928
|
-
local port, location = string.match(assert(child:read("*l")), "^(%d+)\t(.*)$")
|
|
929
|
-
local base = "http://127.0.0.1:" .. port .. "/api"
|
|
930
|
-
|
|
931
|
-
local client = secrets_client(nil, {
|
|
932
|
-
base = base,
|
|
933
|
-
feature = { secrets = {
|
|
934
|
-
active = true,
|
|
935
|
-
name = "refresh_token",
|
|
936
|
-
exchange = { active = true, refresh = "REFRESH01" },
|
|
937
|
-
} },
|
|
938
|
-
})
|
|
939
|
-
local res = client:direct({ path = "/thing" })
|
|
940
|
-
|
|
941
|
-
local stop = require("socket").connect("127.0.0.1", tonumber(port))
|
|
942
|
-
if stop then
|
|
943
|
-
stop:send("GET /stop HTTP/1.0\r\n\r\n")
|
|
944
|
-
stop:close()
|
|
945
|
-
end
|
|
1004
|
+
local res, base, location, seen = against_origins(case[1], case[2])
|
|
946
1005
|
local followed = {}
|
|
947
|
-
for
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
followed[#followed + 1] = where .. " " .. method .. " " .. path .. " " .. body
|
|
1006
|
+
for _, r in ipairs(seen) do
|
|
1007
|
+
if r.where == "other" or r.path ~= "/api/auth/token" then
|
|
1008
|
+
followed[#followed + 1] = r.where .. " " .. r.method .. " " .. r.path .. " " .. r.body
|
|
951
1009
|
end
|
|
952
1010
|
end
|
|
953
|
-
child:close()
|
|
954
|
-
os.remove(script)
|
|
955
1011
|
|
|
956
1012
|
local label = case[1] .. " to " .. location
|
|
957
1013
|
local message = tostring(res and res.err)
|
|
@@ -973,6 +1029,56 @@ describe("secrets", function()
|
|
|
973
1029
|
assert.are.equal(4, refused)
|
|
974
1030
|
end)
|
|
975
1031
|
|
|
1032
|
+
;(has_socket and it or pending)(
|
|
1033
|
+
"with the option, a redirect on the exchange's own origin is followed, and no other",
|
|
1034
|
+
function()
|
|
1035
|
+
local sent = ' {"refresh_token":"REFRESH01"}'
|
|
1036
|
+
local followed, refused, elsewhere, looped, wrong = 0, 0, 0, 0, {}
|
|
1037
|
+
-- Each case: the status, the Location, and the target the exchange is
|
|
1038
|
+
-- asked again at, or false where the redirect is refused. A Location of
|
|
1039
|
+
-- a query alone keeps the path that answered.
|
|
1040
|
+
for _, case in ipairs({ { 307, "/api/moved/token", "/api/moved/token" },
|
|
1041
|
+
{ 308, "ORIGIN", "/api/moved/token" }, { 307, "?step=2", "/api/auth/token?step=2" },
|
|
1042
|
+
{ 307, "OTHER", false }, { 302, "/api/moved/token", false },
|
|
1043
|
+
{ 307, "/api/auth/token", false } }) do
|
|
1044
|
+
local res, base, location, seen = against_origins(case[1], case[2],
|
|
1045
|
+
{ redirect = "same-origin" })
|
|
1046
|
+
local mine, exchanged = {}, 0
|
|
1047
|
+
for _, r in ipairs(seen) do
|
|
1048
|
+
if r.where == "other" then
|
|
1049
|
+
elsewhere = elsewhere + 1
|
|
1050
|
+
elseif r.path == "/api/auth/token" then
|
|
1051
|
+
exchanged = exchanged + 1
|
|
1052
|
+
else
|
|
1053
|
+
mine[#mine + 1] = r.method .. " " .. r.path .. " " .. r.body
|
|
1054
|
+
end
|
|
1055
|
+
end
|
|
1056
|
+
|
|
1057
|
+
local message = tostring(res and res.err)
|
|
1058
|
+
local want = "token exchange failed: " .. case[1] .. " from " .. base .. "/auth/token"
|
|
1059
|
+
if case[3] and res and res.ok == true and #mine == 2
|
|
1060
|
+
and mine[1] == "POST " .. case[3] .. sent then
|
|
1061
|
+
followed = followed + 1
|
|
1062
|
+
elseif not case[3] and #mine == 0 and message:find(want, 1, true) then
|
|
1063
|
+
refused = refused + 1
|
|
1064
|
+
else
|
|
1065
|
+
wrong[#wrong + 1] = case[1] .. " to " .. location .. ": " .. message .. " " ..
|
|
1066
|
+
table.concat(mine, "; ")
|
|
1067
|
+
end
|
|
1068
|
+
if case[2] == "/api/auth/token" then looped = exchanged end
|
|
1069
|
+
end
|
|
1070
|
+
|
|
1071
|
+
print("\nsecrets: exchange opt-in followed " .. followed .. " redirect(s) on its own origin, " ..
|
|
1072
|
+
"refused " .. refused .. ", " .. elsewhere .. " elsewhere")
|
|
1073
|
+
|
|
1074
|
+
assert.are.equal(0, elsewhere, "the exchange reached another origin")
|
|
1075
|
+
assert.are.same({}, wrong)
|
|
1076
|
+
assert.are.equal(3, followed)
|
|
1077
|
+
assert.are.equal(3, refused)
|
|
1078
|
+
-- A redirect to itself stops at the hop limit.
|
|
1079
|
+
assert.are.equal(6, looped)
|
|
1080
|
+
end)
|
|
1081
|
+
|
|
976
1082
|
it("test mode buys nothing", function()
|
|
977
1083
|
-- A LIVE construction (so the feature is installed through extend),
|
|
978
1084
|
-- switched to test mode before the first request: the wrapper runs
|
|
@@ -991,3 +1097,62 @@ describe("secrets", function()
|
|
|
991
1097
|
end)
|
|
992
1098
|
end)
|
|
993
1099
|
end)
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
-- Off by the config where it declares no auth, else by clearing
|
|
1103
|
+
-- `options.auth` after construction, the suppression Lua can express:
|
|
1104
|
+
-- either way the feature places no credential, buys no token and retries
|
|
1105
|
+
-- nothing.
|
|
1106
|
+
describe("secrets with auth off", function()
|
|
1107
|
+
|
|
1108
|
+
it("places no credential and buys no token", function()
|
|
1109
|
+
local declared = nil ~= (require("config_shared")().options or {}).auth
|
|
1110
|
+
local by = declared and "option" or "config"
|
|
1111
|
+
local secrets = { "OFFKEY01", "OFFKEY02", "OFFREFRESH01", "ACCESS01" }
|
|
1112
|
+
local function carries(call)
|
|
1113
|
+
if call.has then return true end
|
|
1114
|
+
for _, secret in ipairs(secrets) do
|
|
1115
|
+
if call.values:find(secret, 1, true) then return true end
|
|
1116
|
+
end
|
|
1117
|
+
return false
|
|
1118
|
+
end
|
|
1119
|
+
local sent, bought = {}, 0
|
|
1120
|
+
|
|
1121
|
+
local refresh = { kind = "memory", values = { REFRESH_TOKEN = "OFFREFRESH01" } }
|
|
1122
|
+
local scenarios = {
|
|
1123
|
+
{ "a key the chain resolves", {}, chain({ memory("OFFKEY01") }), { 200 } },
|
|
1124
|
+
{ "an explicit apikey", { apikey = "OFFKEY02" }, { secrets = { active = true } }, { 200 } },
|
|
1125
|
+
{ "a refusal", {},
|
|
1126
|
+
chain({ refresh }, { name = "refresh_token", exchange = { active = true } }), { 401 } },
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
for _, scenario in ipairs(scenarios) do
|
|
1130
|
+
local what, sdkopts, feature, statuses = table.unpack(scenario)
|
|
1131
|
+
local w = make_wire({ apistatus = statuses })
|
|
1132
|
+
local opts = { feature = feature }
|
|
1133
|
+
for k, v in pairs(sdkopts) do opts[k] = v end
|
|
1134
|
+
local client = secrets_client(w, opts)
|
|
1135
|
+
if declared then
|
|
1136
|
+
client.options.auth = nil
|
|
1137
|
+
end
|
|
1138
|
+
|
|
1139
|
+
client:direct({ path = "/probe" })
|
|
1140
|
+
|
|
1141
|
+
assert.are.equal(1, #w.api(), what .. ": a request was retried with auth off")
|
|
1142
|
+
assert.are.equal(0, #w.token(), what .. ": a token was bought with auth off")
|
|
1143
|
+
assert.is_false(carries(w.api()[1]), what .. ": a credential was sent with auth off")
|
|
1144
|
+
assert.is_nil(secrets_feature_of(client):credential(),
|
|
1145
|
+
what .. ": the feature resolved a credential with auth off")
|
|
1146
|
+
|
|
1147
|
+
for _, call in ipairs(w.api()) do sent[#sent + 1] = call end
|
|
1148
|
+
bought = bought + #w.token()
|
|
1149
|
+
end
|
|
1150
|
+
|
|
1151
|
+
local carried = 0
|
|
1152
|
+
for _, call in ipairs(sent) do
|
|
1153
|
+
if carries(call) then carried = carried + 1 end
|
|
1154
|
+
end
|
|
1155
|
+
print("\nsecrets: auth off by " .. by .. ": " .. #sent .. " request(s), " ..
|
|
1156
|
+
carried .. " credential(s), " .. bought .. " token(s)")
|
|
1157
|
+
end)
|
|
1158
|
+
end)
|
|
@@ -668,6 +668,24 @@ describe("feature", function()
|
|
|
668
668
|
assert.are.equal(2, h.client._cache.bypass)
|
|
669
669
|
end)
|
|
670
670
|
|
|
671
|
+
it("passes a body that declares another type than JSON by, unread", function()
|
|
672
|
+
local sent = {}
|
|
673
|
+
local rec = recording_server(function()
|
|
674
|
+
local res = make_response(200, nil, { ["content-type"] = "audio/wav" })
|
|
675
|
+
sent[#sent + 1] = res
|
|
676
|
+
return res
|
|
677
|
+
end)
|
|
678
|
+
local h = make_client({ features = {
|
|
679
|
+
{ name = "cache" },
|
|
680
|
+
}, server = rec.server })
|
|
681
|
+
local a = h.op({ op = "load", path = "/w/1/audio" })
|
|
682
|
+
local b = h.op({ op = "load", path = "/w/1/audio" })
|
|
683
|
+
assert.are.equal(2, #rec.calls, "the body was stored")
|
|
684
|
+
assert.are.equal(sent[1], a.ctx.response, "the cache handed on a copy it had read")
|
|
685
|
+
assert.are.equal(sent[2], b.ctx.response)
|
|
686
|
+
assert.are.equal(2, h.client._cache.bypass)
|
|
687
|
+
end)
|
|
688
|
+
|
|
671
689
|
it("re-fetches after the ttl", function()
|
|
672
690
|
local clock = make_clock()
|
|
673
691
|
local rec = recording_server()
|
|
@@ -66,7 +66,7 @@ local function make_spec_util(ctx)
|
|
|
66
66
|
if "graphql" == vs.getprop(ctx.point, "kind") then
|
|
67
67
|
-- GraphQL addresses one endpoint: no path parts, no query string, and
|
|
68
68
|
-- the body carries the operation. prepare_body is skipped deliberately
|
|
69
|
-
-- — it only
|
|
69
|
+
-- — it builds only a REST body, whereas every GraphQL op
|
|
70
70
|
-- posts one, including load/list/remove.
|
|
71
71
|
ctx.spec.body = utility.graphql_body(ctx)
|
|
72
72
|
ctx.spec.path = ""
|
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
-- ProjectName SDK utility: prepare_body
|
|
2
2
|
|
|
3
|
+
local vs = require("utility.struct.struct")
|
|
3
4
|
local media = require("utility.media")
|
|
4
5
|
|
|
6
|
+
-- A list, load or remove routed to a method with a body sends the match
|
|
7
|
+
-- fields that body declares, never a path parameter, and never a header,
|
|
8
|
+
-- cookie or query argument the body does not also declare as a field.
|
|
9
|
+
local function match_body(ctx, fields)
|
|
10
|
+
local point = ctx.point
|
|
11
|
+
local routed = {}
|
|
12
|
+
local params = vs.getprop(point, "params")
|
|
13
|
+
if type(params) == "table" then
|
|
14
|
+
for _, name in ipairs(params) do
|
|
15
|
+
routed[name] = true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
for _, kind in ipairs({ "params", "header", "cookie", "query" }) do
|
|
19
|
+
local defs = vs.getpath(point, "args." .. kind)
|
|
20
|
+
if type(defs) == "table" then
|
|
21
|
+
for _, ad in ipairs(defs) do
|
|
22
|
+
local name = vs.getprop(ad, "name")
|
|
23
|
+
if name ~= nil and (kind == "params" or vs.getprop(ad, "field") ~= true) then
|
|
24
|
+
routed[name] = true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
local body = {}
|
|
31
|
+
for _, name in ipairs(fields) do
|
|
32
|
+
local val = vs.getprop(ctx.reqmatch or {}, name)
|
|
33
|
+
if val ~= nil and name ~= "$action" and not routed[name] then
|
|
34
|
+
body[name] = val
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
return body
|
|
38
|
+
end
|
|
39
|
+
|
|
5
40
|
local function prepare_body_util(ctx)
|
|
6
41
|
local op = ctx.op
|
|
7
42
|
|
|
@@ -13,6 +48,11 @@ local function prepare_body_util(ctx)
|
|
|
13
48
|
return body
|
|
14
49
|
end
|
|
15
50
|
|
|
51
|
+
local fields = ctx.point ~= nil and vs.getprop(ctx.point, "fields") or nil
|
|
52
|
+
if type(fields) == "table" and 0 < #fields then
|
|
53
|
+
return match_body(ctx, fields)
|
|
54
|
+
end
|
|
55
|
+
|
|
16
56
|
return nil
|
|
17
57
|
end
|
|
18
58
|
|
|
@@ -36,7 +36,9 @@ local function prepare_query_util(ctx)
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
-- A header or cookie parameter travels in the headers, which prepare_headers
|
|
39
|
-
-- fills,
|
|
39
|
+
-- fills, and a field the point's body declares travels in the body, which
|
|
40
|
+
-- prepare_body fills, unless a query parameter shares its name: then both
|
|
41
|
+
-- are sent.
|
|
40
42
|
local declared = {}
|
|
41
43
|
local ql = vs.getpath(point, "args.query")
|
|
42
44
|
if type(ql) == "table" then
|
|
@@ -59,6 +61,14 @@ local function prepare_query_util(ctx)
|
|
|
59
61
|
end
|
|
60
62
|
end
|
|
61
63
|
end
|
|
64
|
+
local fields = vs.getprop(point, "fields")
|
|
65
|
+
if type(fields) == "table" then
|
|
66
|
+
for _, name in ipairs(fields) do
|
|
67
|
+
if type(name) == "string" and not declared[name] then
|
|
68
|
+
table.insert(params, name)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
62
72
|
end
|
|
63
73
|
|
|
64
74
|
-- A query parameter travels under the name the definition gives it, its
|