@databricks/sdk-auth 0.34.0 → 0.35.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/dist/auth.d.ts +42 -40
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +38 -42
- package/dist/auth.js.map +1 -1
- package/dist/credentials/default/chain.d.ts +26 -22
- package/dist/credentials/default/chain.d.ts.map +1 -1
- package/dist/credentials/default/chain.js +74 -84
- package/dist/credentials/default/chain.js.map +1 -1
- package/dist/credentials/default/default-credentials.d.ts +12 -9
- package/dist/credentials/default/default-credentials.d.ts.map +1 -1
- package/dist/credentials/default/default-credentials.js +29 -20
- package/dist/credentials/default/default-credentials.js.map +1 -1
- package/dist/credentials/default/errors.d.ts +7 -4
- package/dist/credentials/default/errors.d.ts.map +1 -1
- package/dist/credentials/default/errors.js +17 -13
- package/dist/credentials/default/errors.js.map +1 -1
- package/dist/credentials/default/u2m-strategy.d.ts +6 -2
- package/dist/credentials/default/u2m-strategy.d.ts.map +1 -1
- package/dist/credentials/default/u2m-strategy.js +21 -20
- package/dist/credentials/default/u2m-strategy.js.map +1 -1
- package/dist/credentials/errors.d.ts +15 -12
- package/dist/credentials/errors.d.ts.map +1 -1
- package/dist/credentials/errors.js +40 -41
- package/dist/credentials/errors.js.map +1 -1
- package/dist/credentials/host-metadata.d.ts +22 -19
- package/dist/credentials/host-metadata.d.ts.map +1 -1
- package/dist/credentials/host-metadata.js +88 -109
- package/dist/credentials/host-metadata.js.map +1 -1
- package/dist/credentials/index.browser.d.ts +4 -11
- package/dist/credentials/index.browser.js +5 -9
- package/dist/credentials/index.d.ts +7 -14
- package/dist/credentials/index.js +8 -10
- package/dist/credentials/m2m.d.ts +29 -28
- package/dist/credentials/m2m.d.ts.map +1 -1
- package/dist/credentials/m2m.js +66 -81
- package/dist/credentials/m2m.js.map +1 -1
- package/dist/credentials/pat.d.ts +6 -5
- package/dist/credentials/pat.d.ts.map +1 -1
- package/dist/credentials/pat.js +33 -37
- package/dist/credentials/pat.js.map +1 -1
- package/dist/credentials/u2m.d.ts +17 -20
- package/dist/credentials/u2m.d.ts.map +1 -1
- package/dist/credentials/u2m.js +107 -135
- package/dist/credentials/u2m.js.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/oidc/env.d.ts +6 -2
- package/dist/oidc/env.d.ts.map +1 -1
- package/dist/oidc/env.js +19 -16
- package/dist/oidc/env.js.map +1 -1
- package/dist/oidc/file.d.ts +6 -2
- package/dist/oidc/file.d.ts.map +1 -1
- package/dist/oidc/file.js +23 -25
- package/dist/oidc/file.js.map +1 -1
- package/dist/oidc/index.browser.d.ts +3 -13
- package/dist/oidc/index.browser.js +4 -11
- package/dist/oidc/index.d.ts +5 -14
- package/dist/oidc/index.js +6 -12
- package/dist/oidc/oidc.d.ts +8 -5
- package/dist/oidc/oidc.d.ts.map +1 -1
- package/dist/oidc/oidc.js +11 -7
- package/dist/oidc/oidc.js.map +1 -1
- package/dist/oidc/tokensource.d.ts +41 -41
- package/dist/oidc/tokensource.d.ts.map +1 -1
- package/dist/oidc/tokensource.js +47 -52
- package/dist/oidc/tokensource.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/package.json +3 -3
- package/dist/credentials/index.browser.d.ts.map +0 -1
- package/dist/credentials/index.browser.js.map +0 -1
- package/dist/credentials/index.d.ts.map +0 -1
- package/dist/credentials/index.js.map +0 -1
- package/dist/oidc/index.browser.d.ts.map +0 -1
- package/dist/oidc/index.browser.js.map +0 -1
- package/dist/oidc/index.d.ts.map +0 -1
- package/dist/oidc/index.js.map +0 -1
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/auth.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Core authentication interfaces and types for the Databricks SDK.
|
|
3
4
|
*
|
|
@@ -9,54 +10,54 @@
|
|
|
9
10
|
/**
|
|
10
11
|
* Represents a header that can be used to sign requests.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
interface Header {
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Anything that can return authentication headers.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
interface Credentials {
|
|
21
|
+
/**
|
|
22
|
+
* Short identifier for the authentication strategy, e.g. `pat` or
|
|
23
|
+
* `oauth-m2m`. Used for logging and for selecting between strategies.
|
|
24
|
+
*/
|
|
25
|
+
name(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns headers to authenticate requests.
|
|
28
|
+
*/
|
|
29
|
+
authHeaders(): Promise<Header[]>;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Represents a token that can be used to sign requests.
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
interface Token {
|
|
35
|
+
/**
|
|
36
|
+
* The raw value to sign requests with.
|
|
37
|
+
* It typically is an access token but can represent other types of tokens
|
|
38
|
+
* (e.g., ID tokens).
|
|
39
|
+
*/
|
|
40
|
+
value: string;
|
|
41
|
+
/**
|
|
42
|
+
* The type of token. If empty, the token type is assumed to be "Bearer".
|
|
43
|
+
*/
|
|
44
|
+
type?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The time at which the token expires.
|
|
47
|
+
* If undefined, the token is considered to be valid indefinitely.
|
|
48
|
+
*/
|
|
49
|
+
expiry?: Date;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Anything that can return a token.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
interface TokenProvider {
|
|
55
|
+
/**
|
|
56
|
+
* Returns a token or throws an error.
|
|
57
|
+
* The returned Token should be considered immutable and should not be
|
|
58
|
+
* modified.
|
|
59
|
+
*/
|
|
60
|
+
token(): Promise<Token>;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Adapter to allow the use of ordinary functions as TokenProvider.
|
|
@@ -64,12 +65,11 @@ export interface TokenProvider {
|
|
|
64
65
|
* @example
|
|
65
66
|
* const provider = tokenProviderFn(async () => ({ value: 'my-token' }));
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
+
declare function tokenProviderFn(fn: () => Promise<Token>): TokenProvider;
|
|
68
69
|
/**
|
|
69
70
|
* Combines TokenProvider and Credentials interfaces.
|
|
70
71
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
72
|
+
interface TokenCredentials extends TokenProvider, Credentials {}
|
|
73
73
|
/**
|
|
74
74
|
* Creates a TokenCredentials that uses the given TokenProvider to return
|
|
75
75
|
* authentication headers.
|
|
@@ -77,5 +77,7 @@ export interface TokenCredentials extends TokenProvider, Credentials {
|
|
|
77
77
|
* @param name - Short identifier for the auth strategy (e.g. `oauth-m2m`).
|
|
78
78
|
* @param provider - Source of tokens used to build the Authorization header.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
declare function newTokenCredentials(name: string, provider: TokenProvider): TokenCredentials;
|
|
81
|
+
//#endregion
|
|
82
|
+
export { Credentials, Header, Token, TokenCredentials, TokenProvider, newTokenCredentials, tokenProviderFn };
|
|
81
83
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","
|
|
1
|
+
{"version":3,"file":"auth.d.ts","names":[],"sources":["../src/auth.ts"],"mappings":";;AAYA;;;;;AAQA;;;;;UARiB,MAAA;EACf,GAAA;EACA,KAAA;AAAA;;AAsBF;;UAhBiB,WAAA;EAiCF;;;;EA5Bb,IAAA;EA4Ba;;AAMf;EA7BE,WAAA,IAAe,OAAA,CAAQ,MAAA;AAAA;;;;UAMR,KAAA;EA6BO;;AASxB;;;EAhCE,KAAA;EAgCwC;;;EA3BxC,IAAA;EA2BwC;;;;EArBxC,MAAA,GAAS,IAAA;AAAA;AA4BX;;;AAAA,UAtBiB,aAAA;EAsBmD;AASpE;;;;EAzBE,KAAA,IAAS,OAAA,CAAQ,KAAA;AAAA;;;;;;;iBASH,eAAA,CAAgB,EAAA,QAAU,OAAA,CAAQ,KAAA,IAAS,aAAA;;;;UAO1C,gBAAA,SAAyB,aAAA,EAAe,WAAA;;;;;;;;iBASzC,mBAAA,CACd,IAAA,UACA,QAAA,EAAU,aAAA,GACT,gBAAA"}
|
package/dist/auth.js
CHANGED
|
@@ -1,47 +1,43 @@
|
|
|
1
|
+
//#region src/auth.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Adapter to allow the use of ordinary functions as TokenProvider.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const provider = tokenProviderFn(async () => ({ value: 'my-token' }));
|
|
14
|
-
*/
|
|
15
|
-
export function tokenProviderFn(fn) {
|
|
16
|
-
return { token: fn };
|
|
3
|
+
* Adapter to allow the use of ordinary functions as TokenProvider.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const provider = tokenProviderFn(async () => ({ value: 'my-token' }));
|
|
7
|
+
*/
|
|
8
|
+
function tokenProviderFn(fn) {
|
|
9
|
+
return { token: fn };
|
|
17
10
|
}
|
|
18
11
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
class TokenCredentialsImpl {
|
|
29
|
-
strategyName;
|
|
30
|
-
provider;
|
|
31
|
-
constructor(strategyName, provider) {
|
|
32
|
-
this.strategyName = strategyName;
|
|
33
|
-
this.provider = provider;
|
|
34
|
-
}
|
|
35
|
-
name() {
|
|
36
|
-
return this.strategyName;
|
|
37
|
-
}
|
|
38
|
-
async token() {
|
|
39
|
-
return this.provider.token();
|
|
40
|
-
}
|
|
41
|
-
async authHeaders() {
|
|
42
|
-
const t = await this.token();
|
|
43
|
-
const scheme = t.type ?? 'Bearer';
|
|
44
|
-
return [{ key: 'Authorization', value: `${scheme} ${t.value}` }];
|
|
45
|
-
}
|
|
12
|
+
* Creates a TokenCredentials that uses the given TokenProvider to return
|
|
13
|
+
* authentication headers.
|
|
14
|
+
*
|
|
15
|
+
* @param name - Short identifier for the auth strategy (e.g. `oauth-m2m`).
|
|
16
|
+
* @param provider - Source of tokens used to build the Authorization header.
|
|
17
|
+
*/
|
|
18
|
+
function newTokenCredentials(name, provider) {
|
|
19
|
+
return new TokenCredentialsImpl(name, provider);
|
|
46
20
|
}
|
|
21
|
+
var TokenCredentialsImpl = class {
|
|
22
|
+
constructor(strategyName, provider) {
|
|
23
|
+
this.strategyName = strategyName;
|
|
24
|
+
this.provider = provider;
|
|
25
|
+
}
|
|
26
|
+
name() {
|
|
27
|
+
return this.strategyName;
|
|
28
|
+
}
|
|
29
|
+
async token() {
|
|
30
|
+
return this.provider.token();
|
|
31
|
+
}
|
|
32
|
+
async authHeaders() {
|
|
33
|
+
const t = await this.token();
|
|
34
|
+
return [{
|
|
35
|
+
key: "Authorization",
|
|
36
|
+
value: `${t.type ?? "Bearer"} ${t.value}`
|
|
37
|
+
}];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { newTokenCredentials, tokenProviderFn };
|
|
47
43
|
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","
|
|
1
|
+
{"version":3,"file":"auth.js","names":[],"sources":["../src/auth.ts"],"sourcesContent":["/**\n * Core authentication interfaces and types for the Databricks SDK.\n *\n * This module is not meant to be used directly by consumers of the SDK\n * and is subject to change without notice.\n *\n * @packageDocumentation\n */\n\n/**\n * Represents a header that can be used to sign requests.\n */\nexport interface Header {\n key: string;\n value: string;\n}\n\n/**\n * Anything that can return authentication headers.\n */\nexport interface Credentials {\n /**\n * Short identifier for the authentication strategy, e.g. `pat` or\n * `oauth-m2m`. Used for logging and for selecting between strategies.\n */\n name(): string;\n\n /**\n * Returns headers to authenticate requests.\n */\n authHeaders(): Promise<Header[]>;\n}\n\n/**\n * Represents a token that can be used to sign requests.\n */\nexport interface Token {\n /**\n * The raw value to sign requests with.\n * It typically is an access token but can represent other types of tokens\n * (e.g., ID tokens).\n */\n value: string;\n\n /**\n * The type of token. If empty, the token type is assumed to be \"Bearer\".\n */\n type?: string;\n\n /**\n * The time at which the token expires.\n * If undefined, the token is considered to be valid indefinitely.\n */\n expiry?: Date;\n}\n\n/**\n * Anything that can return a token.\n */\nexport interface TokenProvider {\n /**\n * Returns a token or throws an error.\n * The returned Token should be considered immutable and should not be\n * modified.\n */\n token(): Promise<Token>;\n}\n\n/**\n * Adapter to allow the use of ordinary functions as TokenProvider.\n *\n * @example\n * const provider = tokenProviderFn(async () => ({ value: 'my-token' }));\n */\nexport function tokenProviderFn(fn: () => Promise<Token>): TokenProvider {\n return {token: fn};\n}\n\n/**\n * Combines TokenProvider and Credentials interfaces.\n */\nexport interface TokenCredentials extends TokenProvider, Credentials {}\n\n/**\n * Creates a TokenCredentials that uses the given TokenProvider to return\n * authentication headers.\n *\n * @param name - Short identifier for the auth strategy (e.g. `oauth-m2m`).\n * @param provider - Source of tokens used to build the Authorization header.\n */\nexport function newTokenCredentials(\n name: string,\n provider: TokenProvider\n): TokenCredentials {\n return new TokenCredentialsImpl(name, provider);\n}\n\nclass TokenCredentialsImpl implements TokenCredentials {\n constructor(\n private readonly strategyName: string,\n private readonly provider: TokenProvider\n ) {}\n\n name(): string {\n return this.strategyName;\n }\n\n async token(): Promise<Token> {\n return this.provider.token();\n }\n\n async authHeaders(): Promise<Header[]> {\n const t = await this.token();\n const scheme = t.type ?? 'Bearer';\n return [{key: 'Authorization', value: `${scheme} ${t.value}`}];\n }\n}\n"],"mappings":";;;;;;;AA0EA,SAAgB,gBAAgB,IAAyC;AACvE,QAAO,EAAC,OAAO,IAAG;;;;;;;;;AAepB,SAAgB,oBACd,MACA,UACkB;AAClB,QAAO,IAAI,qBAAqB,MAAM,SAAS;;AAGjD,IAAM,uBAAN,MAAuD;CACrD,YACE,AAAiB,cACjB,AAAiB,UACjB;EAFiB;EACA;;CAGnB,OAAe;AACb,SAAO,KAAK;;CAGd,MAAM,QAAwB;AAC5B,SAAO,KAAK,SAAS,OAAO;;CAG9B,MAAM,cAAiC;EACrC,MAAM,IAAI,MAAM,KAAK,OAAO;AAE5B,SAAO,CAAC;GAAC,KAAK;GAAiB,OAAO,GADvB,EAAE,QAAQ,SACuB,GAAG,EAAE;GAAQ,CAAC"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Credentials, Header } from "../../auth.js";
|
|
2
|
+
import { Profile } from "@databricks/sdk-core/profiles";
|
|
3
|
+
|
|
4
|
+
//#region src/credentials/default/chain.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* A named strategy that inspects a profile and either returns configured
|
|
5
7
|
* credentials or `undefined` if it is not applicable. The `name` matches the
|
|
6
8
|
* `name()` of the credentials it produces, so it can be selected by a
|
|
7
9
|
* profile's `authType`.
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
interface Strategy {
|
|
12
|
+
/** Short identifier, e.g. `pat`, `oauth-m2m`, or `databricks-cli`. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly configure: (profile: Profile) => Credentials | undefined;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Lazy {@link Credentials} that resolves to a configured strategy on the
|
|
@@ -19,26 +21,28 @@ export interface Strategy {
|
|
|
19
21
|
* selected. Otherwise the strategies are tried in order and the first
|
|
20
22
|
* configured one wins.
|
|
21
23
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
declare class DefaultCredentials implements Credentials {
|
|
25
|
+
private readonly strategies;
|
|
26
|
+
private readonly loadProfile;
|
|
27
|
+
private resolved;
|
|
28
|
+
constructor(strategies: readonly Strategy[], loadProfile: () => Promise<Profile>);
|
|
29
|
+
/**
|
|
30
|
+
* Returns `default` until a strategy has been resolved, then delegates to
|
|
31
|
+
* the resolved strategy so callers (logging, telemetry) can tell which
|
|
32
|
+
* authentication method won.
|
|
33
|
+
*/
|
|
34
|
+
name(): string;
|
|
35
|
+
authHeaders(): Promise<Header[]>;
|
|
36
|
+
private resolveChain;
|
|
37
|
+
private resolveByAuthType;
|
|
36
38
|
}
|
|
37
39
|
/** PAT strategy: configured when `token` is set in the profile. */
|
|
38
|
-
|
|
40
|
+
declare const patStrategy: Strategy;
|
|
39
41
|
/**
|
|
40
42
|
* OAuth M2M strategy: configured when `clientId` and `clientSecret` are
|
|
41
43
|
* both set in the profile.
|
|
42
44
|
*/
|
|
43
|
-
|
|
45
|
+
declare const m2mStrategy: Strategy;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { DefaultCredentials, Strategy, m2mStrategy, patStrategy };
|
|
44
48
|
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.d.ts","
|
|
1
|
+
{"version":3,"file":"chain.d.ts","names":[],"sources":["../../../src/credentials/default/chain.ts"],"mappings":";;;;;;AAcA;;;;UAAiB,QAAA;EAGN;EAAA,SADA,IAAA;EAAA,SACA,SAAA,GAAY,OAAA,EAAS,OAAA,KAAY,WAAA;AAAA;;;AAc5C;;;;;;cAAa,kBAAA,YAA8B,WAAA;EAAA,iBAItB,UAAA;EAAA,iBACA,WAAA;EAAA,QAJX,QAAA;cAGW,UAAA,WAAqB,QAAA,IACrB,WAAA,QAAmB,OAAA,CAAQ,OAAA;EALL;;;;;EAazC,IAAA,CAAA;EAIM,WAAA,CAAA,GAAe,OAAA,CAAQ,MAAA;EAAA,QAKf,YAAA;EAAA,QAiBN,iBAAA;AAAA;;cAoBG,WAAA,EAAa,QAAA;;;;;cAab,WAAA,EAAa,QAAA"}
|
|
@@ -1,91 +1,81 @@
|
|
|
1
|
-
import { newM2mCredentials } from
|
|
2
|
-
import { newPatCredentials } from
|
|
3
|
-
import { DefaultCredentialsError } from
|
|
4
|
-
|
|
1
|
+
import { newM2mCredentials } from "../m2m.js";
|
|
2
|
+
import { newPatCredentials } from "../pat.js";
|
|
3
|
+
import { DefaultCredentialsError } from "./errors.js";
|
|
4
|
+
|
|
5
|
+
//#region src/credentials/default/chain.ts
|
|
6
|
+
const AUTH_DOC_URL = "https://docs.databricks.com/aws/en/dev-tools/auth/index";
|
|
5
7
|
const NO_AUTH_CONFIGURED_MESSAGE = `cannot configure default credentials, please check ${AUTH_DOC_URL} to configure credentials for your preferred authentication method`;
|
|
6
8
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (strategy === undefined) {
|
|
50
|
-
throw new DefaultCredentialsError('AUTH_TYPE_NOT_FOUND', `auth type "${authType}" not found, please check ${AUTH_DOC_URL} for a list of supported auth types`);
|
|
51
|
-
}
|
|
52
|
-
const built = strategy.configure(profile);
|
|
53
|
-
if (built === undefined) {
|
|
54
|
-
throw new DefaultCredentialsError('NO_AUTH_CONFIGURED', NO_AUTH_CONFIGURED_MESSAGE);
|
|
55
|
-
}
|
|
56
|
-
return built;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
9
|
+
* Lazy {@link Credentials} that resolves to a configured strategy on the
|
|
10
|
+
* first `authHeaders()` call.
|
|
11
|
+
*
|
|
12
|
+
* If the profile sets `authType`, the strategy whose name matches it is
|
|
13
|
+
* selected. Otherwise the strategies are tried in order and the first
|
|
14
|
+
* configured one wins.
|
|
15
|
+
*/
|
|
16
|
+
var DefaultCredentials = class {
|
|
17
|
+
resolved;
|
|
18
|
+
constructor(strategies, loadProfile) {
|
|
19
|
+
this.strategies = strategies;
|
|
20
|
+
this.loadProfile = loadProfile;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns `default` until a strategy has been resolved, then delegates to
|
|
24
|
+
* the resolved strategy so callers (logging, telemetry) can tell which
|
|
25
|
+
* authentication method won.
|
|
26
|
+
*/
|
|
27
|
+
name() {
|
|
28
|
+
return this.resolved?.name() ?? "default";
|
|
29
|
+
}
|
|
30
|
+
async authHeaders() {
|
|
31
|
+
this.resolved ??= await this.resolveChain();
|
|
32
|
+
return this.resolved.authHeaders();
|
|
33
|
+
}
|
|
34
|
+
async resolveChain() {
|
|
35
|
+
const profile = await this.loadProfile();
|
|
36
|
+
if (profile.authType !== void 0) return this.resolveByAuthType(profile, profile.authType);
|
|
37
|
+
for (const strategy of this.strategies) {
|
|
38
|
+
const built = strategy.configure(profile);
|
|
39
|
+
if (built !== void 0) return built;
|
|
40
|
+
}
|
|
41
|
+
throw new DefaultCredentialsError("NO_AUTH_CONFIGURED", NO_AUTH_CONFIGURED_MESSAGE);
|
|
42
|
+
}
|
|
43
|
+
resolveByAuthType(profile, authType) {
|
|
44
|
+
const strategy = this.strategies.find((s) => s.name === authType);
|
|
45
|
+
if (strategy === void 0) throw new DefaultCredentialsError("AUTH_TYPE_NOT_FOUND", `auth type "${authType}" not found, please check ${AUTH_DOC_URL} for a list of supported auth types`);
|
|
46
|
+
const built = strategy.configure(profile);
|
|
47
|
+
if (built === void 0) throw new DefaultCredentialsError("NO_AUTH_CONFIGURED", NO_AUTH_CONFIGURED_MESSAGE);
|
|
48
|
+
return built;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
59
51
|
/** PAT strategy: configured when `token` is set in the profile. */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return newPatCredentials(profile.token.value);
|
|
68
|
-
},
|
|
52
|
+
const patStrategy = {
|
|
53
|
+
name: "pat",
|
|
54
|
+
configure: (profile) => {
|
|
55
|
+
if (profile.host === void 0) return void 0;
|
|
56
|
+
if (profile.token === void 0) return void 0;
|
|
57
|
+
return newPatCredentials(profile.token.value);
|
|
58
|
+
}
|
|
69
59
|
};
|
|
70
60
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
...(profile.accountId !== undefined && { accountId: profile.accountId }),
|
|
88
|
-
});
|
|
89
|
-
},
|
|
61
|
+
* OAuth M2M strategy: configured when `clientId` and `clientSecret` are
|
|
62
|
+
* both set in the profile.
|
|
63
|
+
*/
|
|
64
|
+
const m2mStrategy = {
|
|
65
|
+
name: "oauth-m2m",
|
|
66
|
+
configure: (profile) => {
|
|
67
|
+
if (profile.host === void 0) return void 0;
|
|
68
|
+
if (profile.clientId === void 0) return void 0;
|
|
69
|
+
if (profile.clientSecret === void 0) return void 0;
|
|
70
|
+
return newM2mCredentials({
|
|
71
|
+
host: profile.host,
|
|
72
|
+
clientId: profile.clientId,
|
|
73
|
+
clientSecret: profile.clientSecret.value,
|
|
74
|
+
...profile.accountId !== void 0 && { accountId: profile.accountId }
|
|
75
|
+
});
|
|
76
|
+
}
|
|
90
77
|
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { DefaultCredentials, m2mStrategy, patStrategy };
|
|
91
81
|
//# sourceMappingURL=chain.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","
|
|
1
|
+
{"version":3,"file":"chain.js","names":[],"sources":["../../../src/credentials/default/chain.ts"],"sourcesContent":["import type {Profile} from '@databricks/sdk-core/profiles';\n\nimport type {Credentials, Header} from '../../auth';\nimport {newM2mCredentials} from '../m2m';\nimport {newPatCredentials} from '../pat';\n\nimport {DefaultCredentialsError} from './errors';\n\n/**\n * A named strategy that inspects a profile and either returns configured\n * credentials or `undefined` if it is not applicable. The `name` matches the\n * `name()` of the credentials it produces, so it can be selected by a\n * profile's `authType`.\n */\nexport interface Strategy {\n /** Short identifier, e.g. `pat`, `oauth-m2m`, or `databricks-cli`. */\n readonly name: string;\n readonly configure: (profile: Profile) => Credentials | undefined;\n}\n\nconst AUTH_DOC_URL = 'https://docs.databricks.com/aws/en/dev-tools/auth/index';\nconst NO_AUTH_CONFIGURED_MESSAGE = `cannot configure default credentials, please check ${AUTH_DOC_URL} to configure credentials for your preferred authentication method`;\n\n/**\n * Lazy {@link Credentials} that resolves to a configured strategy on the\n * first `authHeaders()` call.\n *\n * If the profile sets `authType`, the strategy whose name matches it is\n * selected. Otherwise the strategies are tried in order and the first\n * configured one wins.\n */\nexport class DefaultCredentials implements Credentials {\n private resolved: Credentials | undefined;\n\n constructor(\n private readonly strategies: readonly Strategy[],\n private readonly loadProfile: () => Promise<Profile>\n ) {}\n\n /**\n * Returns `default` until a strategy has been resolved, then delegates to\n * the resolved strategy so callers (logging, telemetry) can tell which\n * authentication method won.\n */\n name(): string {\n return this.resolved?.name() ?? 'default';\n }\n\n async authHeaders(): Promise<Header[]> {\n this.resolved ??= await this.resolveChain();\n return this.resolved.authHeaders();\n }\n\n private async resolveChain(): Promise<Credentials> {\n const profile = await this.loadProfile();\n if (profile.authType !== undefined) {\n return this.resolveByAuthType(profile, profile.authType);\n }\n for (const strategy of this.strategies) {\n const built = strategy.configure(profile);\n if (built !== undefined) {\n return built;\n }\n }\n throw new DefaultCredentialsError(\n 'NO_AUTH_CONFIGURED',\n NO_AUTH_CONFIGURED_MESSAGE\n );\n }\n\n private resolveByAuthType(profile: Profile, authType: string): Credentials {\n const strategy = this.strategies.find(s => s.name === authType);\n if (strategy === undefined) {\n throw new DefaultCredentialsError(\n 'AUTH_TYPE_NOT_FOUND',\n `auth type \"${authType}\" not found, please check ${AUTH_DOC_URL} for a list of supported auth types`\n );\n }\n const built = strategy.configure(profile);\n if (built === undefined) {\n throw new DefaultCredentialsError(\n 'NO_AUTH_CONFIGURED',\n NO_AUTH_CONFIGURED_MESSAGE\n );\n }\n return built;\n }\n}\n\n/** PAT strategy: configured when `token` is set in the profile. */\nexport const patStrategy: Strategy = {\n name: 'pat',\n configure: profile => {\n if (profile.host === undefined) return undefined;\n if (profile.token === undefined) return undefined;\n return newPatCredentials(profile.token.value);\n },\n};\n\n/**\n * OAuth M2M strategy: configured when `clientId` and `clientSecret` are\n * both set in the profile.\n */\nexport const m2mStrategy: Strategy = {\n name: 'oauth-m2m',\n configure: profile => {\n if (profile.host === undefined) return undefined;\n if (profile.clientId === undefined) return undefined;\n if (profile.clientSecret === undefined) return undefined;\n return newM2mCredentials({\n host: profile.host,\n clientId: profile.clientId,\n clientSecret: profile.clientSecret.value,\n ...(profile.accountId !== undefined && {accountId: profile.accountId}),\n });\n },\n};\n"],"mappings":";;;;;AAoBA,MAAM,eAAe;AACrB,MAAM,6BAA6B,sDAAsD,aAAa;;;;;;;;;AAUtG,IAAa,qBAAb,MAAuD;CACrD,AAAQ;CAER,YACE,AAAiB,YACjB,AAAiB,aACjB;EAFiB;EACA;;;;;;;CAQnB,OAAe;AACb,SAAO,KAAK,UAAU,MAAM,IAAI;;CAGlC,MAAM,cAAiC;AACrC,OAAK,aAAa,MAAM,KAAK,cAAc;AAC3C,SAAO,KAAK,SAAS,aAAa;;CAGpC,MAAc,eAAqC;EACjD,MAAM,UAAU,MAAM,KAAK,aAAa;AACxC,MAAI,QAAQ,aAAa,OACvB,QAAO,KAAK,kBAAkB,SAAS,QAAQ,SAAS;AAE1D,OAAK,MAAM,YAAY,KAAK,YAAY;GACtC,MAAM,QAAQ,SAAS,UAAU,QAAQ;AACzC,OAAI,UAAU,OACZ,QAAO;;AAGX,QAAM,IAAI,wBACR,sBACA,2BACD;;CAGH,AAAQ,kBAAkB,SAAkB,UAA+B;EACzE,MAAM,WAAW,KAAK,WAAW,MAAK,MAAK,EAAE,SAAS,SAAS;AAC/D,MAAI,aAAa,OACf,OAAM,IAAI,wBACR,uBACA,cAAc,SAAS,4BAA4B,aAAa,qCACjE;EAEH,MAAM,QAAQ,SAAS,UAAU,QAAQ;AACzC,MAAI,UAAU,OACZ,OAAM,IAAI,wBACR,sBACA,2BACD;AAEH,SAAO;;;;AAKX,MAAa,cAAwB;CACnC,MAAM;CACN,YAAW,YAAW;AACpB,MAAI,QAAQ,SAAS,OAAW,QAAO;AACvC,MAAI,QAAQ,UAAU,OAAW,QAAO;AACxC,SAAO,kBAAkB,QAAQ,MAAM,MAAM;;CAEhD;;;;;AAMD,MAAa,cAAwB;CACnC,MAAM;CACN,YAAW,YAAW;AACpB,MAAI,QAAQ,SAAS,OAAW,QAAO;AACvC,MAAI,QAAQ,aAAa,OAAW,QAAO;AAC3C,MAAI,QAAQ,iBAAiB,OAAW,QAAO;AAC/C,SAAO,kBAAkB;GACvB,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB,cAAc,QAAQ,aAAa;GACnC,GAAI,QAAQ,cAAc,UAAa,EAAC,WAAW,QAAQ,WAAU;GACtE,CAAC;;CAEL"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Credentials } from "../../auth.js";
|
|
2
|
+
import { Profile } from "@databricks/sdk-core/profiles";
|
|
3
|
+
|
|
4
|
+
//#region src/credentials/default/default-credentials.d.ts
|
|
3
5
|
interface DefaultCredentialsOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Pre-resolved profile. When omitted, the profile is resolved on first
|
|
8
|
+
* use from the default config file and environment variables.
|
|
9
|
+
*/
|
|
10
|
+
profile?: Profile;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Returns a lazy {@link Credentials} that resolves to the first configured
|
|
@@ -20,6 +22,7 @@ interface DefaultCredentialsOptions {
|
|
|
20
22
|
* resolved on first use from the default config file (~/.databrickscfg)
|
|
21
23
|
* and environment variables.
|
|
22
24
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
declare function defaultCredentials(options?: DefaultCredentialsOptions): Credentials;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { defaultCredentials };
|
|
25
28
|
//# sourceMappingURL=default-credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-credentials.d.ts","
|
|
1
|
+
{"version":3,"file":"default-credentials.d.ts","names":[],"sources":["../../../src/credentials/default/default-credentials.ts"],"mappings":";;;;UAWU,yBAAA;;AARkC;;;EAa1C,OAAA,GAAU,OAAA;AAAA;AAgBZ;;;;;;;;;;;;;AAAA,iBAAgB,kBAAA,CACd,OAAA,GAAU,yBAAA,GACT,WAAA"}
|
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { DefaultCredentials, m2mStrategy, patStrategy } from "./chain.js";
|
|
2
|
+
import { u2mStrategy } from "./u2m-strategy.js";
|
|
3
|
+
import { resolve } from "@databricks/sdk-core/profiles";
|
|
4
|
+
|
|
5
|
+
//#region src/credentials/default/default-credentials.ts
|
|
6
|
+
const STRATEGIES = [
|
|
7
|
+
patStrategy,
|
|
8
|
+
m2mStrategy,
|
|
9
|
+
u2mStrategy
|
|
10
|
+
];
|
|
5
11
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
* Returns a lazy {@link Credentials} that resolves to the first configured
|
|
13
|
+
* authentication strategy on first use.
|
|
14
|
+
*
|
|
15
|
+
* Strategies are tried in this order:
|
|
16
|
+
* 1. PAT (`pat`).
|
|
17
|
+
* 2. OAuth M2M (`oauth-m2m`).
|
|
18
|
+
* 3. Databricks CLI (`databricks-cli`).
|
|
19
|
+
*
|
|
20
|
+
* When no profile is provided via `options.profile`, the profile is
|
|
21
|
+
* resolved on first use from the default config file (~/.databrickscfg)
|
|
22
|
+
* and environment variables.
|
|
23
|
+
*/
|
|
24
|
+
function defaultCredentials(options) {
|
|
25
|
+
const explicit = options?.profile;
|
|
26
|
+
const loadProfile = () => explicit !== void 0 ? Promise.resolve(explicit) : resolve();
|
|
27
|
+
return new DefaultCredentials(STRATEGIES, loadProfile);
|
|
22
28
|
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { defaultCredentials };
|
|
23
32
|
//# sourceMappingURL=default-credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-credentials.js","
|
|
1
|
+
{"version":3,"file":"default-credentials.js","names":[],"sources":["../../../src/credentials/default/default-credentials.ts"],"sourcesContent":["import type {Profile} from '@databricks/sdk-core/profiles';\nimport {resolve} from '@databricks/sdk-core/profiles';\n\nimport type {Credentials} from '../../auth';\n\nimport {DefaultCredentials, m2mStrategy, patStrategy} from './chain';\nimport type {Strategy} from './chain';\nimport {u2mStrategy} from './u2m-strategy';\n\nconst STRATEGIES: readonly Strategy[] = [patStrategy, m2mStrategy, u2mStrategy];\n\ninterface DefaultCredentialsOptions {\n /**\n * Pre-resolved profile. When omitted, the profile is resolved on first\n * use from the default config file and environment variables.\n */\n profile?: Profile;\n}\n\n/**\n * Returns a lazy {@link Credentials} that resolves to the first configured\n * authentication strategy on first use.\n *\n * Strategies are tried in this order:\n * 1. PAT (`pat`).\n * 2. OAuth M2M (`oauth-m2m`).\n * 3. Databricks CLI (`databricks-cli`).\n *\n * When no profile is provided via `options.profile`, the profile is\n * resolved on first use from the default config file (~/.databrickscfg)\n * and environment variables.\n */\nexport function defaultCredentials(\n options?: DefaultCredentialsOptions\n): Credentials {\n const explicit = options?.profile;\n const loadProfile = (): Promise<Profile> =>\n explicit !== undefined ? Promise.resolve(explicit) : resolve();\n return new DefaultCredentials(STRATEGIES, loadProfile);\n}\n"],"mappings":";;;;;AASA,MAAM,aAAkC;CAAC;CAAa;CAAa;CAAY;;;;;;;;;;;;;;AAuB/E,SAAgB,mBACd,SACa;CACb,MAAM,WAAW,SAAS;CAC1B,MAAM,oBACJ,aAAa,SAAY,QAAQ,QAAQ,SAAS,GAAG,SAAS;AAChE,QAAO,IAAI,mBAAmB,YAAY,YAAY"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
//#region src/credentials/default/errors.d.ts
|
|
1
2
|
/** Discriminant codes for {@link DefaultCredentialsError}. */
|
|
2
|
-
|
|
3
|
+
type DefaultCredentialsErrorCode = 'NO_AUTH_CONFIGURED' | 'AUTH_TYPE_NOT_FOUND';
|
|
3
4
|
/**
|
|
4
5
|
* Error thrown when the default credentials chain cannot resolve a
|
|
5
6
|
* strategy to authenticate with.
|
|
6
7
|
*
|
|
7
8
|
* Use the `code` field to distinguish between error causes.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
declare class DefaultCredentialsError extends Error {
|
|
11
|
+
readonly code: DefaultCredentialsErrorCode;
|
|
12
|
+
constructor(code: DefaultCredentialsErrorCode, message: string);
|
|
12
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DefaultCredentialsError, DefaultCredentialsErrorCode };
|
|
13
16
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/credentials/default/errors.ts"],"mappings":";;KACY,2BAAA;;;;;AAUZ;;cAAa,uBAAA,SAAgC,KAAA;EAAA,SAClC,IAAA,EAAM,2BAAA;cAEH,IAAA,EAAM,2BAAA,EAA6B,OAAA;AAAA"}
|