@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
|
@@ -47,11 +47,14 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// A header or cookie parameter travels in the headers, which prepare_headers
|
|
50
|
-
// fills,
|
|
50
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
51
|
+
// prepare_body fills, unless a query parameter shares its name: then both
|
|
52
|
+
// are sent.
|
|
51
53
|
let aheader = getp(&getp(&point, "args"), "header");
|
|
52
54
|
let acookie = getp(&getp(&point, "args"), "cookie");
|
|
53
55
|
let declared = getp(&getp(&point, "args"), "query");
|
|
54
|
-
let
|
|
56
|
+
let fields = getp(&point, "fields");
|
|
57
|
+
let elsewhere = |key: &str| -> bool {
|
|
55
58
|
if let Value::List(ql) = &declared {
|
|
56
59
|
for qd in ql.borrow().iter() {
|
|
57
60
|
if let Value::Str(s) = getp(qd, "name") {
|
|
@@ -61,6 +64,11 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
if let Value::List(fl) = &fields {
|
|
68
|
+
if fl.borrow().iter().any(|f| f.as_str() == Some(key)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
for located in [&aheader, &acookie] {
|
|
65
73
|
if let Value::List(hl) = located {
|
|
66
74
|
for hd in hl.borrow().iter() {
|
|
@@ -100,7 +108,7 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
100
108
|
.collect();
|
|
101
109
|
for (key, val) in entries {
|
|
102
110
|
if !val.is_noval() && !val.is_null() && "$action" != key && !contains(&key) && !in_args(&key)
|
|
103
|
-
&& !
|
|
111
|
+
&& !elsewhere(&key)
|
|
104
112
|
{
|
|
105
113
|
setp(&out, &wire_name(&key), val);
|
|
106
114
|
}
|
|
@@ -109,7 +117,7 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
109
117
|
|
|
110
118
|
// A create or update passes its query arguments in its data.
|
|
111
119
|
for (name, wire, val) in call_args(ctx, "query") {
|
|
112
|
-
if !val.is_noval() && !val.is_null() && !contains(&name) && !in_args(&name) && !
|
|
120
|
+
if !val.is_noval() && !val.is_null() && !contains(&name) && !in_args(&name) && !elsewhere(&name) {
|
|
113
121
|
setp(&out, &wire, val);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -15,9 +15,4 @@ class Control {
|
|
|
15
15
|
var actor: String = ""
|
|
16
16
|
|
|
17
17
|
var paging: JMap[String, Object] = null
|
|
18
|
-
|
|
19
|
-
// Outbound streaming marker: the entity `stream` method sets this to the
|
|
20
|
-
// caller-supplied streamable payload so the request builder / transport can
|
|
21
|
-
// stream it as the request body.
|
|
22
|
-
var streamOut: Object = null
|
|
23
18
|
}
|
|
@@ -18,6 +18,8 @@ class Point(pointmap: JMap[String, Object]) {
|
|
|
18
18
|
var relations: JList[Object] = null
|
|
19
19
|
var alias: JMap[String, Object] = new LinkedHashMap[String, Object]()
|
|
20
20
|
var transform: JMap[String, Object] = new LinkedHashMap[String, Object]()
|
|
21
|
+
// The fields a list, load or remove sends in a request body.
|
|
22
|
+
var fields: JList[Object] = null
|
|
21
23
|
|
|
22
24
|
locally {
|
|
23
25
|
Struct.getprop(pointmap, "args") match { case m: JMap[_, _] => args = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
@@ -41,5 +43,6 @@ class Point(pointmap: JMap[String, Object]) {
|
|
|
41
43
|
Struct.getprop(pointmap, "relations") match { case l: JList[_] => relations = l.asInstanceOf[JList[Object]]; case _ => }
|
|
42
44
|
Struct.getprop(pointmap, "alias") match { case m: JMap[_, _] => alias = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
43
45
|
Struct.getprop(pointmap, "transform") match { case m: JMap[_, _] => transform = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
46
|
+
Struct.getprop(pointmap, "fields") match { case l: JList[_] => fields = l.asInstanceOf[JList[Object]]; case _ => }
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -3,6 +3,7 @@ package SCALAPACKAGE.feature
|
|
|
3
3
|
import java.util.{ArrayList, LinkedHashMap, List => JList, Map => JMap}
|
|
4
4
|
import java.util.function.Supplier
|
|
5
5
|
import SCALAPACKAGE.core.{Context, FetcherFn, SdkClient}
|
|
6
|
+
import SCALAPACKAGE.utility.Media
|
|
6
7
|
|
|
7
8
|
// Response caching for safe (read) requests. Wraps the active transport and
|
|
8
9
|
// serves a fresh cached snapshot instead of hitting the network when the
|
|
@@ -97,6 +98,12 @@ class CacheFeature extends BaseFeature("cache", "0.0.1", true) {
|
|
|
97
98
|
throw err
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// A body that declares another type than JSON passes by, unread.
|
|
102
|
+
if (storable(res) && !json(res)) {
|
|
103
|
+
this.bypass += 1
|
|
104
|
+
return res
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
if (storable(res)) {
|
|
101
108
|
val snapshot = this.snapshot(res)
|
|
102
109
|
val ttl = FeatureOptions.foptInt(this.options, "ttl", 5000)
|
|
@@ -121,6 +128,11 @@ class CacheFeature extends BaseFeature("cache", "0.0.1", true) {
|
|
|
121
128
|
java.lang.Boolean.TRUE != res.asInstanceOf[JMap[String, Object]].get("unreadable")
|
|
122
129
|
}
|
|
123
130
|
|
|
131
|
+
private def json(res: Object): Boolean = {
|
|
132
|
+
val ctype = FeatureOptions.fresHeader(res, "content-type")
|
|
133
|
+
"" == ctype || Media.isJsonMedia(ctype)
|
|
134
|
+
}
|
|
135
|
+
|
|
124
136
|
private def snapshot(res: Object): CacheSnapshot = {
|
|
125
137
|
val rm: JMap[String, Object] = res match {
|
|
126
138
|
case m: JMap[_, _] => m.asInstanceOf[JMap[String, Object]]
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package SCALAPACKAGE.feature
|
|
2
2
|
|
|
3
|
-
import java.
|
|
3
|
+
import java.net.URI
|
|
4
|
+
import java.nio.charset.StandardCharsets
|
|
5
|
+
import java.util.{Base64, LinkedHashMap, Locale, List => JList, Map => JMap}
|
|
4
6
|
import java.util.function.{BiFunction, Supplier}
|
|
5
7
|
|
|
6
8
|
import scala.collection.immutable.ListMap
|
|
@@ -78,6 +80,11 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
78
80
|
// writes it - see the class note.
|
|
79
81
|
private var liveopts: JMap[String, Object] = null
|
|
80
82
|
|
|
83
|
+
// What prepareAuth was generated from: the config declares auth only
|
|
84
|
+
// where it places a credential, and Basic only where it composes one.
|
|
85
|
+
private var declared: Boolean = false
|
|
86
|
+
private var basic: Boolean = false
|
|
87
|
+
|
|
81
88
|
private var secretname: String = "apikey"
|
|
82
89
|
private var docache: Boolean = true
|
|
83
90
|
private var sek: Sekreto = null
|
|
@@ -97,6 +104,7 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
97
104
|
private var xresponse: String = "access_token"
|
|
98
105
|
private var xstatuses: List[Int] = List(401)
|
|
99
106
|
private var xretries: Int = 1
|
|
107
|
+
private var xredirect: String = "refuse"
|
|
100
108
|
|
|
101
109
|
// The refresh credential the chain resolved, for every later purchase.
|
|
102
110
|
private var refresh: String = ""
|
|
@@ -136,6 +144,18 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
136
144
|
this.liveopts = ctx.options
|
|
137
145
|
this.active = FeatureOptions.foptBool(options, "active", false)
|
|
138
146
|
|
|
147
|
+
val configopts = if (ctx.config == null) null else ctx.config.get("options")
|
|
148
|
+
val authdecl = configopts match {
|
|
149
|
+
case m: JMap[_, _] => m.get("auth")
|
|
150
|
+
case _ => null
|
|
151
|
+
}
|
|
152
|
+
authdecl match {
|
|
153
|
+
case m: JMap[_, _] =>
|
|
154
|
+
this.declared = true
|
|
155
|
+
this.basic = java.lang.Boolean.TRUE == m.get("basic")
|
|
156
|
+
case _ =>
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
if (!this.active) return
|
|
140
160
|
|
|
141
161
|
this.secretname = FeatureOptions.foptStr(options, "name", "apikey")
|
|
@@ -149,6 +169,9 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
149
169
|
this.xrequest = FeatureOptions.foptStr(xopts, "request", "refresh_token")
|
|
150
170
|
this.xresponse = FeatureOptions.foptStr(xopts, "response", "access_token")
|
|
151
171
|
this.xretries = FeatureOptions.foptInt(xopts, "retries", 1)
|
|
172
|
+
this.xredirect =
|
|
173
|
+
if ("same-origin" == FeatureOptions.foptStr(xopts, "redirect", "refuse")) "same-origin"
|
|
174
|
+
else "refuse"
|
|
152
175
|
|
|
153
176
|
val statuses = ListBuffer.empty[Int]
|
|
154
177
|
val slist = FeatureOptions.foptList(xopts, "statuses")
|
|
@@ -293,11 +316,16 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
293
316
|
}
|
|
294
317
|
}
|
|
295
318
|
|
|
319
|
+
// prepareAuth's decision: auth the config declares, not suppressed by
|
|
320
|
+
// `auth: null`.
|
|
321
|
+
private def authon(): Boolean =
|
|
322
|
+
this.declared && this.liveopts != null && this.liveopts.get("auth") != null
|
|
323
|
+
|
|
296
324
|
// Resolve once, reporting whether a credential came out of it. That
|
|
297
325
|
// boolean is the whole of what resolve() needs to tell a cacheable HIT
|
|
298
326
|
// from a miss it must not keep.
|
|
299
327
|
private def resolveonce(): Boolean = {
|
|
300
|
-
if (this.sek == null) return false
|
|
328
|
+
if (this.sek == null || !authon()) return false
|
|
301
329
|
|
|
302
330
|
// tryget returns None for a MISS and RAISES for an ERROR. That is the
|
|
303
331
|
// whole miss-vs-error rule, and it is sekreto's, not this feature's.
|
|
@@ -327,15 +355,6 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
327
355
|
// the same path expiry takes anyway.
|
|
328
356
|
if ("" != this.cred) return true
|
|
329
357
|
|
|
330
|
-
// `auth: null` is the documented way to send NO credential, and a
|
|
331
|
-
// purchase is a credential-bearing call: the refresh token goes to the
|
|
332
|
-
// token endpoint in the request body. withrefresh honours suppression
|
|
333
|
-
// for the RETRY, but it runs after this - by then the refresh token has
|
|
334
|
-
// already left the process, and no later check can call it back. The
|
|
335
|
-
// suppression has to be honoured here, before the first purchase, or it
|
|
336
|
-
// only ever half-held.
|
|
337
|
-
if (this.liveopts == null || this.liveopts.get("auth") == null) return false
|
|
338
|
-
|
|
339
358
|
buyonce()
|
|
340
359
|
|
|
341
360
|
true
|
|
@@ -355,12 +374,9 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
355
374
|
fetchdef: JMap[String, Object],
|
|
356
375
|
inner: FetcherFn,
|
|
357
376
|
): Object = {
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
|
|
361
|
-
// cannot be fixed by buying one - retrying would transmit exactly the
|
|
362
|
-
// credential the caller suppressed.
|
|
363
|
-
if (this.liveopts == null || this.liveopts.get("auth") == null) {
|
|
377
|
+
// A refusal of an unauthenticated request is not an expired token, and
|
|
378
|
+
// retrying would transmit the credential that auth off withholds.
|
|
379
|
+
if (!authon()) {
|
|
364
380
|
return inner(ctx, url, fetchdef)
|
|
365
381
|
}
|
|
366
382
|
|
|
@@ -423,7 +439,7 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
423
439
|
// Reached defensively on the exchange path - withrefresh does not retry
|
|
424
440
|
// at all when auth is null - but this is the function that writes the
|
|
425
441
|
// credential, so it is where the rule has to hold.
|
|
426
|
-
val rawauth = if (
|
|
442
|
+
val rawauth = if (!authon()) null else this.liveopts.get("auth")
|
|
427
443
|
rawauth match {
|
|
428
444
|
case authmap: JMap[_, _] =>
|
|
429
445
|
// The header prepareAuth wrote: auth.name, lower-cased.
|
|
@@ -431,16 +447,29 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
431
447
|
case s: String if s.nonEmpty => s.toLowerCase(java.util.Locale.ROOT)
|
|
432
448
|
case _ => "authorization"
|
|
433
449
|
}
|
|
450
|
+
val value =
|
|
451
|
+
if (this.basic && java.lang.Boolean.TRUE == authmap.get("basic")) pair(token) else token
|
|
434
452
|
val prefix = authmap.asInstanceOf[JMap[String, Object]].get("prefix") match {
|
|
435
453
|
case s: String => s
|
|
436
454
|
case _ => ""
|
|
437
455
|
}
|
|
438
|
-
if ("" == prefix) headers.put(name,
|
|
439
|
-
else headers.put(name, prefix + " " +
|
|
456
|
+
if ("" == prefix) headers.put(name, value)
|
|
457
|
+
else headers.put(name, prefix + " " + value)
|
|
440
458
|
case _ => headers.remove("authorization")
|
|
441
459
|
}
|
|
442
460
|
}
|
|
443
461
|
|
|
462
|
+
// Under Basic the token is the key half, as apikey is: prepareAuth's pair.
|
|
463
|
+
private def pair(token: String): String = {
|
|
464
|
+
val secret = this.liveopts.get("secret") match {
|
|
465
|
+
case s: String => s
|
|
466
|
+
case _ => ""
|
|
467
|
+
}
|
|
468
|
+
val pair = Base64.getEncoder.encodeToString((token + ":" + secret).getBytes(StandardCharsets.UTF_8))
|
|
469
|
+
register(pair)
|
|
470
|
+
pair
|
|
471
|
+
}
|
|
472
|
+
|
|
444
473
|
// ---- the access-token exchange -----------------------------------------
|
|
445
474
|
|
|
446
475
|
// Buy an access token with the refresh token, and publish it. ALWAYS
|
|
@@ -486,10 +515,21 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
486
515
|
fetchdef.put("method", this.xmethod)
|
|
487
516
|
fetchdef.put("headers", headers)
|
|
488
517
|
fetchdef.put("body", Struct.jsonify(bodymap, flags))
|
|
489
|
-
// Never followed: a redirect would carry the refresh token on.
|
|
518
|
+
// Never followed by the client: a redirect would carry the refresh token on.
|
|
490
519
|
fetchdef.put("redirect", "manual")
|
|
491
520
|
|
|
492
|
-
|
|
521
|
+
var res = exchangefetch(url, fetchdef)
|
|
522
|
+
|
|
523
|
+
// By option alone, and only while the exchange stays on its own origin.
|
|
524
|
+
var at = url
|
|
525
|
+
var hops = 0
|
|
526
|
+
var next = if ("same-origin" == this.xredirect) moved(url, at, res) else null
|
|
527
|
+
while (next != null && hops < SecretsFeature.REDIRECT_MAX) {
|
|
528
|
+
at = next
|
|
529
|
+
res = exchangefetch(at, fetchdef)
|
|
530
|
+
hops += 1
|
|
531
|
+
next = moved(url, at, res)
|
|
532
|
+
}
|
|
493
533
|
if (res == null) {
|
|
494
534
|
throw new SekretoError("secrets: token exchange failed: no response from " + url)
|
|
495
535
|
}
|
|
@@ -557,6 +597,28 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
557
597
|
}
|
|
558
598
|
}
|
|
559
599
|
|
|
600
|
+
// Where a 307 or 308 points, when that is on the exchange's own origin. Any
|
|
601
|
+
// other redirect would drop the body or leave the origin.
|
|
602
|
+
private def moved(url: String, at: String, res: JMap[String, Object]): String = {
|
|
603
|
+
val status = FeatureOptions.fresStatus(res)
|
|
604
|
+
if (307 != status && 308 != status) return null
|
|
605
|
+
val location = FeatureOptions.fresHeader(res, "location")
|
|
606
|
+
if ("" == location) return null
|
|
607
|
+
try {
|
|
608
|
+
val next = Fetcher.resolveLocation(URI.create(at), location)
|
|
609
|
+
val origin = originOf(next)
|
|
610
|
+
if (origin != null && origin == originOf(URI.create(url))) next.toString else null
|
|
611
|
+
}
|
|
612
|
+
catch { case _: RuntimeException => null }
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
private def originOf(uri: URI): String = {
|
|
616
|
+
if (uri.getScheme == null || uri.getHost == null) return null
|
|
617
|
+
val scheme = uri.getScheme.toLowerCase(Locale.ROOT)
|
|
618
|
+
val port = if (uri.getPort < 0) (if ("https" == scheme) 443 else 80) else uri.getPort
|
|
619
|
+
scheme + "://" + uri.getHost.toLowerCase(Locale.ROOT) + ":" + port
|
|
620
|
+
}
|
|
621
|
+
|
|
560
622
|
// ---- support ------------------------------------------------------------
|
|
561
623
|
|
|
562
624
|
private def optstr(map: JMap[String, Object], key: String): String = {
|
|
@@ -597,3 +659,7 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
|
|
|
597
659
|
case other => VStr(String.valueOf(other))
|
|
598
660
|
}
|
|
599
661
|
}
|
|
662
|
+
|
|
663
|
+
object SecretsFeature {
|
|
664
|
+
private val REDIRECT_MAX = 5
|
|
665
|
+
}
|
|
@@ -406,6 +406,28 @@ object SdkTestMain {
|
|
|
406
406
|
{ val rec = new FhRecorder()
|
|
407
407
|
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(new CacheFeature(), om("active" -> B(false))))
|
|
408
408
|
h.op(fhOp("load").withPath("/x")); h.op(fhOp("load").withPath("/x")); eqI("cache.inactive", 2, rec.calls.size()) }
|
|
409
|
+
// A body that declares another type than JSON passes by, unread.
|
|
410
|
+
{ val sent = new java.util.ArrayList[JMap[String, Object]]()
|
|
411
|
+
val rec = new FhRecorder()
|
|
412
|
+
rec.reply = (n, fd) => {
|
|
413
|
+
val res = fhResponse(200, null, om("content-type" -> "audio/wav"))
|
|
414
|
+
res.put("body", "RIFF".getBytes)
|
|
415
|
+
sent.add(res)
|
|
416
|
+
res
|
|
417
|
+
}
|
|
418
|
+
val f = new CacheFeature()
|
|
419
|
+
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(f, om("ttl" -> I(10000))))
|
|
420
|
+
val a = h.op(fhOp("load").withPath("/w/1/audio")); val b = h.op(fhOp("load").withPath("/w/1/audio"))
|
|
421
|
+
eqI("cache.notJson.calls", 2, rec.calls.size())
|
|
422
|
+
check("cache.notJson.first", a.ctx.response != null &&
|
|
423
|
+
(sent.get(0).get("body") eq a.ctx.response.body) &&
|
|
424
|
+
(sent.get(0).get("headers") eq a.ctx.response.headers),
|
|
425
|
+
"the cache handed on a copy it had read")
|
|
426
|
+
check("cache.notJson.second", b.ctx.response != null &&
|
|
427
|
+
(sent.get(1).get("body") eq b.ctx.response.body) &&
|
|
428
|
+
(sent.get(1).get("headers") eq b.ctx.response.headers),
|
|
429
|
+
"the cache handed on a copy it had read")
|
|
430
|
+
eqI("cache.notJson.bypass", 2, f.bypass) }
|
|
409
431
|
}
|
|
410
432
|
|
|
411
433
|
private def testIdempotency(): Unit = {
|
|
@@ -769,6 +791,44 @@ object SdkTestMain {
|
|
|
769
791
|
finally server.stop(0)
|
|
770
792
|
}
|
|
771
793
|
|
|
794
|
+
// A Location of a query alone keeps the path that answered.
|
|
795
|
+
private def testRedirectToAQuery(): Unit = {
|
|
796
|
+
val seen = java.util.Collections.synchronizedList(new ArrayList[String]())
|
|
797
|
+
val server = com.sun.net.httpserver.HttpServer.create(new java.net.InetSocketAddress("127.0.0.1", 0), 0)
|
|
798
|
+
server.createContext("/", (exchange: com.sun.net.httpserver.HttpExchange) => {
|
|
799
|
+
val query = exchange.getRequestURI.getRawQuery
|
|
800
|
+
seen.add(exchange.getRequestURI.getRawPath + (if (query == null) "" else "?" + query))
|
|
801
|
+
if (query == null) {
|
|
802
|
+
exchange.getResponseHeaders.set("Location", "?step=2")
|
|
803
|
+
exchange.sendResponseHeaders(302, -1L)
|
|
804
|
+
} else {
|
|
805
|
+
val body = "{\"id\":\"q1\"}".getBytes("UTF-8")
|
|
806
|
+
exchange.getResponseHeaders.set("Content-Type", "application/json")
|
|
807
|
+
exchange.sendResponseHeaders(200, body.length.toLong)
|
|
808
|
+
exchange.getResponseBody.write(body)
|
|
809
|
+
}
|
|
810
|
+
exchange.close()
|
|
811
|
+
})
|
|
812
|
+
server.start()
|
|
813
|
+
val base = "http://127.0.0.1:" + server.getAddress.getPort
|
|
814
|
+
try {
|
|
815
|
+
val opts = new LinkedHashMap[String, Object]()
|
|
816
|
+
opts.put("base", base)
|
|
817
|
+
val client = new ProjectNameSDK(opts)
|
|
818
|
+
val utility = client.getUtility()
|
|
819
|
+
val cm = new LinkedHashMap[String, Object]()
|
|
820
|
+
cm.put("opname", "load")
|
|
821
|
+
val ctx = utility.makeContext(cm, client.getRootCtx())
|
|
822
|
+
val fetchdef = new LinkedHashMap[String, Object]()
|
|
823
|
+
fetchdef.put("method", "GET")
|
|
824
|
+
fetchdef.put("headers", new LinkedHashMap[String, Object]())
|
|
825
|
+
val res = utility.fetcher(ctx, base + "/redirect/q1", fetchdef).asInstanceOf[JMap[String, Object]]
|
|
826
|
+
eq("redirect.query.status", Integer.valueOf(200), res.get("status"))
|
|
827
|
+
eq("redirect.query.hops", "[/redirect/q1, /redirect/q1?step=2]", seen.toString)
|
|
828
|
+
}
|
|
829
|
+
finally server.stop(0)
|
|
830
|
+
}
|
|
831
|
+
|
|
772
832
|
private val REDIRECT_SECRET = "REDIRECT-SECRET-q7w3e9r1"
|
|
773
833
|
private val REDIRECT_CREDENTIALS =
|
|
774
834
|
Seq("authorization", "cookie", "x-api-key", "private-token", "x-acme-auth")
|
|
@@ -993,7 +1053,7 @@ object SdkTestMain {
|
|
|
993
1053
|
"composition" -> testComposition, "featureAdd" -> testFeatureAdd,
|
|
994
1054
|
"featureOrder" -> testFeatureOrder, "entityCrud" -> testEntityCrud,
|
|
995
1055
|
"entityStream" -> testEntityStream, "getOnlyGuard" -> testGetOnlyGuard,
|
|
996
|
-
"redirect" -> testRedirect, "redirectToAnotherOrigin" -> testRedirectToAnotherOrigin,
|
|
1056
|
+
"redirect" -> testRedirect, "redirectToAQuery" -> testRedirectToAQuery, "redirectToAnotherOrigin" -> testRedirectToAnotherOrigin,
|
|
997
1057
|
"redirectOnTheSameOrigin" -> testRedirectOnTheSameOrigin,
|
|
998
1058
|
"redirectBody" -> testRedirectBody, "redirectMethods" -> testRedirectMethods,
|
|
999
1059
|
"redirectLimit" -> testRedirectLimit,
|