@voxgig/sdkgen 4.19.1 → 4.20.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/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +6 -3
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +4 -1
- package/dist/utility.js +60 -0
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.aon +10 -0
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/Config_c.ts +15 -0
- package/project/.sdk/src/cmp/c/Main_c.ts +15 -0
- package/project/.sdk/src/cmp/c/PrepareAuth_c.ts +371 -0
- package/project/.sdk/src/cmp/clojure/Config_clojure.ts +47 -1
- package/project/.sdk/src/cmp/clojure/Main_clojure.ts +11 -1
- package/project/.sdk/src/cmp/clojure/PrepareAuth_clojure.ts +374 -0
- package/project/.sdk/src/cmp/cpp/Config_cpp.ts +40 -0
- package/project/.sdk/src/cmp/cpp/Main_cpp.ts +17 -0
- package/project/.sdk/src/cmp/cpp/PrepareAuth_cpp.ts +441 -0
- package/project/.sdk/src/cmp/csharp/Config_csharp.ts +42 -1
- package/project/.sdk/src/cmp/csharp/Main_csharp.ts +18 -0
- package/project/.sdk/src/cmp/csharp/PrepareAuth_csharp.ts +392 -0
- package/project/.sdk/src/cmp/elixir/Config_elixir.ts +36 -1
- package/project/.sdk/src/cmp/elixir/Main_elixir.ts +15 -0
- package/project/.sdk/src/cmp/elixir/PrepareAuth_elixir.ts +418 -0
- package/project/.sdk/src/cmp/go/Config_go.ts +12 -1
- package/project/.sdk/src/cmp/go/Main_go.ts +14 -0
- package/project/.sdk/src/cmp/go/PrepareAuth_go.ts +322 -0
- package/project/.sdk/src/cmp/java/Config_java.ts +20 -1
- package/project/.sdk/src/cmp/java/Main_java.ts +14 -0
- package/project/.sdk/src/cmp/java/PrepareAuth_java.ts +298 -0
- package/project/.sdk/src/cmp/js/Config_js.ts +12 -1
- package/project/.sdk/src/cmp/js/Main_js.ts +6 -0
- package/project/.sdk/src/cmp/js/PrepareAuth_js.ts +244 -0
- package/project/.sdk/src/cmp/kotlin/Config_kotlin.ts +23 -1
- package/project/.sdk/src/cmp/kotlin/Main_kotlin.ts +20 -0
- package/project/.sdk/src/cmp/kotlin/PrepareAuth_kotlin.ts +440 -0
- package/project/.sdk/src/cmp/lua/Config_lua.ts +15 -1
- package/project/.sdk/src/cmp/lua/Main_lua.ts +11 -0
- package/project/.sdk/src/cmp/lua/PrepareAuth_lua.ts +364 -0
- package/project/.sdk/src/cmp/ocaml/Config_ocaml.ts +31 -1
- package/project/.sdk/src/cmp/ocaml/Main_ocaml.ts +19 -0
- package/project/.sdk/src/cmp/ocaml/PrepareAuth_ocaml.ts +454 -0
- package/project/.sdk/src/cmp/perl/Config_perl.ts +30 -0
- package/project/.sdk/src/cmp/perl/Main_perl.ts +14 -0
- package/project/.sdk/src/cmp/perl/PrepareAuth_perl.ts +387 -0
- package/project/.sdk/src/cmp/php/Config_php.ts +12 -1
- package/project/.sdk/src/cmp/php/Main_php.ts +7 -0
- package/project/.sdk/src/cmp/php/PrepareAuth_php.ts +325 -0
- package/project/.sdk/src/cmp/py/Config_py.ts +12 -1
- package/project/.sdk/src/cmp/py/Main_py.ts +12 -0
- package/project/.sdk/src/cmp/py/PrepareAuth_py.ts +389 -0
- package/project/.sdk/src/cmp/rb/Config_rb.ts +18 -1
- package/project/.sdk/src/cmp/rb/Main_rb.ts +10 -0
- package/project/.sdk/src/cmp/rb/PrepareAuth_rb.ts +305 -0
- package/project/.sdk/src/cmp/rust/Config_rust.ts +41 -1
- package/project/.sdk/src/cmp/rust/Main_rust.ts +16 -0
- package/project/.sdk/src/cmp/rust/PrepareAuth_rust.ts +410 -0
- package/project/.sdk/src/cmp/scala/Config_scala.ts +21 -1
- package/project/.sdk/src/cmp/scala/Main_scala.ts +14 -0
- package/project/.sdk/src/cmp/scala/PrepareAuth_scala.ts +415 -0
- package/project/.sdk/src/cmp/swift/Config_swift.ts +37 -1
- package/project/.sdk/src/cmp/swift/Main_swift.ts +10 -0
- package/project/.sdk/src/cmp/swift/PrepareAuth_swift.ts +439 -0
- package/project/.sdk/src/cmp/ts/Config_ts.ts +12 -1
- package/project/.sdk/src/cmp/ts/Main_ts.ts +5 -0
- package/project/.sdk/src/cmp/ts/PrepareAuth_ts.ts +237 -0
- package/project/.sdk/src/cmp/zig/Config_zig.ts +33 -1
- package/project/.sdk/src/cmp/zig/Main_zig.ts +16 -0
- package/project/.sdk/src/cmp/zig/PrepareAuth_zig.ts +545 -0
- package/project/.sdk/tm/clojure/src/sdk/core.clj +31 -20
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +36 -40
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +11 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +19 -32
- package/project/.sdk/tm/java/utility/MakeOptions.java +13 -1
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +14 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +13 -46
- package/project/.sdk/tm/ocaml/Makefile +11 -1
- package/project/.sdk/tm/ocaml/sdk_helpers.ml +15 -0
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +31 -25
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +125 -12
- package/project/.sdk/tm/ocaml/test/t_pipeline.ml +64 -6
- package/project/.sdk/tm/perl/utility/make_options.pm +10 -1
- package/project/.sdk/tm/php/utility/MakeOptions.php +8 -1
- package/project/.sdk/tm/rust/utility/make_options.rs +13 -1
- package/project/.sdk/tm/scala/utility/Make.scala +14 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +16 -40
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +30 -3
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +21 -39
- package/project/.sdk/tm/zig/core/utility.zig +37 -45
- package/project/.sdk/tm/zig/test/pipeline_test.zig +34 -0
- package/project/sdkgen-package.json +1 -1
- package/src/sdkgen.ts +4 -1
- package/src/utility.ts +75 -0
- package/project/.sdk/tm/c/utility/prepare_auth.c +0 -65
- package/project/.sdk/tm/csharp/utility/PrepareAuth.cs +0 -54
- package/project/.sdk/tm/go/utility/prepare_auth.go +0 -59
- package/project/.sdk/tm/java/utility/PrepareAuth.java +0 -66
- package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +0 -49
- package/project/.sdk/tm/lua/utility/prepare_auth.lua +0 -52
- package/project/.sdk/tm/perl/utility/prepare_auth.pm +0 -56
- package/project/.sdk/tm/php/utility/PrepareAuth.php +0 -45
- package/project/.sdk/tm/py/pkg/utility/prepare_auth.py +0 -46
- package/project/.sdk/tm/rb/utility/prepare_auth.rb +0 -35
- package/project/.sdk/tm/rust/utility/prepare_auth.rs +0 -65
- package/project/.sdk/tm/ts/src/utility/PrepareAuthUtility.ts +0 -78
package/src/utility.ts
CHANGED
|
@@ -75,6 +75,78 @@ function resolveAuthPrefix(model: any): string {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
// AUTH SUPPRESSED AT GENERATION TIME — and ONLY by an explicit opt-out.
|
|
79
|
+
//
|
|
80
|
+
// NOT `isAuthActive`, and the difference is load-bearing. That helper is
|
|
81
|
+
// also false when `main.kit.info.auth` is false, which only means the SPEC
|
|
82
|
+
// declared no security scheme. Such an SDK still carries a credential:
|
|
83
|
+
// `optspec` always declares `apikey`, and makeOptions fills `options.auth`
|
|
84
|
+
// from the optspec defaults, so the runtime `null == options.auth` guard
|
|
85
|
+
// never fires and the credential has always been sent. Emitting a no-op
|
|
86
|
+
// prepareAuth for those SDKs silently breaks a working credential — and
|
|
87
|
+
// takes the secrets feature with it, since that resolves a secret into
|
|
88
|
+
// `options.apikey` and prepareAuth then places nothing.
|
|
89
|
+
//
|
|
90
|
+
// `main.kit.config.auth.active: false` is the project saying "this SDK
|
|
91
|
+
// sends no credential, ever". That is the only signal that can be honoured
|
|
92
|
+
// before runtime, so it is the only one used here.
|
|
93
|
+
function isAuthSuppressed(model: any): boolean {
|
|
94
|
+
const auth = getModelPath(model, `main.${KIT}.config.auth`,
|
|
95
|
+
{ only_active: false, required: false })
|
|
96
|
+
return null != auth && false === auth.active
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// WHERE the credential goes, and UNDER WHAT NAME. Same priority order as
|
|
101
|
+
// resolveAuthPrefix: a per-SDK override first, then what apidef derived
|
|
102
|
+
// from the spec's securityScheme, then the convention.
|
|
103
|
+
//
|
|
104
|
+
// THESE EXISTED IN THE MODEL AND WERE DROPPED AT GENERATION. apidef has
|
|
105
|
+
// always resolved `in` and `name` (transform/top.ts resolveSecurity), and
|
|
106
|
+
// api-info.aon records them — joplin's says `in: "query", name: "token"`.
|
|
107
|
+
// But nothing read them: every target's prepare_auth template hardcoded an
|
|
108
|
+
// `authorization` header, so an apiKey-in-query API got a header it does
|
|
109
|
+
// not read and never got the query parameter it does. Four repos in the
|
|
110
|
+
// cedar fleet ship SDKs that cannot authenticate for this reason
|
|
111
|
+
// (joplin `token`, pipedrive `api_token`, trello `key`,
|
|
112
|
+
// lm-umbrella `apiKey`).
|
|
113
|
+
//
|
|
114
|
+
// 'header' and 'Authorization' remain the defaults, so every SDK whose
|
|
115
|
+
// scheme is header-based generates exactly what it generated before.
|
|
116
|
+
function resolveAuthIn(model: any): string {
|
|
117
|
+
const auth = getModelPath(model, `main.${KIT}.config.auth`,
|
|
118
|
+
{ only_active: false, required: false })
|
|
119
|
+
if (null != auth && null != auth.in && '' !== auth.in) {
|
|
120
|
+
return String(auth.in).toLowerCase()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const security = getModelPath(model, `main.${KIT}.info.security`,
|
|
124
|
+
{ only_active: false, required: false })
|
|
125
|
+
if (null != security && null != security.in && '' !== security.in) {
|
|
126
|
+
return String(security.in).toLowerCase()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return 'header'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
function resolveAuthName(model: any): string {
|
|
134
|
+
const auth = getModelPath(model, `main.${KIT}.config.auth`,
|
|
135
|
+
{ only_active: false, required: false })
|
|
136
|
+
if (null != auth && null != auth.name && '' !== auth.name) {
|
|
137
|
+
return String(auth.name)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const security = getModelPath(model, `main.${KIT}.info.security`,
|
|
141
|
+
{ only_active: false, required: false })
|
|
142
|
+
if (null != security && null != security.name && '' !== security.name) {
|
|
143
|
+
return String(security.name)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 'Authorization'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
78
150
|
// True when the spec's security scheme is genuine HTTP Basic Auth (two
|
|
79
151
|
// credentials, base64-joined) rather than a single bearer-style token with
|
|
80
152
|
// a prefix. Priority order mirrors resolveAuthPrefix:
|
|
@@ -157,6 +229,9 @@ export {
|
|
|
157
229
|
requirePath,
|
|
158
230
|
isAuthActive,
|
|
159
231
|
resolveAuthPrefix,
|
|
232
|
+
resolveAuthIn,
|
|
233
|
+
resolveAuthName,
|
|
234
|
+
isAuthSuppressed,
|
|
160
235
|
resolveAuthExchange,
|
|
161
236
|
isHttpBasicAuth,
|
|
162
237
|
SdkGenError,
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// prepare_auth utility (mirrors utility/prepare_auth.rs).
|
|
2
|
-
|
|
3
|
-
#include "sdk.h"
|
|
4
|
-
|
|
5
|
-
#include <stdio.h>
|
|
6
|
-
#include <string.h>
|
|
7
|
-
|
|
8
|
-
#define HEADER_AUTH "authorization"
|
|
9
|
-
#define OPTION_APIKEY "apikey"
|
|
10
|
-
#define NOT_FOUND "__NOTFOUND__"
|
|
11
|
-
|
|
12
|
-
Spec* prepare_auth_util(Context* ctx, PNError** err) {
|
|
13
|
-
*err = NULL;
|
|
14
|
-
Spec* spec = ctx->spec;
|
|
15
|
-
if (!spec) {
|
|
16
|
-
*err = context_make_error(ctx, "auth_no_spec", "Expected context spec property to be defined.");
|
|
17
|
-
return NULL;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
voxgig_value* headers = spec->headers;
|
|
21
|
-
voxgig_value* options = ctx->client ? sdk_options_map(ctx->client) : ctx->options;
|
|
22
|
-
|
|
23
|
-
voxgig_value* auth = getp(options, "auth");
|
|
24
|
-
if (v_is_noval(auth) || v_is_null(auth)) {
|
|
25
|
-
voxgig_value* k = voxgig_new_string(HEADER_AUTH);
|
|
26
|
-
voxgig_delprop(headers, k);
|
|
27
|
-
voxgig_release(k);
|
|
28
|
-
return spec;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
voxgig_value* akey_key = voxgig_new_string(OPTION_APIKEY);
|
|
32
|
-
voxgig_value* nf = voxgig_new_string(NOT_FOUND);
|
|
33
|
-
voxgig_value* apikey = voxgig_getprop(options, akey_key, nf);
|
|
34
|
-
voxgig_release(akey_key);
|
|
35
|
-
voxgig_release(nf);
|
|
36
|
-
|
|
37
|
-
bool skip;
|
|
38
|
-
if (v_is_noval(apikey) || v_is_null(apikey)) {
|
|
39
|
-
skip = true;
|
|
40
|
-
} else if (voxgig_is_string(apikey)) {
|
|
41
|
-
const char* s = voxgig_as_string(apikey);
|
|
42
|
-
skip = (strcmp(s, NOT_FOUND) == 0 || s[0] == '\0');
|
|
43
|
-
} else {
|
|
44
|
-
skip = false;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (skip) {
|
|
48
|
-
voxgig_value* k = voxgig_new_string(HEADER_AUTH);
|
|
49
|
-
voxgig_delprop(headers, k);
|
|
50
|
-
voxgig_release(k);
|
|
51
|
-
} else {
|
|
52
|
-
voxgig_value* prefix_v = getpath2(options, "auth", "prefix");
|
|
53
|
-
const char* auth_prefix = voxgig_is_string(prefix_v) ? voxgig_as_string(prefix_v) : "";
|
|
54
|
-
const char* apikey_val = voxgig_is_string(apikey) ? voxgig_as_string(apikey) : "";
|
|
55
|
-
if (auth_prefix[0] == '\0') {
|
|
56
|
-
setp(headers, HEADER_AUTH, v_str(apikey_val));
|
|
57
|
-
} else {
|
|
58
|
-
char buf[1024];
|
|
59
|
-
snprintf(buf, sizeof(buf), "%s %s", auth_prefix, apikey_val);
|
|
60
|
-
setp(headers, HEADER_AUTH, v_str(buf));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return spec;
|
|
65
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// ProjectName SDK utility: prepareAuth - shape the authorization header
|
|
2
|
-
// from the client options.
|
|
3
|
-
|
|
4
|
-
using Voxgig.Struct;
|
|
5
|
-
|
|
6
|
-
namespace ProjectNameSdk.Util;
|
|
7
|
-
|
|
8
|
-
public static partial class SdkUtility
|
|
9
|
-
{
|
|
10
|
-
private const string HeaderAuth = "authorization";
|
|
11
|
-
private const string OptionApikey = "apikey";
|
|
12
|
-
private const string NotFound = "__NOTFOUND__";
|
|
13
|
-
|
|
14
|
-
internal static Spec PrepareAuthUtil(Context ctx)
|
|
15
|
-
{
|
|
16
|
-
var spec = ctx.Spec ?? throw ctx.MakeError("auth_no_spec",
|
|
17
|
-
"Expected context spec property to be defined.");
|
|
18
|
-
|
|
19
|
-
var headers = spec.Headers;
|
|
20
|
-
var options = ctx.Client!.OptionsMap();
|
|
21
|
-
|
|
22
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
23
|
-
if (!options.TryGetValue("auth", out var auth) || auth == null)
|
|
24
|
-
{
|
|
25
|
-
headers.Remove(HeaderAuth);
|
|
26
|
-
return spec;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var apikey = StructUtils.GetProp(options, OptionApikey, NotFound);
|
|
30
|
-
|
|
31
|
-
var skip = apikey == null ||
|
|
32
|
-
(apikey is string apikeyStr && (apikeyStr == NotFound || apikeyStr == ""));
|
|
33
|
-
|
|
34
|
-
if (skip)
|
|
35
|
-
{
|
|
36
|
-
headers.Remove(HeaderAuth);
|
|
37
|
-
}
|
|
38
|
-
else
|
|
39
|
-
{
|
|
40
|
-
var authPrefix = "";
|
|
41
|
-
if (StructUtils.GetPath(options, StructUtils.Jt("auth", "prefix")) is string ap)
|
|
42
|
-
{
|
|
43
|
-
authPrefix = ap;
|
|
44
|
-
}
|
|
45
|
-
var apikeyVal = apikey as string ?? "";
|
|
46
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
47
|
-
headers[HeaderAuth] = authPrefix == ""
|
|
48
|
-
? apikeyVal
|
|
49
|
-
: authPrefix + " " + apikeyVal;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return spec;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
package utility
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
vs "github.com/voxgig/struct"
|
|
5
|
-
|
|
6
|
-
"GOMODULE/core"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
const headerAuth = "authorization"
|
|
10
|
-
const optionApikey = "apikey"
|
|
11
|
-
const notFound = "__NOTFOUND__"
|
|
12
|
-
|
|
13
|
-
func prepareAuthUtil(ctx *core.Context) (*core.Spec, error) {
|
|
14
|
-
spec := ctx.Spec
|
|
15
|
-
if spec == nil {
|
|
16
|
-
return nil, ctx.MakeError("auth_no_spec",
|
|
17
|
-
"Expected context spec property to be defined.")
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
headers := spec.Headers
|
|
21
|
-
options := ctx.Client.OptionsMap()
|
|
22
|
-
|
|
23
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
24
|
-
if options["auth"] == nil {
|
|
25
|
-
delete(headers, headerAuth)
|
|
26
|
-
return spec, nil
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
apikey := vs.GetProp(options, optionApikey, notFound)
|
|
30
|
-
|
|
31
|
-
skip := false
|
|
32
|
-
if apikey == nil {
|
|
33
|
-
skip = true
|
|
34
|
-
} else if apikeyStr, ok := apikey.(string); ok &&
|
|
35
|
-
(apikeyStr == notFound || apikeyStr == "") {
|
|
36
|
-
skip = true
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if skip {
|
|
40
|
-
delete(headers, headerAuth)
|
|
41
|
-
} else {
|
|
42
|
-
authPrefix := ""
|
|
43
|
-
if ap := vs.GetPath(options, []any{"auth", "prefix"}); ap != nil {
|
|
44
|
-
authPrefix, _ = ap.(string)
|
|
45
|
-
}
|
|
46
|
-
apikeyVal := ""
|
|
47
|
-
if av, ok := apikey.(string); ok {
|
|
48
|
-
apikeyVal = av
|
|
49
|
-
}
|
|
50
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
51
|
-
if authPrefix == "" {
|
|
52
|
-
headers[headerAuth] = apikeyVal
|
|
53
|
-
} else {
|
|
54
|
-
headers[headerAuth] = authPrefix + " " + apikeyVal
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return spec, nil
|
|
59
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package JAVAPACKAGE.utility;
|
|
2
|
-
|
|
3
|
-
import java.util.List;
|
|
4
|
-
import java.util.Map;
|
|
5
|
-
|
|
6
|
-
import JAVAPACKAGE.core.Context;
|
|
7
|
-
import JAVAPACKAGE.core.Spec;
|
|
8
|
-
import JAVAPACKAGE.utility.struct.Struct;
|
|
9
|
-
|
|
10
|
-
final class PrepareAuth {
|
|
11
|
-
|
|
12
|
-
private PrepareAuth() {}
|
|
13
|
-
|
|
14
|
-
static final String HEADER_AUTH = "authorization";
|
|
15
|
-
static final String OPTION_APIKEY = "apikey";
|
|
16
|
-
static final String NOT_FOUND = "__NOTFOUND__";
|
|
17
|
-
|
|
18
|
-
static Spec prepareAuth(Context ctx) {
|
|
19
|
-
Spec spec = ctx.spec;
|
|
20
|
-
if (spec == null) {
|
|
21
|
-
throw ctx.makeError("auth_no_spec",
|
|
22
|
-
"Expected context spec property to be defined.");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Map<String, Object> headers = spec.headers;
|
|
26
|
-
Map<String, Object> options = ctx.client.optionsMap();
|
|
27
|
-
|
|
28
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
29
|
-
if (options.get("auth") == null) {
|
|
30
|
-
headers.remove(HEADER_AUTH);
|
|
31
|
-
return spec;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Object apikey = Struct.getprop(options, OPTION_APIKEY, NOT_FOUND);
|
|
35
|
-
|
|
36
|
-
boolean skip = false;
|
|
37
|
-
if (apikey == null) {
|
|
38
|
-
skip = true;
|
|
39
|
-
}
|
|
40
|
-
else if (apikey instanceof String
|
|
41
|
-
&& (NOT_FOUND.equals(apikey) || "".equals(apikey))) {
|
|
42
|
-
skip = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (skip) {
|
|
46
|
-
headers.remove(HEADER_AUTH);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
String authPrefix = "";
|
|
50
|
-
Object ap = Struct.getpath(options, List.of("auth", "prefix"));
|
|
51
|
-
if (ap instanceof String) {
|
|
52
|
-
authPrefix = (String) ap;
|
|
53
|
-
}
|
|
54
|
-
String apikeyVal = apikey instanceof String ? (String) apikey : "";
|
|
55
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
56
|
-
if ("".equals(authPrefix)) {
|
|
57
|
-
headers.put(HEADER_AUTH, apikeyVal);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
headers.put(HEADER_AUTH, authPrefix + " " + apikeyVal);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return spec;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const HEADER_auth = 'authorization'
|
|
3
|
-
|
|
4
|
-
const OPTION_apikey = 'apikey'
|
|
5
|
-
|
|
6
|
-
const NOTFOUND = '__NOTFOUND__'
|
|
7
|
-
|
|
8
|
-
function prepareAuth(ctx) {
|
|
9
|
-
const utility = ctx.utility
|
|
10
|
-
|
|
11
|
-
const struct = utility.struct
|
|
12
|
-
const getprop = struct.getprop
|
|
13
|
-
const setprop = struct.setprop
|
|
14
|
-
const delprop = struct.delprop
|
|
15
|
-
|
|
16
|
-
const client = ctx.client
|
|
17
|
-
const spec = ctx.spec
|
|
18
|
-
|
|
19
|
-
if (null == spec) {
|
|
20
|
-
return ctx.error('auth_no_spec', 'Expected context spec property to be defined.')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const headers = spec.headers
|
|
24
|
-
|
|
25
|
-
const options = client.options()
|
|
26
|
-
|
|
27
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
28
|
-
if (null == options.auth) {
|
|
29
|
-
delprop(headers, HEADER_auth)
|
|
30
|
-
return spec
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const apikey = getprop(options, OPTION_apikey, NOTFOUND)
|
|
34
|
-
|
|
35
|
-
if (NOTFOUND === apikey || null == apikey || '' === apikey) {
|
|
36
|
-
delprop(headers, HEADER_auth)
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
40
|
-
setprop(headers, HEADER_auth,
|
|
41
|
-
options.auth.prefix ? options.auth.prefix + ' ' + apikey : apikey)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return spec
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = {
|
|
48
|
-
prepareAuth
|
|
49
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
-- ProjectName SDK utility: prepare_auth
|
|
2
|
-
|
|
3
|
-
local vs = require("utility.struct.struct")
|
|
4
|
-
|
|
5
|
-
local HEADER_AUTH = "authorization"
|
|
6
|
-
local OPTION_APIKEY = "apikey"
|
|
7
|
-
local NOT_FOUND = "__NOTFOUND__"
|
|
8
|
-
|
|
9
|
-
local function prepare_auth_util(ctx)
|
|
10
|
-
local spec = ctx.spec
|
|
11
|
-
if spec == nil then
|
|
12
|
-
return nil, ctx:make_error("auth_no_spec",
|
|
13
|
-
"Expected context spec property to be defined.")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
local headers = spec.headers
|
|
17
|
-
local options = ctx.client:options_map()
|
|
18
|
-
|
|
19
|
-
-- Public APIs that need no auth omit the options.auth block entirely.
|
|
20
|
-
if options.auth == nil then
|
|
21
|
-
headers[HEADER_AUTH] = nil
|
|
22
|
-
return spec, nil
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
local apikey = vs.getprop(options, OPTION_APIKEY, NOT_FOUND)
|
|
26
|
-
|
|
27
|
-
if apikey == nil
|
|
28
|
-
or (type(apikey) == "string" and (apikey == NOT_FOUND or apikey == ""))
|
|
29
|
-
then
|
|
30
|
-
headers[HEADER_AUTH] = nil
|
|
31
|
-
else
|
|
32
|
-
local auth_prefix = ""
|
|
33
|
-
local ap = vs.getpath(options, "auth.prefix")
|
|
34
|
-
if type(ap) == "string" then
|
|
35
|
-
auth_prefix = ap
|
|
36
|
-
end
|
|
37
|
-
local apikey_val = ""
|
|
38
|
-
if type(apikey) == "string" then
|
|
39
|
-
apikey_val = apikey
|
|
40
|
-
end
|
|
41
|
-
-- Empty prefix (raw apiKey credential) must not add a leading space.
|
|
42
|
-
if auth_prefix == "" then
|
|
43
|
-
headers[HEADER_AUTH] = apikey_val
|
|
44
|
-
else
|
|
45
|
-
headers[HEADER_AUTH] = auth_prefix .. " " .. apikey_val
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
return spec, nil
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
return prepare_auth_util
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# ProjectName SDK utility: prepare_auth
|
|
2
|
-
|
|
3
|
-
use strict;
|
|
4
|
-
use warnings;
|
|
5
|
-
|
|
6
|
-
use File::Basename ();
|
|
7
|
-
use Cwd ();
|
|
8
|
-
|
|
9
|
-
my $__dir;
|
|
10
|
-
BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
|
|
11
|
-
require(Cwd::abs_path("$__dir/../lib/Voxgig/Struct.pm"));
|
|
12
|
-
require(Cwd::abs_path("$__dir/../core/helpers.pm"));
|
|
13
|
-
|
|
14
|
-
package ProjectNameUtilities;
|
|
15
|
-
|
|
16
|
-
our %REGISTRY;
|
|
17
|
-
|
|
18
|
-
my $HEADER_AUTH = 'authorization';
|
|
19
|
-
my $OPTION_APIKEY = 'apikey';
|
|
20
|
-
my $NOT_FOUND = '__NOTFOUND__';
|
|
21
|
-
|
|
22
|
-
$REGISTRY{prepare_auth} = sub {
|
|
23
|
-
my ($ctx) = @_;
|
|
24
|
-
my $spec = $ctx->{spec};
|
|
25
|
-
return (undef, $ctx->make_error('auth_no_spec',
|
|
26
|
-
'Expected context spec property to be defined.')) unless $spec;
|
|
27
|
-
|
|
28
|
-
my $headers = $spec->{headers};
|
|
29
|
-
my $options = $ctx->{client}->options_map;
|
|
30
|
-
|
|
31
|
-
# Public APIs that need no auth omit the options.auth block entirely.
|
|
32
|
-
if (!defined ProjectNameHelpers::gp($options, 'auth')) {
|
|
33
|
-
delete $headers->{$HEADER_AUTH};
|
|
34
|
-
return ($spec, undef);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
my $apikey = Voxgig::Struct::getprop($options, $OPTION_APIKEY, $NOT_FOUND);
|
|
38
|
-
|
|
39
|
-
if (!defined $apikey || Voxgig::Struct::is_none($apikey)
|
|
40
|
-
|| Voxgig::Struct::is_jnull($apikey)
|
|
41
|
-
|| (!ref $apikey && ($apikey eq $NOT_FOUND || $apikey eq ''))) {
|
|
42
|
-
delete $headers->{$HEADER_AUTH};
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
my $auth_prefix = ProjectNameHelpers::gpath($options, 'auth.prefix');
|
|
46
|
-
$auth_prefix = '' unless defined $auth_prefix && !ref $auth_prefix;
|
|
47
|
-
my $apikey_val = (!ref $apikey) ? "$apikey" : '';
|
|
48
|
-
# Empty prefix (raw apiKey credential) must not add a leading space.
|
|
49
|
-
$headers->{$HEADER_AUTH} =
|
|
50
|
-
('' eq $auth_prefix) ? $apikey_val : "$auth_prefix $apikey_val";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return ($spec, undef);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
1;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
declare(strict_types=1);
|
|
3
|
-
|
|
4
|
-
// ProjectName SDK utility: prepare_auth
|
|
5
|
-
|
|
6
|
-
class ProjectNamePrepareAuth
|
|
7
|
-
{
|
|
8
|
-
private const HEADER_AUTH = 'authorization';
|
|
9
|
-
private const OPTION_APIKEY = 'apikey';
|
|
10
|
-
private const NOT_FOUND = '__NOTFOUND__';
|
|
11
|
-
|
|
12
|
-
public static function call(ProjectNameContext $ctx): array
|
|
13
|
-
{
|
|
14
|
-
$spec = $ctx->spec;
|
|
15
|
-
if (!$spec) {
|
|
16
|
-
return [null, $ctx->make_error('auth_no_spec', 'Expected context spec property to be defined.')];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
$headers = &$spec->headers;
|
|
20
|
-
$options = $ctx->client->options_map();
|
|
21
|
-
|
|
22
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
23
|
-
if (!isset($options['auth']) || $options['auth'] === null) {
|
|
24
|
-
unset($headers[self::HEADER_AUTH]);
|
|
25
|
-
return [$spec, null];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
$apikey = \Voxgig\Struct\Struct::getprop($options, self::OPTION_APIKEY, self::NOT_FOUND);
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
(is_string($apikey) && ($apikey === self::NOT_FOUND || $apikey === ''))
|
|
32
|
-
|| $apikey === null
|
|
33
|
-
) {
|
|
34
|
-
unset($headers[self::HEADER_AUTH]);
|
|
35
|
-
} else {
|
|
36
|
-
$auth_prefix = \Voxgig\Struct\Struct::getpath($options, 'auth.prefix') ?? '';
|
|
37
|
-
$apikey_val = is_string($apikey) ? $apikey : '';
|
|
38
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
39
|
-
$headers[self::HEADER_AUTH] = $auth_prefix === ''
|
|
40
|
-
? $apikey_val : "{$auth_prefix} {$apikey_val}";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return [$spec, null];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# ProjectName SDK utility: prepare_auth
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
from projectname_sdk.utility.voxgig_struct import voxgig_struct as vs
|
|
5
|
-
|
|
6
|
-
HEADER_AUTH = "authorization"
|
|
7
|
-
OPTION_APIKEY = "apikey"
|
|
8
|
-
NOT_FOUND = "__NOTFOUND__"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def prepare_auth_util(ctx):
|
|
12
|
-
spec = ctx.spec
|
|
13
|
-
if spec is None:
|
|
14
|
-
return None, ctx.make_error("auth_no_spec",
|
|
15
|
-
"Expected context spec property to be defined.")
|
|
16
|
-
|
|
17
|
-
headers = spec.headers
|
|
18
|
-
options = ctx.client.options_map()
|
|
19
|
-
|
|
20
|
-
# Public APIs that need no auth omit the options.auth block entirely.
|
|
21
|
-
if options.get("auth") is None:
|
|
22
|
-
headers.pop(HEADER_AUTH, None)
|
|
23
|
-
return spec, None
|
|
24
|
-
|
|
25
|
-
apikey = vs.getprop(options, OPTION_APIKEY, NOT_FOUND)
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
(isinstance(apikey, str) and apikey == NOT_FOUND)
|
|
29
|
-
or apikey is None
|
|
30
|
-
or apikey == ""
|
|
31
|
-
):
|
|
32
|
-
headers.pop(HEADER_AUTH, None)
|
|
33
|
-
else:
|
|
34
|
-
auth_prefix = ""
|
|
35
|
-
ap = vs.getpath(options, "auth.prefix")
|
|
36
|
-
if isinstance(ap, str):
|
|
37
|
-
auth_prefix = ap
|
|
38
|
-
apikey_val = ""
|
|
39
|
-
if isinstance(apikey, str):
|
|
40
|
-
apikey_val = apikey
|
|
41
|
-
# Empty prefix (raw apiKey credential) must not add a leading space.
|
|
42
|
-
headers[HEADER_AUTH] = (
|
|
43
|
-
auth_prefix + " " + apikey_val if auth_prefix else apikey_val
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
return spec, None
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# ProjectName SDK utility: prepare_auth
|
|
2
|
-
require_relative 'struct/voxgig_struct'
|
|
3
|
-
module ProjectNameUtilities
|
|
4
|
-
HEADER_AUTH = "authorization"
|
|
5
|
-
OPTION_APIKEY = "apikey"
|
|
6
|
-
NOT_FOUND = "__NOTFOUND__"
|
|
7
|
-
|
|
8
|
-
PrepareAuth = ->(ctx) {
|
|
9
|
-
spec = ctx.spec
|
|
10
|
-
return nil, ctx.make_error("auth_no_spec", "Expected context spec property to be defined.") unless spec
|
|
11
|
-
|
|
12
|
-
headers = spec.headers
|
|
13
|
-
options = ctx.client.options_map
|
|
14
|
-
|
|
15
|
-
# Public APIs that need no auth omit the options.auth block entirely.
|
|
16
|
-
if options["auth"].nil?
|
|
17
|
-
headers.delete(HEADER_AUTH)
|
|
18
|
-
return spec, nil
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
apikey = VoxgigStruct.getprop(options, OPTION_APIKEY, NOT_FOUND)
|
|
22
|
-
|
|
23
|
-
if apikey.nil? || (apikey.is_a?(String) && (apikey == NOT_FOUND || apikey == ""))
|
|
24
|
-
headers.delete(HEADER_AUTH)
|
|
25
|
-
else
|
|
26
|
-
auth_prefix = VoxgigStruct.getpath(options, "auth.prefix") || ""
|
|
27
|
-
apikey_val = apikey.is_a?(String) ? apikey : ""
|
|
28
|
-
# Empty prefix (raw apiKey credential) must not add a leading space.
|
|
29
|
-
headers[HEADER_AUTH] =
|
|
30
|
-
auth_prefix.empty? ? apikey_val : "#{auth_prefix} #{apikey_val}"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
return spec, nil
|
|
34
|
-
}
|
|
35
|
-
end
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
use std::cell::RefCell;
|
|
2
|
-
use std::rc::Rc;
|
|
3
|
-
|
|
4
|
-
use crate::core::context::Context;
|
|
5
|
-
use crate::core::error::ProjectNameError;
|
|
6
|
-
use crate::core::helpers::{getp, getpath, setp};
|
|
7
|
-
use crate::core::spec::Spec;
|
|
8
|
-
use crate::utility::voxgigstruct as vs;
|
|
9
|
-
use crate::utility::voxgigstruct::Value;
|
|
10
|
-
|
|
11
|
-
const HEADER_AUTH: &str = "authorization";
|
|
12
|
-
const OPTION_APIKEY: &str = "apikey";
|
|
13
|
-
const NOT_FOUND: &str = "__NOTFOUND__";
|
|
14
|
-
|
|
15
|
-
pub fn prepare_auth_util(ctx: &Rc<Context>) -> Result<Rc<RefCell<Spec>>, ProjectNameError> {
|
|
16
|
-
let spec = ctx.spec.borrow().clone().ok_or_else(|| {
|
|
17
|
-
ctx.make_error("auth_no_spec", "Expected context spec property to be defined.")
|
|
18
|
-
})?;
|
|
19
|
-
|
|
20
|
-
let headers = spec.borrow().headers.clone();
|
|
21
|
-
let options = match ctx.client.borrow().clone() {
|
|
22
|
-
Some(client) => client.options_map(),
|
|
23
|
-
None => ctx.options.borrow().clone(),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Public APIs that need no auth omit the options.auth block entirely.
|
|
27
|
-
let auth = getp(&options, "auth");
|
|
28
|
-
if auth.is_noval() || auth.is_null() {
|
|
29
|
-
vs::del_prop(headers, &Value::str(HEADER_AUTH));
|
|
30
|
-
return Ok(spec);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let apikey = vs::get_prop(&options, &Value::str(OPTION_APIKEY), Value::str(NOT_FOUND));
|
|
34
|
-
|
|
35
|
-
let skip = match &apikey {
|
|
36
|
-
Value::Noval | Value::Null => true,
|
|
37
|
-
Value::Str(s) => s == NOT_FOUND || s.is_empty(),
|
|
38
|
-
_ => false,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
if skip {
|
|
42
|
-
vs::del_prop(headers, &Value::str(HEADER_AUTH));
|
|
43
|
-
} else {
|
|
44
|
-
let auth_prefix = match getpath(&["auth", "prefix"], &options) {
|
|
45
|
-
Value::Str(s) => s,
|
|
46
|
-
_ => String::new(),
|
|
47
|
-
};
|
|
48
|
-
let apikey_val = match &apikey {
|
|
49
|
-
Value::Str(s) => s.clone(),
|
|
50
|
-
_ => String::new(),
|
|
51
|
-
};
|
|
52
|
-
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
53
|
-
if auth_prefix.is_empty() {
|
|
54
|
-
setp(&headers, HEADER_AUTH, Value::str(apikey_val));
|
|
55
|
-
} else {
|
|
56
|
-
setp(
|
|
57
|
-
&headers,
|
|
58
|
-
HEADER_AUTH,
|
|
59
|
-
Value::str(format!("{} {}", auth_prefix, apikey_val)),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
Ok(spec)
|
|
65
|
-
}
|