@voxgig/sdkgen 4.48.1 → 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/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/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +8 -1
- 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/csharp/core/Control.cs +0 -5
- 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/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/test/feature/secrets/secrets_test.exs +178 -19
- package/project/.sdk/tm/elixir/test/feature_test.exs +20 -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/java/core/Control.java +0 -5
- 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/Media.java +2 -2
- 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/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/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/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/ocaml/feature/secrets_feature.ml +100 -14
- package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
- 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/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/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/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/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/scala/core/Control.scala +0 -5
- 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/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- 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/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/feature/cache/CacheFeature.ts +13 -0
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
- 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/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
|
@@ -47,6 +47,7 @@ struct SecretsExchange {
|
|
|
47
47
|
response: String,
|
|
48
48
|
statuses: Vec<i64>,
|
|
49
49
|
retries: i64,
|
|
50
|
+
redirect: String,
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/// Everything the transport closure needs, behind one RefCell.
|
|
@@ -66,6 +67,11 @@ pub struct SecretsState {
|
|
|
66
67
|
options: Value,
|
|
67
68
|
mode: String,
|
|
68
69
|
|
|
70
|
+
/// What prepare_auth was generated from: the config declares auth only
|
|
71
|
+
/// where it places a credential, and Basic only where it composes one.
|
|
72
|
+
declared: bool,
|
|
73
|
+
basic: bool,
|
|
74
|
+
|
|
69
75
|
cred: String,
|
|
70
76
|
refresh: String,
|
|
71
77
|
|
|
@@ -90,6 +96,8 @@ impl SecretsState {
|
|
|
90
96
|
exchange: None,
|
|
91
97
|
options: Value::Noval,
|
|
92
98
|
mode: "live".to_string(),
|
|
99
|
+
declared: false,
|
|
100
|
+
basic: false,
|
|
93
101
|
cred: String::new(),
|
|
94
102
|
refresh: String::new(),
|
|
95
103
|
resolved: false,
|
|
@@ -217,6 +225,12 @@ impl Feature for SecretsFeature {
|
|
|
217
225
|
.map(|c| c.mode.borrow().clone())
|
|
218
226
|
.unwrap_or_else(|| "live".to_string());
|
|
219
227
|
state.options = ctx.options.borrow().clone();
|
|
228
|
+
|
|
229
|
+
let config = ctx.config.borrow().clone();
|
|
230
|
+
let declared = getpath(&["options", "auth"], &config);
|
|
231
|
+
state.declared = matches!(declared, Value::Map(_));
|
|
232
|
+
state.basic = matches!(getp(&declared, "basic"), Value::Bool(true));
|
|
233
|
+
|
|
220
234
|
state.secretname = fopt_str(options, "name", "apikey");
|
|
221
235
|
state.cache = fopt_bool(options, "cache", true);
|
|
222
236
|
|
|
@@ -238,6 +252,11 @@ impl Feature for SecretsFeature {
|
|
|
238
252
|
response: fopt_str(&xopts, "response", "access_token"),
|
|
239
253
|
statuses,
|
|
240
254
|
retries: fopt_int(&xopts, "retries", 1),
|
|
255
|
+
redirect: if "same-origin" == fopt_str(&xopts, "redirect", "refuse") {
|
|
256
|
+
"same-origin".to_string()
|
|
257
|
+
} else {
|
|
258
|
+
"refuse".to_string()
|
|
259
|
+
},
|
|
241
260
|
});
|
|
242
261
|
}
|
|
243
262
|
|
|
@@ -426,7 +445,7 @@ fn resolve(state: &Rc<RefCell<SecretsState>>) -> Result<(), ProjectNameError> {
|
|
|
426
445
|
fn resolve_once(state: &Rc<RefCell<SecretsState>>) -> Result<bool, ProjectNameError> {
|
|
427
446
|
let name = {
|
|
428
447
|
let s = state.borrow();
|
|
429
|
-
if s.sek.is_none() {
|
|
448
|
+
if s.sek.is_none() || !authon(&s) {
|
|
430
449
|
return Ok(false);
|
|
431
450
|
}
|
|
432
451
|
s.secretname.clone()
|
|
@@ -477,10 +496,6 @@ fn resolve_once(state: &Rc<RefCell<SecretsState>>) -> Result<bool, ProjectNameEr
|
|
|
477
496
|
// buys another, which is the same path expiry takes anyway.
|
|
478
497
|
return Ok(true);
|
|
479
498
|
}
|
|
480
|
-
|
|
481
|
-
if !authactive(&s.options) {
|
|
482
|
-
return Ok(false);
|
|
483
|
-
}
|
|
484
499
|
}
|
|
485
500
|
|
|
486
501
|
buy(state).map(|_| true)
|
|
@@ -522,7 +537,7 @@ fn with_refresh(
|
|
|
522
537
|
let (suppressed, max) = {
|
|
523
538
|
let s = state.borrow();
|
|
524
539
|
(
|
|
525
|
-
!
|
|
540
|
+
!authon(&s),
|
|
526
541
|
s.exchange.as_ref().map(|x| x.retries).unwrap_or(0),
|
|
527
542
|
)
|
|
528
543
|
};
|
|
@@ -599,13 +614,22 @@ fn authactive(options: &Value) -> bool {
|
|
|
599
614
|
}
|
|
600
615
|
}
|
|
601
616
|
|
|
617
|
+
// prepare_auth's decision: auth the config declares, not suppressed by
|
|
618
|
+
// `auth: null`.
|
|
619
|
+
fn authon(s: &SecretsState) -> bool {
|
|
620
|
+
s.declared && authactive(&s.options)
|
|
621
|
+
}
|
|
622
|
+
|
|
602
623
|
fn reauth(state: &Rc<RefCell<SecretsState>>, fetchdef: &Value, token: &str) {
|
|
603
624
|
let headers = getp(fetchdef, "headers");
|
|
604
625
|
if !matches!(headers, Value::Map(_)) {
|
|
605
626
|
return;
|
|
606
627
|
}
|
|
607
628
|
|
|
608
|
-
let options =
|
|
629
|
+
let (options, on, basic) = {
|
|
630
|
+
let s = state.borrow();
|
|
631
|
+
(s.options.clone(), authon(&s), s.basic)
|
|
632
|
+
};
|
|
609
633
|
|
|
610
634
|
let name = match getpath(&["auth", "name"], &options) {
|
|
611
635
|
Value::Str(s) if !s.is_empty() => s.to_ascii_lowercase(),
|
|
@@ -613,14 +637,17 @@ fn reauth(state: &Rc<RefCell<SecretsState>>, fetchdef: &Value, token: &str) {
|
|
|
613
637
|
};
|
|
614
638
|
|
|
615
639
|
// Suppressed auth means NO header, the same answer prepare_auth gives.
|
|
616
|
-
|
|
617
|
-
// is suppressed - but this is the function that writes the credential,
|
|
618
|
-
// so it is where the rule has to hold.
|
|
619
|
-
if !authactive(&options) {
|
|
640
|
+
if !on {
|
|
620
641
|
vs::del_prop(headers, &Value::str(name.as_str()));
|
|
621
642
|
return;
|
|
622
643
|
}
|
|
623
644
|
|
|
645
|
+
let value = if basic && matches!(getpath(&["auth", "basic"], &options), Value::Bool(true)) {
|
|
646
|
+
pair(&options, token)
|
|
647
|
+
} else {
|
|
648
|
+
token.to_string()
|
|
649
|
+
};
|
|
650
|
+
|
|
624
651
|
let prefix = match getpath(&["auth", "prefix"], &options) {
|
|
625
652
|
Value::Str(s) => s,
|
|
626
653
|
_ => String::new(),
|
|
@@ -628,12 +655,23 @@ fn reauth(state: &Rc<RefCell<SecretsState>>, fetchdef: &Value, token: &str) {
|
|
|
628
655
|
|
|
629
656
|
// Empty prefix (a raw apiKey credential) must not add a leading space.
|
|
630
657
|
if prefix.is_empty() {
|
|
631
|
-
setp(&headers, &name, Value::str(
|
|
658
|
+
setp(&headers, &name, Value::str(value));
|
|
632
659
|
} else {
|
|
633
|
-
setp(&headers, &name, Value::str(format!("{} {}", prefix,
|
|
660
|
+
setp(&headers, &name, Value::str(format!("{} {}", prefix, value)));
|
|
634
661
|
}
|
|
635
662
|
}
|
|
636
663
|
|
|
664
|
+
// Under Basic the token is the key half, as apikey is: prepare_auth's pair.
|
|
665
|
+
fn pair(options: &Value, token: &str) -> String {
|
|
666
|
+
let secret = match getp(options, "secret") {
|
|
667
|
+
Value::Str(s) => s,
|
|
668
|
+
_ => String::new(),
|
|
669
|
+
};
|
|
670
|
+
let pair = crate::utility::clean::base64_encode(format!("{}:{}", token, secret).as_bytes());
|
|
671
|
+
register(options, &pair);
|
|
672
|
+
pair
|
|
673
|
+
}
|
|
674
|
+
|
|
637
675
|
|
|
638
676
|
fn buy(state: &Rc<RefCell<SecretsState>>) -> Result<String, ProjectNameError> {
|
|
639
677
|
let (testmode, response) = {
|
|
@@ -720,19 +758,32 @@ fn buy_once(state: &Rc<RefCell<SecretsState>>) -> Result<String, ProjectNameErro
|
|
|
720
758
|
|
|
721
759
|
let sys_fetch = getpath(&["system", "fetch"], &options);
|
|
722
760
|
|
|
723
|
-
let
|
|
724
|
-
let
|
|
725
|
-
&sys_fetch,
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
761
|
+
let fetch = |at: &str| -> Result<Value, ProjectNameError> {
|
|
762
|
+
if let Value::Func(_) = sys_fetch {
|
|
763
|
+
let out = call_vfn(&sys_fetch, &ja(vec![Value::str(at), fetchdef.clone()]));
|
|
764
|
+
if let Some(msg) = get_str(&out, "__err__") {
|
|
765
|
+
return Err(fail(&msg));
|
|
766
|
+
}
|
|
767
|
+
Ok(out)
|
|
768
|
+
} else {
|
|
769
|
+
raw_exchange_fetch(at, &fetchdef)
|
|
730
770
|
}
|
|
731
|
-
out
|
|
732
|
-
} else {
|
|
733
|
-
raw_exchange_fetch(&url, &fetchdef)?
|
|
734
771
|
};
|
|
735
772
|
|
|
773
|
+
let mut res = fetch(&url)?;
|
|
774
|
+
|
|
775
|
+
// By option alone, and only while the exchange stays on its own origin.
|
|
776
|
+
let mut at = url.clone();
|
|
777
|
+
let mut hops = 0;
|
|
778
|
+
while "same-origin" == x.redirect && hops < REDIRECT_MAX {
|
|
779
|
+
match moved(&url, &at, &res) {
|
|
780
|
+
Some(next) => at = next,
|
|
781
|
+
None => break,
|
|
782
|
+
}
|
|
783
|
+
res = fetch(&at)?;
|
|
784
|
+
hops += 1;
|
|
785
|
+
}
|
|
786
|
+
|
|
736
787
|
let status = to_int(&getp(&res, "status"));
|
|
737
788
|
if !(200..300).contains(&status) {
|
|
738
789
|
return Err(fail(&format!(
|
|
@@ -763,6 +814,27 @@ fn buy_once(state: &Rc<RefCell<SecretsState>>) -> Result<String, ProjectNameErro
|
|
|
763
814
|
Ok(token)
|
|
764
815
|
}
|
|
765
816
|
|
|
817
|
+
const REDIRECT_MAX: usize = 5;
|
|
818
|
+
|
|
819
|
+
// The URL a body-keeping redirect names, while it stays on the exchange's own
|
|
820
|
+
// origin. Any other redirect would drop the body or leave the origin.
|
|
821
|
+
fn moved(url: &str, at: &str, res: &Value) -> Option<String> {
|
|
822
|
+
let status = to_int(&getp(res, "status"));
|
|
823
|
+
if 307 != status && 308 != status {
|
|
824
|
+
return None;
|
|
825
|
+
}
|
|
826
|
+
let location = get_str(&getp(res, "headers"), "location").filter(|l| !l.is_empty())?;
|
|
827
|
+
let agent = exchange_agent();
|
|
828
|
+
let from = agent.request("GET", at).request_url().ok()?;
|
|
829
|
+
let next = from.as_url().join(&location).ok()?;
|
|
830
|
+
let own = agent.request("GET", url).request_url().ok()?;
|
|
831
|
+
if next.origin() == own.as_url().origin() {
|
|
832
|
+
Some(next.to_string())
|
|
833
|
+
} else {
|
|
834
|
+
None
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
766
838
|
// One pooled agent for every exchange; a followed redirect would carry the token.
|
|
767
839
|
fn exchange_agent() -> ureq::Agent {
|
|
768
840
|
static AGENT: std::sync::OnceLock<ureq::Agent> = std::sync::OnceLock::new();
|
|
@@ -803,6 +875,13 @@ fn raw_exchange_fetch(fullurl: &str, fetchdef: &Value) -> Result<Value, ProjectN
|
|
|
803
875
|
|
|
804
876
|
let status = resp.status() as i64;
|
|
805
877
|
|
|
878
|
+
let headers = Value::empty_map();
|
|
879
|
+
for name in resp.headers_names() {
|
|
880
|
+
if let Some(val) = resp.header(&name) {
|
|
881
|
+
setp(&headers, &name.to_lowercase(), Value::str(val));
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
806
885
|
let text = resp
|
|
807
886
|
.into_string()
|
|
808
887
|
.map_err(|err| fail(&format!("secrets: token exchange body: {}", err)))?;
|
|
@@ -815,6 +894,7 @@ fn raw_exchange_fetch(fullurl: &str, fetchdef: &Value) -> Result<Value, ProjectN
|
|
|
815
894
|
|
|
816
895
|
Ok(jo(vec![
|
|
817
896
|
("status", Value::Num(status as f64)),
|
|
897
|
+
("headers", headers),
|
|
818
898
|
("json", json_thunk(parsed)),
|
|
819
899
|
]))
|
|
820
900
|
}
|