@dbx-tools/auth 0.9.31 → 0.9.36
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/README.md +49 -97
- package/index.ts +8 -26
- package/lib/index.d.ts +8 -26
- package/lib/index.js +6 -22
- package/lib/src/{databricks-cli.d.ts → _databricks-cli.d.ts} +3 -7
- package/lib/src/_databricks-cli.js +172 -0
- package/lib/src/_errors.d.ts +5 -0
- package/lib/src/_errors.js +10 -0
- package/lib/src/{lifecycle.d.ts → _lifecycle.d.ts} +5 -5
- package/lib/src/_lifecycle.js +214 -0
- package/lib/src/_logging.d.ts +1 -1
- package/lib/src/_logging.js +2 -2
- package/lib/src/{personal-access-token.d.ts → _personal-access-token.d.ts} +1 -1
- package/lib/src/_personal-access-token.js +30 -0
- package/lib/src/_profile-config.d.ts +43 -0
- package/lib/src/_profile-config.js +443 -0
- package/lib/src/{service-principal.d.ts → _service-principal.d.ts} +1 -1
- package/lib/src/_service-principal.js +69 -0
- package/lib/src/{storage.d.ts → _storage.d.ts} +4 -6
- package/lib/src/_storage.js +94 -0
- package/lib/src/_types.d.ts +40 -0
- package/lib/src/_types.js +2 -0
- package/lib/src/client.d.ts +30 -0
- package/lib/src/client.js +223 -0
- package/lib/src/config.d.ts +36 -0
- package/lib/src/config.js +15 -0
- package/lib/src/profile.d.ts +11 -0
- package/lib/src/profile.js +21 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -10
- package/src/{databricks-cli.ts → _databricks-cli.ts} +20 -109
- package/src/_errors.ts +11 -0
- package/src/{lifecycle.ts → _lifecycle.ts} +24 -48
- package/src/_logging.ts +2 -2
- package/src/{personal-access-token.ts → _personal-access-token.ts} +1 -1
- package/src/_profile-config.ts +545 -0
- package/src/{service-principal.ts → _service-principal.ts} +2 -2
- package/src/_storage.ts +109 -0
- package/src/_types.ts +45 -0
- package/src/client.ts +291 -0
- package/src/config.ts +44 -0
- package/src/profile.ts +33 -0
- package/lib/exports.d.ts +0 -2
- package/lib/exports.js +0 -3
- package/lib/src/_profile-core.d.ts +0 -28
- package/lib/src/_profile-core.js +0 -216
- package/lib/src/_profile.d.ts +0 -15
- package/lib/src/_profile.js +0 -236
- package/lib/src/databricks-auth.d.ts +0 -11
- package/lib/src/databricks-auth.js +0 -314
- package/lib/src/databricks-cli.js +0 -239
- package/lib/src/errors.d.ts +0 -7
- package/lib/src/errors.js +0 -14
- package/lib/src/generated/databricks-cli-assets.json +0 -33
- package/lib/src/http-client.d.ts +0 -23
- package/lib/src/http-client.js +0 -116
- package/lib/src/lifecycle.js +0 -229
- package/lib/src/node-storage.d.ts +0 -20
- package/lib/src/node-storage.js +0 -207
- package/lib/src/personal-access-token.js +0 -30
- package/lib/src/service-principal.js +0 -69
- package/lib/src/storage.js +0 -98
- package/lib/src/types.d.ts +0 -157
- package/lib/src/types.js +0 -67
- package/src/_profile-core.ts +0 -258
- package/src/_profile.ts +0 -319
- package/src/databricks-auth.ts +0 -416
- package/src/errors.ts +0 -16
- package/src/generated/databricks-cli-assets.json +0 -33
- package/src/http-client.ts +0 -147
- package/src/node-storage.ts +0 -230
- package/src/storage.ts +0 -104
- package/src/types.ts +0 -188
package/src/_types.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { DatabricksProfileSummary } from "@dbx-tools/shared-auth/profile";
|
|
2
|
+
|
|
3
|
+
/** Stored OAuth credential with renewal metadata. */
|
|
4
|
+
export interface Token {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
tokenType: string;
|
|
7
|
+
refreshToken?: string;
|
|
8
|
+
expiry?: string;
|
|
9
|
+
scopes: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Resolved profile with secrets retained for provider construction. */
|
|
13
|
+
export interface DatabricksProfile extends DatabricksProfileSummary {
|
|
14
|
+
host: string;
|
|
15
|
+
selectedProfile?: string;
|
|
16
|
+
clientId: string;
|
|
17
|
+
groupId?: string;
|
|
18
|
+
scopes: string[];
|
|
19
|
+
clientSecret?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
cacheKey: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Process-local credential lease adapter. */
|
|
25
|
+
export interface LockAdapter {
|
|
26
|
+
acquire(key: string, timeoutMs?: number): Promise<string>;
|
|
27
|
+
release(lease: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Internal credential lifecycle storage. */
|
|
31
|
+
export interface CredentialStore {
|
|
32
|
+
load(key: string): Promise<Token | undefined>;
|
|
33
|
+
save(key: string, token: Token): Promise<void>;
|
|
34
|
+
remove(key: string): Promise<void>;
|
|
35
|
+
acquireLock(key: string, timeoutMs?: number): Promise<string>;
|
|
36
|
+
releaseLock(lease: string): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Provider-specific token acquisition. */
|
|
40
|
+
export interface TokenProvider {
|
|
41
|
+
authenticate(timeoutMs: number): Promise<Token>;
|
|
42
|
+
login(timeoutMs: number): Promise<Token>;
|
|
43
|
+
refresh(token: Token): Promise<Token>;
|
|
44
|
+
canAuthenticateSilently(): boolean;
|
|
45
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import type { DatabricksAuthClientInfo } from "@dbx-tools/shared-auth/client";
|
|
2
|
+
import { AuthType, TargetKind } from "@dbx-tools/shared-auth/config";
|
|
3
|
+
import { DatabricksCliProvider, resolveDatabricksCli } from "./_databricks-cli.ts";
|
|
4
|
+
import { AuthError } from "./_errors.ts";
|
|
5
|
+
import { publicToken, TokenLifecycle } from "./_lifecycle.ts";
|
|
6
|
+
import { authLogger, tokenMetadata } from "./_logging.ts";
|
|
7
|
+
import { DatabricksPersonalAccessTokenProvider } from "./_personal-access-token.ts";
|
|
8
|
+
import { machineScopes, resolveConfigFile, resolveDatabricksProfile } from "./_profile-config.ts";
|
|
9
|
+
import { DatabricksServicePrincipalProvider } from "./_service-principal.ts";
|
|
10
|
+
import { MemoryCredentialStore } from "./_storage.ts";
|
|
11
|
+
import { type DatabricksProfile, type Token, type TokenProvider } from "./_types.ts";
|
|
12
|
+
import {
|
|
13
|
+
AUTH_DEFAULTS,
|
|
14
|
+
type DatabricksAuthOptions,
|
|
15
|
+
DEFAULT_ACCESS_TOKEN_HEADER,
|
|
16
|
+
WORKSPACE_ID_HEADER,
|
|
17
|
+
} from "./config.ts";
|
|
18
|
+
|
|
19
|
+
const logger = authLogger("databricks");
|
|
20
|
+
|
|
21
|
+
/** Public credential result with no refresh token. */
|
|
22
|
+
export interface AccessToken {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
tokenType: string;
|
|
25
|
+
expiry?: string;
|
|
26
|
+
scopes: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Token acquisition controls. */
|
|
30
|
+
export interface TokenOptions {
|
|
31
|
+
/** Permit interactive CLI login when required. */
|
|
32
|
+
login?: boolean;
|
|
33
|
+
/** Bypass a reusable cached token and refresh it. */
|
|
34
|
+
refresh?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** WorkspaceClient-shaped Databricks authentication facade. */
|
|
38
|
+
export interface AuthClient extends DatabricksAuthClientInfo {
|
|
39
|
+
token(options?: TokenOptions): Promise<AccessToken>;
|
|
40
|
+
headers(options?: TokenOptions): Promise<Record<string, string>>;
|
|
41
|
+
logout(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Injectable host capabilities for Databricks authentication. */
|
|
45
|
+
export interface DatabricksAuthDependencies {
|
|
46
|
+
environment?: Readonly<Record<string, string | undefined>>;
|
|
47
|
+
fetch?: typeof globalThis.fetch;
|
|
48
|
+
resolveCli?: () => Promise<string | undefined>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Default Databricks auth facade over the provider-neutral lifecycle. */
|
|
52
|
+
class DefaultAuthClient implements AuthClient {
|
|
53
|
+
readonly profile?: string;
|
|
54
|
+
readonly host: string;
|
|
55
|
+
readonly accountId?: string;
|
|
56
|
+
readonly workspaceId?: string;
|
|
57
|
+
readonly target: TargetKind;
|
|
58
|
+
readonly authType: AuthType;
|
|
59
|
+
readonly principal: string;
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
private readonly profileValue: DatabricksProfile,
|
|
63
|
+
private readonly client?: TokenLifecycle,
|
|
64
|
+
private readonly requestToken?: Token,
|
|
65
|
+
) {
|
|
66
|
+
this.profile = profileValue.selectedProfile;
|
|
67
|
+
this.host = profileValue.host;
|
|
68
|
+
this.accountId = profileValue.accountId;
|
|
69
|
+
this.workspaceId = profileValue.workspaceId;
|
|
70
|
+
this.target = profileValue.target;
|
|
71
|
+
this.authType = profileValue.authType;
|
|
72
|
+
this.principal = profileValue.principal;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
token(options: TokenOptions = {}) {
|
|
76
|
+
logger.debug("Databricks token requested", {
|
|
77
|
+
...this.context(),
|
|
78
|
+
login: options.login ?? "auto",
|
|
79
|
+
refresh: options.refresh ?? false,
|
|
80
|
+
source: this.requestToken ? "request" : "lifecycle",
|
|
81
|
+
});
|
|
82
|
+
if (this.requestToken) return Promise.resolve(publicToken(this.requestToken));
|
|
83
|
+
return options.refresh
|
|
84
|
+
? this.requiredClient().forceRefresh(options.login ?? true)
|
|
85
|
+
: this.requiredClient().tokenWithLogin(options.login);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async headers(options: TokenOptions = {}): Promise<Record<string, string>> {
|
|
89
|
+
const token = await this.token(options);
|
|
90
|
+
const headers = {
|
|
91
|
+
[DEFAULT_ACCESS_TOKEN_HEADER]: `${token.tokenType} ${token.accessToken}`,
|
|
92
|
+
...(this.profileValue.workspaceId
|
|
93
|
+
? { [WORKSPACE_ID_HEADER]: this.profileValue.workspaceId }
|
|
94
|
+
: {}),
|
|
95
|
+
};
|
|
96
|
+
logger.debug("generated Databricks authentication headers", {
|
|
97
|
+
...this.context(),
|
|
98
|
+
headerNames: Object.keys(headers),
|
|
99
|
+
token: tokenMetadata(token),
|
|
100
|
+
});
|
|
101
|
+
return headers;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
logout(): Promise<void> {
|
|
105
|
+
logger.debug("Databricks logout requested", this.context());
|
|
106
|
+
return this.client?.logout() ?? Promise.resolve();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private requiredClient(): TokenLifecycle {
|
|
110
|
+
if (!this.client) throw new AuthError("oauth", "Authentication lifecycle is not available");
|
|
111
|
+
return this.client;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private context(): Record<string, unknown> {
|
|
115
|
+
return {
|
|
116
|
+
profile: this.profileValue.name,
|
|
117
|
+
host: this.profileValue.host,
|
|
118
|
+
authType: this.profileValue.authType,
|
|
119
|
+
hasWorkspaceId: Boolean(this.profileValue.workspaceId),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Create a Databricks authentication client. */
|
|
125
|
+
export async function createAuthClient(
|
|
126
|
+
options: DatabricksAuthOptions = {},
|
|
127
|
+
dependencies: DatabricksAuthDependencies = {},
|
|
128
|
+
): Promise<AuthClient> {
|
|
129
|
+
return createResolvedAuth(options, dependencies);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Resolve a Databricks profile and create its token lifecycle. */
|
|
133
|
+
async function createResolvedAuth(
|
|
134
|
+
options: DatabricksAuthOptions,
|
|
135
|
+
dependencies: DatabricksAuthDependencies,
|
|
136
|
+
): Promise<DefaultAuthClient> {
|
|
137
|
+
const environment = dependencies.environment ?? process.env;
|
|
138
|
+
const profile = resolveDatabricksProfile(options, environment);
|
|
139
|
+
logger.debug("creating Databricks auth", {
|
|
140
|
+
profile: profile.name,
|
|
141
|
+
host: profile.host,
|
|
142
|
+
authType: profile.authType,
|
|
143
|
+
});
|
|
144
|
+
if (profile.authType === AuthType.AppOnBehalfOf) {
|
|
145
|
+
logger.debug("created request-scoped App OBO authentication", {
|
|
146
|
+
profile: profile.name,
|
|
147
|
+
host: profile.host,
|
|
148
|
+
hasWorkspaceId: Boolean(profile.workspaceId),
|
|
149
|
+
});
|
|
150
|
+
return new DefaultAuthClient(profile, undefined, {
|
|
151
|
+
accessToken: profile.accessToken!,
|
|
152
|
+
tokenType: "Bearer",
|
|
153
|
+
scopes: [...profile.scopes],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const provider = await providerFor(profile, options, dependencies);
|
|
157
|
+
const store = new MemoryCredentialStore();
|
|
158
|
+
const client = new TokenLifecycle(profile.cacheKey, provider, store, {
|
|
159
|
+
...AUTH_DEFAULTS,
|
|
160
|
+
...options.auth,
|
|
161
|
+
});
|
|
162
|
+
const auth = new DefaultAuthClient(profile, client);
|
|
163
|
+
logger.debug("created authentication lifecycle", {
|
|
164
|
+
profile: profile.name,
|
|
165
|
+
host: profile.host,
|
|
166
|
+
authType: profile.authType,
|
|
167
|
+
});
|
|
168
|
+
return auth;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function providerFor(
|
|
172
|
+
profile: DatabricksProfile,
|
|
173
|
+
options: DatabricksAuthOptions,
|
|
174
|
+
dependencies: DatabricksAuthDependencies,
|
|
175
|
+
): Promise<TokenProvider> {
|
|
176
|
+
const environment = dependencies.environment ?? process.env;
|
|
177
|
+
switch (profile.authType) {
|
|
178
|
+
case AuthType.DatabricksCli: {
|
|
179
|
+
logger.debug("selected Databricks CLI provider", { profile: profile.name });
|
|
180
|
+
return new DatabricksCliProvider(
|
|
181
|
+
profile.name,
|
|
182
|
+
() =>
|
|
183
|
+
dependencies.resolveCli ? dependencies.resolveCli() : resolveDatabricksCli(environment),
|
|
184
|
+
cliEnvironment(profile, resolveConfigFile(options.configFile, environment)),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
case AuthType.PersonalAccessToken:
|
|
188
|
+
logger.debug("selected personal access token provider", { profile: profile.name });
|
|
189
|
+
return new DatabricksPersonalAccessTokenProvider(profile.accessToken!);
|
|
190
|
+
case AuthType.OAuthM2M:
|
|
191
|
+
case AuthType.AppServicePrincipal: {
|
|
192
|
+
logger.debug("selected service-principal provider", {
|
|
193
|
+
profile: profile.name,
|
|
194
|
+
authType: profile.authType,
|
|
195
|
+
target: profile.target,
|
|
196
|
+
});
|
|
197
|
+
const endpoints = await resolveOAuthEndpoints(profile, dependencies.fetch);
|
|
198
|
+
return new DatabricksServicePrincipalProvider({
|
|
199
|
+
tokenEndpoint: endpoints.tokenEndpoint,
|
|
200
|
+
clientId: profile.clientId,
|
|
201
|
+
clientSecret: profile.clientSecret!,
|
|
202
|
+
scopes: machineScopes(profile.scopes),
|
|
203
|
+
...(profile.groupId ? { groupId: profile.groupId } : {}),
|
|
204
|
+
allowInsecureRequests: isLoopbackHttp(profile.host),
|
|
205
|
+
fetch: dependencies.fetch,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
case AuthType.AppOnBehalfOf:
|
|
209
|
+
throw new AuthError("config", "App OBO tokens do not use a token provider");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface AuthorizationServer {
|
|
214
|
+
tokenEndpoint: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function resolveOAuthEndpoints(
|
|
218
|
+
profile: DatabricksProfile,
|
|
219
|
+
fetcher: typeof globalThis.fetch = globalThis.fetch,
|
|
220
|
+
): Promise<AuthorizationServer> {
|
|
221
|
+
const host = profile.host.replace(/\/$/, "");
|
|
222
|
+
if (profile.target === TargetKind.Account) {
|
|
223
|
+
if (!profile.accountId) throw new AuthError("config", "Account target requires account_id");
|
|
224
|
+
const endpoints = {
|
|
225
|
+
tokenEndpoint: `${host}/oidc/accounts/${profile.accountId}/v1/token`,
|
|
226
|
+
};
|
|
227
|
+
logger.debug("resolved account OAuth endpoint", {
|
|
228
|
+
profile: profile.name,
|
|
229
|
+
tokenOrigin: new URL(endpoints.tokenEndpoint).origin,
|
|
230
|
+
});
|
|
231
|
+
return endpoints;
|
|
232
|
+
}
|
|
233
|
+
const discovery =
|
|
234
|
+
profile.target === TargetKind.Unified
|
|
235
|
+
? `${host}/oidc/accounts/${requiredAccountId(profile)}/.well-known/oauth-authorization-server`
|
|
236
|
+
: `${host}/oidc/.well-known/oauth-authorization-server`;
|
|
237
|
+
logger.debug("requesting OAuth discovery", {
|
|
238
|
+
profile: profile.name,
|
|
239
|
+
target: profile.target,
|
|
240
|
+
discovery,
|
|
241
|
+
});
|
|
242
|
+
const response = await fetcher(discovery, { redirect: "manual" });
|
|
243
|
+
logger.debug("received OAuth discovery response", {
|
|
244
|
+
profile: profile.name,
|
|
245
|
+
status: response.status,
|
|
246
|
+
});
|
|
247
|
+
if (response.status === 404) {
|
|
248
|
+
throw new AuthError("oauth", `OAuth is not supported at ${discovery}`);
|
|
249
|
+
}
|
|
250
|
+
if (!response.ok) {
|
|
251
|
+
throw new AuthError("oauth", `OAuth discovery returned HTTP ${response.status}`);
|
|
252
|
+
}
|
|
253
|
+
const value = (await response.json()) as Record<string, unknown>;
|
|
254
|
+
const tokenEndpoint = stringValue(value.token_endpoint);
|
|
255
|
+
if (!tokenEndpoint) throw new AuthError("oauth", "OAuth discovery response is incomplete");
|
|
256
|
+
logger.debug("resolved OAuth token endpoint", {
|
|
257
|
+
profile: profile.name,
|
|
258
|
+
tokenOrigin: new URL(tokenEndpoint).origin,
|
|
259
|
+
});
|
|
260
|
+
return { tokenEndpoint };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function requiredAccountId(profile: DatabricksProfile): string {
|
|
264
|
+
if (!profile.accountId) throw new AuthError("config", "Unified target requires account_id");
|
|
265
|
+
return profile.accountId;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function isLoopbackHttp(host: string): boolean {
|
|
269
|
+
const url = new URL(host);
|
|
270
|
+
return url.protocol === "http:" && ["127.0.0.1", "localhost"].includes(url.hostname);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cliEnvironment(profile: DatabricksProfile, configFile: string): Record<string, string> {
|
|
274
|
+
return {
|
|
275
|
+
DATABRICKS_CONFIG_FILE: configFile,
|
|
276
|
+
DATABRICKS_CONFIG_PROFILE: profile.name,
|
|
277
|
+
DATABRICKS_HOST: profile.host,
|
|
278
|
+
...(profile.accountId ? { DATABRICKS_ACCOUNT_ID: profile.accountId } : {}),
|
|
279
|
+
...(profile.workspaceId ? { DATABRICKS_WORKSPACE_ID: profile.workspaceId } : {}),
|
|
280
|
+
...(profile.authType === AuthType.PersonalAccessToken
|
|
281
|
+
? {
|
|
282
|
+
DATABRICKS_AUTH_TYPE: "pat",
|
|
283
|
+
DATABRICKS_TOKEN: profile.accessToken!,
|
|
284
|
+
}
|
|
285
|
+
: {}),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function stringValue(value: unknown): string | undefined {
|
|
290
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
291
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AuthType, TargetKind } from "@dbx-tools/shared-auth/config";
|
|
2
|
+
|
|
3
|
+
/** Token lifecycle timing configuration in milliseconds. */
|
|
4
|
+
export interface AuthOptions {
|
|
5
|
+
refreshBufferMs?: number;
|
|
6
|
+
lockTimeoutMs?: number;
|
|
7
|
+
loginTimeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Default token refresh, lock, and interactive login timing values. */
|
|
11
|
+
export const AUTH_DEFAULTS: Required<AuthOptions> = {
|
|
12
|
+
refreshBufferMs: 300_000,
|
|
13
|
+
lockTimeoutMs: 0,
|
|
14
|
+
loginTimeoutMs: 900_000,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Databricks profile and credential-source options. */
|
|
18
|
+
export interface DatabricksAuthOptions {
|
|
19
|
+
profile?: string;
|
|
20
|
+
host?: string;
|
|
21
|
+
accountId?: string;
|
|
22
|
+
workspaceId?: string;
|
|
23
|
+
configFile?: string;
|
|
24
|
+
clientId?: string;
|
|
25
|
+
clientSecret?: string;
|
|
26
|
+
accessToken?: string;
|
|
27
|
+
groupId?: string;
|
|
28
|
+
authType?: AuthType;
|
|
29
|
+
scopes?: string[];
|
|
30
|
+
target?: TargetKind;
|
|
31
|
+
auth?: AuthOptions;
|
|
32
|
+
requestHeaders?: Record<string, string>;
|
|
33
|
+
accessTokenHeader?: string;
|
|
34
|
+
preferUserToMachine?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** OAuth client used by Databricks CLI-compatible user authentication. */
|
|
38
|
+
export const DEFAULT_CLIENT_ID = "databricks-cli";
|
|
39
|
+
/** Default Databricks profile configuration path. */
|
|
40
|
+
export const DEFAULT_CONFIG_FILE = "~/.databrickscfg";
|
|
41
|
+
/** Request header carrying a bearer access token. */
|
|
42
|
+
export const DEFAULT_ACCESS_TOKEN_HEADER = "authorization";
|
|
43
|
+
/** Request header carrying the resolved Databricks workspace ID. */
|
|
44
|
+
export const WORKSPACE_ID_HEADER = "x-databricks-workspace-id";
|
package/src/profile.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DatabricksProfileSummary } from "@dbx-tools/shared-auth/profile";
|
|
2
|
+
|
|
3
|
+
import { listDatabricksProfiles, resolveDatabricksProfile } from "./_profile-config.ts";
|
|
4
|
+
import type { DatabricksProfile } from "./_types.ts";
|
|
5
|
+
import type { DatabricksAuthOptions } from "./config.ts";
|
|
6
|
+
|
|
7
|
+
/** Profile-listing controls. */
|
|
8
|
+
export interface ListProfilesOptions {
|
|
9
|
+
configFile?: string;
|
|
10
|
+
refresh?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Resolve one selected profile without exposing credentials. */
|
|
14
|
+
export function resolveProfile(options: DatabricksAuthOptions = {}): DatabricksProfileSummary {
|
|
15
|
+
return toProfileSummary(resolveDatabricksProfile(options));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** List configured profiles without exposing credentials. */
|
|
19
|
+
export function listProfiles(options: ListProfilesOptions = {}): DatabricksProfileSummary[] {
|
|
20
|
+
return listDatabricksProfiles(options.configFile, options.refresh);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toProfileSummary(profile: DatabricksProfile): DatabricksProfileSummary {
|
|
24
|
+
return {
|
|
25
|
+
name: profile.name,
|
|
26
|
+
host: profile.host,
|
|
27
|
+
...(profile.accountId ? { accountId: profile.accountId } : {}),
|
|
28
|
+
...(profile.workspaceId ? { workspaceId: profile.workspaceId } : {}),
|
|
29
|
+
target: profile.target,
|
|
30
|
+
authType: profile.authType,
|
|
31
|
+
principal: profile.principal,
|
|
32
|
+
};
|
|
33
|
+
}
|
package/lib/exports.d.ts
DELETED
package/lib/exports.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { createAuthClient } from "./src/databricks-auth.js";
|
|
2
|
-
export { AuthOptions, DatabricksAuthOptions } from "./src/types.js";
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhwb3J0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL2V4cG9ydHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDNUQsT0FBTyxFQUFFLFdBQVcsRUFBRSxxQkFBcUIsRUFBRSxNQUFNLGdCQUFnQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHsgY3JlYXRlQXV0aENsaWVudCB9IGZyb20gXCIuL3NyYy9kYXRhYnJpY2tzLWF1dGgudHNcIjtcbmV4cG9ydCB7IEF1dGhPcHRpb25zLCBEYXRhYnJpY2tzQXV0aE9wdGlvbnMgfSBmcm9tIFwiLi9zcmMvdHlwZXMudHNcIjtcbiJdfQ==
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AuthKind, TargetKind } from "./types.ts";
|
|
2
|
-
export declare const SETTINGS_SECTION = "__settings__";
|
|
3
|
-
export type Environment = Readonly<Record<string, string | undefined>>;
|
|
4
|
-
export type IniConfig = Map<string, Map<string, string>>;
|
|
5
|
-
export interface RawProfile {
|
|
6
|
-
host?: string;
|
|
7
|
-
accountId?: string;
|
|
8
|
-
workspaceId?: string;
|
|
9
|
-
clientId?: string;
|
|
10
|
-
clientSecret?: string;
|
|
11
|
-
accessToken?: string;
|
|
12
|
-
groupId?: string;
|
|
13
|
-
scopes?: string;
|
|
14
|
-
authType?: string;
|
|
15
|
-
}
|
|
16
|
-
/** Parse Databricks INI text through the maintained `ini` package. */
|
|
17
|
-
export declare function parseDatabricksConfig(source: string): IniConfig;
|
|
18
|
-
export declare function loadRawProfile(config: IniConfig | undefined, name: string): RawProfile;
|
|
19
|
-
export declare function resolveProfileName(requested: string | undefined, explicit: boolean, config: IniConfig | undefined, preferUserToMachine: boolean): string;
|
|
20
|
-
/** Normalize Databricks hosts and require TLS outside loopback development. */
|
|
21
|
-
export declare function normalizeHost(value: string | undefined, profile?: string): string;
|
|
22
|
-
export declare function resolveAuthKind(authType: string | undefined, clientId: string | undefined, clientSecret: string | undefined, accessToken: string | undefined): AuthKind;
|
|
23
|
-
export declare function requestOboToken(headers?: Record<string, string>, headerName?: string): string | undefined;
|
|
24
|
-
export declare function inferTarget(host: string | undefined, accountId: string | undefined): TargetKind;
|
|
25
|
-
export declare function parseTarget(value: string): TargetKind;
|
|
26
|
-
export declare function cleanList(values: readonly string[]): string[];
|
|
27
|
-
export declare function nonempty(value: string | undefined): string | undefined;
|
|
28
|
-
export declare function missing(profile: string, field: string): never;
|