@databricks/sdk-core 0.33.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/apierror/apierror.d.ts +52 -49
- package/dist/apierror/apierror.d.ts.map +1 -1
- package/dist/apierror/apierror.js +124 -172
- package/dist/apierror/apierror.js.map +1 -1
- package/dist/apierror/codes/codes.d.ts +113 -113
- package/dist/apierror/codes/codes.d.ts.map +1 -1
- package/dist/apierror/codes/codes.js +24 -115
- package/dist/apierror/codes/codes.js.map +1 -1
- package/dist/apierror/codes/index.d.ts +2 -7
- package/dist/apierror/codes/index.js +3 -7
- package/dist/apierror/details.d.ts +104 -101
- package/dist/apierror/details.d.ts.map +1 -1
- package/dist/apierror/details.js +151 -226
- package/dist/apierror/details.js.map +1 -1
- package/dist/apierror/index.d.ts +3 -8
- package/dist/apierror/index.js +3 -7
- package/dist/clientinfo/agent.d.ts +6 -3
- package/dist/clientinfo/agent.d.ts.map +1 -1
- package/dist/clientinfo/agent.js +134 -112
- package/dist/clientinfo/agent.js.map +1 -1
- package/dist/clientinfo/base.d.ts +13 -15
- package/dist/clientinfo/base.d.ts.map +1 -1
- package/dist/clientinfo/base.js +50 -50
- package/dist/clientinfo/base.js.map +1 -1
- package/dist/clientinfo/clientinfo.d.ts +40 -38
- package/dist/clientinfo/clientinfo.d.ts.map +1 -1
- package/dist/clientinfo/clientinfo.js +78 -88
- package/dist/clientinfo/clientinfo.js.map +1 -1
- package/dist/clientinfo/default.browser.d.ts +6 -10
- package/dist/clientinfo/default.browser.d.ts.map +1 -1
- package/dist/clientinfo/default.browser.js +24 -16
- package/dist/clientinfo/default.browser.js.map +1 -1
- package/dist/clientinfo/default.d.ts +8 -4
- package/dist/clientinfo/default.d.ts.map +1 -1
- package/dist/clientinfo/default.js +157 -102
- package/dist/clientinfo/default.js.map +1 -1
- package/dist/clientinfo/index.browser.d.ts +4 -5
- package/dist/clientinfo/index.browser.js +5 -4
- package/dist/clientinfo/index.d.ts +4 -5
- package/dist/clientinfo/index.js +5 -4
- package/dist/clientinfo/meta-harness.d.ts +6 -3
- package/dist/clientinfo/meta-harness.d.ts.map +1 -1
- package/dist/clientinfo/meta-harness.js +30 -46
- package/dist/clientinfo/meta-harness.js.map +1 -1
- package/dist/http/http.d.ts +25 -22
- package/dist/http/http.d.ts.map +1 -1
- package/dist/http/http.js +24 -34
- package/dist/http/http.js.map +1 -1
- package/dist/http/index.d.ts +2 -8
- package/dist/http/index.js +3 -7
- package/dist/index.d.ts +1 -6
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +2 -8
- package/dist/logger/index.js +3 -7
- package/dist/logger/logger.d.ts +26 -23
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +46 -60
- package/dist/logger/logger.js.map +1 -1
- package/dist/ops/execute.d.ts +7 -3
- package/dist/ops/execute.d.ts.map +1 -1
- package/dist/ops/execute.js +55 -67
- package/dist/ops/execute.js.map +1 -1
- package/dist/ops/index.d.ts +5 -12
- package/dist/ops/index.js +4 -9
- package/dist/ops/limiter.d.ts +5 -2
- package/dist/ops/limiter.d.ts.map +1 -1
- package/dist/ops/limiter.js +0 -2
- package/dist/ops/options.d.ts +23 -19
- package/dist/ops/options.d.ts.map +1 -1
- package/dist/ops/options.js +0 -2
- package/dist/ops/retrier.d.ts +34 -31
- package/dist/ops/retrier.d.ts.map +1 -1
- package/dist/ops/retrier.js +55 -66
- package/dist/ops/retrier.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/profiles/errors.d.ts +7 -4
- package/dist/profiles/errors.d.ts.map +1 -1
- package/dist/profiles/errors.js +16 -17
- package/dist/profiles/errors.js.map +1 -1
- package/dist/profiles/index.browser.d.ts +4 -10
- package/dist/profiles/index.browser.js +4 -8
- package/dist/profiles/index.d.ts +5 -15
- package/dist/profiles/index.js +5 -13
- package/dist/profiles/ini.d.ts +6 -3
- package/dist/profiles/ini.d.ts.map +1 -1
- package/dist/profiles/ini.js +60 -108
- package/dist/profiles/ini.js.map +1 -1
- package/dist/profiles/profile.d.ts +66 -67
- package/dist/profiles/profile.d.ts.map +1 -1
- package/dist/profiles/profile.js +89 -84
- package/dist/profiles/profile.js.map +1 -1
- package/dist/profiles/resolve.d.ts +8 -9
- package/dist/profiles/resolve.d.ts.map +1 -1
- package/dist/profiles/resolve.js +140 -185
- package/dist/profiles/resolve.js.map +1 -1
- package/dist/profiles/secret.d.ts +15 -12
- package/dist/profiles/secret.d.ts.map +1 -1
- package/dist/profiles/secret.js +38 -35
- package/dist/profiles/secret.js.map +1 -1
- package/dist/wkt/fieldmask.d.ts +23 -20
- package/dist/wkt/fieldmask.d.ts.map +1 -1
- package/dist/wkt/fieldmask.js +53 -62
- package/dist/wkt/fieldmask.js.map +1 -1
- package/dist/wkt/index.d.ts +3 -4
- package/dist/wkt/index.js +3 -2
- package/dist/wkt/value.d.ts +6 -3
- package/dist/wkt/value.d.ts.map +1 -1
- package/dist/wkt/value.js +0 -2
- package/package.json +2 -2
- package/dist/apierror/codes/index.d.ts.map +0 -1
- package/dist/apierror/codes/index.js.map +0 -1
- package/dist/apierror/index.d.ts.map +0 -1
- package/dist/apierror/index.js.map +0 -1
- package/dist/clientinfo/index.browser.d.ts.map +0 -1
- package/dist/clientinfo/index.browser.js.map +0 -1
- package/dist/clientinfo/index.d.ts.map +0 -1
- package/dist/clientinfo/index.js.map +0 -1
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/ops/index.d.ts.map +0 -1
- package/dist/ops/index.js.map +0 -1
- package/dist/ops/limiter.js.map +0 -1
- package/dist/ops/options.js.map +0 -1
- package/dist/profiles/index.browser.d.ts.map +0 -1
- package/dist/profiles/index.browser.js.map +0 -1
- package/dist/profiles/index.d.ts.map +0 -1
- package/dist/profiles/index.js.map +0 -1
- package/dist/wkt/index.d.ts.map +0 -1
- package/dist/wkt/index.js.map +0 -1
- package/dist/wkt/value.js.map +0 -1
package/dist/profiles/profile.js
CHANGED
|
@@ -1,89 +1,94 @@
|
|
|
1
|
+
import { Secret } from "./secret.js";
|
|
2
|
+
|
|
3
|
+
//#region src/profiles/profile.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { Secret } from './secret';
|
|
5
|
+
* Profile interface and property mapping for Databricks configuration.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
7
9
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* Reserved INI section name for SDK settings. It is never treated as a
|
|
11
|
+
* profile.
|
|
12
|
+
*/
|
|
13
|
+
const SETTINGS_SECTION = "__settings__";
|
|
12
14
|
/**
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
15
|
+
* Declarative property mapping table for all known profile fields.
|
|
16
|
+
*/
|
|
17
|
+
const PROPERTY_DEFS = [
|
|
18
|
+
{
|
|
19
|
+
field: "host",
|
|
20
|
+
envVar: "DATABRICKS_HOST",
|
|
21
|
+
iniKey: "host",
|
|
22
|
+
set: (p, v) => {
|
|
23
|
+
p.host = v;
|
|
24
|
+
},
|
|
25
|
+
get: (p) => p.host
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
field: "workspaceId",
|
|
29
|
+
envVar: "DATABRICKS_WORKSPACE_ID",
|
|
30
|
+
iniKey: "workspace_id",
|
|
31
|
+
set: (p, v) => {
|
|
32
|
+
p.workspaceId = v;
|
|
33
|
+
},
|
|
34
|
+
get: (p) => p.workspaceId
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
field: "accountId",
|
|
38
|
+
envVar: "DATABRICKS_ACCOUNT_ID",
|
|
39
|
+
iniKey: "account_id",
|
|
40
|
+
set: (p, v) => {
|
|
41
|
+
p.accountId = v;
|
|
42
|
+
},
|
|
43
|
+
get: (p) => p.accountId
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
field: "token",
|
|
47
|
+
envVar: "DATABRICKS_TOKEN",
|
|
48
|
+
iniKey: "token",
|
|
49
|
+
set: (p, v) => {
|
|
50
|
+
p.token = new Secret(v);
|
|
51
|
+
},
|
|
52
|
+
get: (p) => p.token?.value
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
field: "authType",
|
|
56
|
+
envVar: "DATABRICKS_AUTH_TYPE",
|
|
57
|
+
iniKey: "auth_type",
|
|
58
|
+
set: (p, v) => {
|
|
59
|
+
p.authType = v;
|
|
60
|
+
},
|
|
61
|
+
get: (p) => p.authType
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
field: "clientId",
|
|
65
|
+
envVar: "DATABRICKS_CLIENT_ID",
|
|
66
|
+
iniKey: "client_id",
|
|
67
|
+
set: (p, v) => {
|
|
68
|
+
p.clientId = v;
|
|
69
|
+
},
|
|
70
|
+
get: (p) => p.clientId
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
field: "clientSecret",
|
|
74
|
+
envVar: "DATABRICKS_CLIENT_SECRET",
|
|
75
|
+
iniKey: "client_secret",
|
|
76
|
+
set: (p, v) => {
|
|
77
|
+
p.clientSecret = new Secret(v);
|
|
78
|
+
},
|
|
79
|
+
get: (p) => p.clientSecret?.value
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
field: "databricksCliPath",
|
|
83
|
+
envVar: "DATABRICKS_CLI_PATH",
|
|
84
|
+
iniKey: "databricks_cli_path",
|
|
85
|
+
set: (p, v) => {
|
|
86
|
+
p.databricksCliPath = v;
|
|
87
|
+
},
|
|
88
|
+
get: (p) => p.databricksCliPath
|
|
89
|
+
}
|
|
88
90
|
];
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { PROPERTY_DEFS, SETTINGS_SECTION };
|
|
89
94
|
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","
|
|
1
|
+
{"version":3,"file":"profile.js","names":[],"sources":["../../src/profiles/profile.ts"],"sourcesContent":["/**\n * Profile interface and property mapping for Databricks configuration.\n *\n * @module\n */\n\nimport {Secret} from './secret';\n\n/**\n * Holds configuration values resolved from a databrickscfg file and/or\n * environment variables. All fields are optional; an absent field means the\n * value was not configured.\n */\nexport interface Profile {\n /** Profile name (INI section name). */\n name?: string;\n\n /** Databricks workspace or Accounts API endpoint URL. */\n host?: string;\n\n /**\n * Databricks Workspace ID, used with unified hosts. Accepts either a classic\n * numeric workspace ID or another workspace identifier format that the server\n * understands.\n */\n workspaceId?: string;\n\n /** Databricks Account ID for Accounts API. */\n accountId?: string;\n\n /** Personal access token for PAT authentication. */\n token?: Secret;\n\n /** Selects a specific auth method when multiple credentials are available. */\n authType?: string;\n\n /** OAuth client ID for M2M authentication. */\n clientId?: string;\n\n /** OAuth client secret for M2M authentication. */\n clientSecret?: Secret;\n\n /** Path to the Databricks CLI binary (>= 0.100.0) for CLI-based auth. */\n databricksCliPath?: string;\n\n /**\n * INI keys not mapped to a known field. Only populated when loading from a\n * config file; environment variables do not contribute to extra.\n */\n extra?: Record<string, string>;\n}\n\n/**\n * Configures how a profile is resolved by {@link resolve}.\n *\n * Resolution is enabled by default: with no options, {@link resolve} reads the\n * config file and overlays DATABRICKS_* environment variables on top. Each\n * source can be disabled independently with {@link ProfileOptions.noProfile}\n * and {@link ProfileOptions.disableEnv}.\n */\nexport interface ProfileOptions {\n /**\n * Profile name (INI section) to load. If not set, resolves from the\n * DATABRICKS_CONFIG_PROFILE environment variable, then the default_profile\n * key in the __settings__ section, then falls back to the DEFAULT section.\n */\n profile?: string;\n\n /**\n * Path to the databrickscfg file. If not set, reads DATABRICKS_CONFIG_FILE\n * from the environment, falling back to ~/.databrickscfg.\n */\n configFile?: string;\n\n /**\n * Disable reading the config file. Cannot be combined with\n * {@link ProfileOptions.profile} or {@link ProfileOptions.configFile},\n * which would have nothing to read.\n */\n noProfile?: boolean;\n\n /**\n * Disable overlaying DATABRICKS_* environment variables.\n */\n disableEnv?: boolean;\n}\n\n/**\n * Reserved INI section name for SDK settings. It is never treated as a\n * profile.\n */\nexport const SETTINGS_SECTION = '__settings__';\n\n// ---------------------------------------------------------------------------\n// Declarative property mapping\n// ---------------------------------------------------------------------------\n\n/**\n * Maps a {@link Profile} field to its environment variable and INI key,\n * with typed getter and setter closures. This avoids reflection while\n * keeping the mapping declarative, matching the Go SDK's approach.\n */\nexport interface PropertyDef {\n /** The Profile field name this property maps to. */\n readonly field: keyof Profile;\n readonly envVar: string;\n readonly iniKey: string;\n /** Sets the profile field from a raw INI/env string value. */\n readonly set: (profile: Profile, raw: string) => void;\n /** Returns the profile field as a string, or undefined if unset. */\n readonly get: (profile: Profile) => string | undefined;\n}\n\n/**\n * Declarative property mapping table for all known profile fields.\n */\nexport const PROPERTY_DEFS: readonly PropertyDef[] = [\n {\n field: 'host',\n envVar: 'DATABRICKS_HOST',\n iniKey: 'host',\n set: (p: Profile, v: string): void => {\n p.host = v;\n },\n get: (p: Profile): string | undefined => p.host,\n },\n {\n field: 'workspaceId',\n envVar: 'DATABRICKS_WORKSPACE_ID',\n iniKey: 'workspace_id',\n set: (p: Profile, v: string): void => {\n p.workspaceId = v;\n },\n get: (p: Profile): string | undefined => p.workspaceId,\n },\n {\n field: 'accountId',\n envVar: 'DATABRICKS_ACCOUNT_ID',\n iniKey: 'account_id',\n set: (p: Profile, v: string): void => {\n p.accountId = v;\n },\n get: (p: Profile): string | undefined => p.accountId,\n },\n {\n field: 'token',\n envVar: 'DATABRICKS_TOKEN',\n iniKey: 'token',\n set: (p: Profile, v: string): void => {\n p.token = new Secret(v);\n },\n get: (p: Profile): string | undefined => p.token?.value,\n },\n {\n field: 'authType',\n envVar: 'DATABRICKS_AUTH_TYPE',\n iniKey: 'auth_type',\n set: (p: Profile, v: string): void => {\n p.authType = v;\n },\n get: (p: Profile): string | undefined => p.authType,\n },\n {\n field: 'clientId',\n envVar: 'DATABRICKS_CLIENT_ID',\n iniKey: 'client_id',\n set: (p: Profile, v: string): void => {\n p.clientId = v;\n },\n get: (p: Profile): string | undefined => p.clientId,\n },\n {\n field: 'clientSecret',\n envVar: 'DATABRICKS_CLIENT_SECRET',\n iniKey: 'client_secret',\n set: (p: Profile, v: string): void => {\n p.clientSecret = new Secret(v);\n },\n get: (p: Profile): string | undefined => p.clientSecret?.value,\n },\n {\n field: 'databricksCliPath',\n envVar: 'DATABRICKS_CLI_PATH',\n iniKey: 'databricks_cli_path',\n set: (p: Profile, v: string): void => {\n p.databricksCliPath = v;\n },\n get: (p: Profile): string | undefined => p.databricksCliPath,\n },\n];\n"],"mappings":";;;;;;;;;;;;AA2FA,MAAa,mBAAmB;;;;AAyBhC,MAAa,gBAAwC;CACnD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,OAAO;;EAEX,MAAM,MAAmC,EAAE;EAC5C;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,cAAc;;EAElB,MAAM,MAAmC,EAAE;EAC5C;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,YAAY;;EAEhB,MAAM,MAAmC,EAAE;EAC5C;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,QAAQ,IAAI,OAAO,EAAE;;EAEzB,MAAM,MAAmC,EAAE,OAAO;EACnD;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,WAAW;;EAEf,MAAM,MAAmC,EAAE;EAC5C;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,WAAW;;EAEf,MAAM,MAAmC,EAAE;EAC5C;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,eAAe,IAAI,OAAO,EAAE;;EAEhC,MAAM,MAAmC,EAAE,cAAc;EAC1D;CACD;EACE,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,MAAM,GAAY,MAAoB;AACpC,KAAE,oBAAoB;;EAExB,MAAM,MAAmC,EAAE;EAC5C;CACF"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import type { Profile, ProfileOptions } from './profile';
|
|
1
|
+
import { Profile, ProfileOptions } from "./profile.js";
|
|
2
|
+
|
|
3
|
+
//#region src/profiles/resolve.d.ts
|
|
7
4
|
/**
|
|
8
5
|
* Creates a {@link Profile} from a databrickscfg file and/or environment
|
|
9
6
|
* variables.
|
|
@@ -15,16 +12,18 @@ import type { Profile, ProfileOptions } from './profile';
|
|
|
15
12
|
* {@link ProfileOptions.noProfile} and the environment overlay with
|
|
16
13
|
* {@link ProfileOptions.disableEnv}.
|
|
17
14
|
*/
|
|
18
|
-
|
|
15
|
+
declare function resolve(options?: ProfileOptions): Promise<Profile>;
|
|
19
16
|
/**
|
|
20
17
|
* Returns the path to the default databrickscfg file. Reads
|
|
21
18
|
* DATABRICKS_CONFIG_FILE from the environment, falling back to
|
|
22
19
|
* ~/.databrickscfg.
|
|
23
20
|
*/
|
|
24
|
-
|
|
21
|
+
declare function defaultConfigFile(): string;
|
|
25
22
|
/**
|
|
26
23
|
* Returns the names of all profiles (INI sections) in the given config
|
|
27
24
|
* file. The DEFAULT section is included only if it has keys.
|
|
28
25
|
*/
|
|
29
|
-
|
|
26
|
+
declare function listProfiles(path: string): Promise<string[]>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { defaultConfigFile, listProfiles, resolve };
|
|
30
29
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","names":[],"sources":["../../src/profiles/resolve.ts"],"mappings":";;;;;;;;;;;;;;iBAqLsB,OAAA,CAAQ,OAAA,GAAU,cAAA,GAAiB,OAAA,CAAQ,OAAA;;;;;AA6CjE;iBAZgB,iBAAA,CAAA;;;;;iBAYM,YAAA,CAAa,IAAA,WAAe,OAAA"}
|
package/dist/profiles/resolve.js
CHANGED
|
@@ -1,208 +1,163 @@
|
|
|
1
|
+
import { ProfileError } from "./errors.js";
|
|
2
|
+
import { parseIni } from "./ini.js";
|
|
3
|
+
import { PROPERTY_DEFS, SETTINGS_SECTION } from "./profile.js";
|
|
4
|
+
import { access, readFile } from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/profiles/resolve.ts
|
|
1
9
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { access, readFile } from 'node:fs/promises';
|
|
7
|
-
import { homedir } from 'node:os';
|
|
8
|
-
import { join } from 'node:path';
|
|
9
|
-
import { ProfileError } from './errors';
|
|
10
|
-
import { parseIni } from './ini';
|
|
11
|
-
import { PROPERTY_DEFS, SETTINGS_SECTION } from './profile';
|
|
10
|
+
* Node.js implementation of profile resolution.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
12
14
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
* Reports whether a section is an empty DEFAULT section that should be
|
|
16
|
+
* treated as non-existent.
|
|
17
|
+
*
|
|
18
|
+
* In the INI format, DEFAULT is typically a special fallback section, not a
|
|
19
|
+
* regular section. Databricks historically treats DEFAULT as a regular
|
|
20
|
+
* profile name. An intentionally empty [DEFAULT] section is silently ignored.
|
|
21
|
+
*/
|
|
20
22
|
function isPhantomDefault(name, section) {
|
|
21
|
-
|
|
23
|
+
return name === "DEFAULT" && section.size === 0;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
* Returns ~/.databrickscfg without checking environment variables.
|
|
27
|
+
*/
|
|
26
28
|
function defaultConfigFilePath() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
29
|
+
try {
|
|
30
|
+
return join(homedir(), ".databrickscfg");
|
|
31
|
+
} catch {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
35
|
/** Returns true if the file at the given path exists. */
|
|
35
36
|
async function fileExists(path) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
37
|
+
try {
|
|
38
|
+
await access(path);
|
|
39
|
+
return true;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
* Loads a profile from a databrickscfg file. If filePath is undefined,
|
|
46
|
+
* reads DATABRICKS_CONFIG_FILE from the environment, falling back to
|
|
47
|
+
* ~/.databrickscfg.
|
|
48
|
+
*/
|
|
49
49
|
async function loadFile(filePath, profileName) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new ProfileError('INVALID_PROFILE_NAME', `invalid profile name: "${resolved}" is a reserved section`);
|
|
98
|
-
}
|
|
99
|
-
const explicitProfile = resolved !== undefined;
|
|
100
|
-
resolved ??= 'DEFAULT';
|
|
101
|
-
const section = data.get(resolved);
|
|
102
|
-
if (section === undefined || isPhantomDefault(resolved, section)) {
|
|
103
|
-
if (explicitProfile) {
|
|
104
|
-
throw new ProfileError('PROFILE_NOT_FOUND', `profile not found: "${resolved}" in ${path}`);
|
|
105
|
-
}
|
|
106
|
-
return {};
|
|
107
|
-
}
|
|
108
|
-
// Build profile from section values.
|
|
109
|
-
const profile = { name: resolved };
|
|
110
|
-
const knownKeys = new Set();
|
|
111
|
-
for (const def of PROPERTY_DEFS) {
|
|
112
|
-
knownKeys.add(def.iniKey);
|
|
113
|
-
const value = section.get(def.iniKey);
|
|
114
|
-
if (value !== undefined) {
|
|
115
|
-
def.set(profile, value);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Collect extra keys that are not in the property mapping.
|
|
119
|
-
for (const [key, value] of section) {
|
|
120
|
-
if (!knownKeys.has(key)) {
|
|
121
|
-
profile.extra ??= {};
|
|
122
|
-
profile.extra[key] = value;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return profile;
|
|
50
|
+
let explicitFile = filePath !== void 0;
|
|
51
|
+
let path;
|
|
52
|
+
if (filePath !== void 0) path = filePath;
|
|
53
|
+
else {
|
|
54
|
+
const envPath = process.env.DATABRICKS_CONFIG_FILE ?? "";
|
|
55
|
+
if (envPath !== "") {
|
|
56
|
+
path = envPath;
|
|
57
|
+
explicitFile = true;
|
|
58
|
+
} else path = defaultConfigFilePath();
|
|
59
|
+
}
|
|
60
|
+
if (!await fileExists(path)) {
|
|
61
|
+
if (explicitFile) throw new ProfileError("CONFIG_FILE_NOT_FOUND", `config file not found: ${path}`);
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
const data = parseIni(await readFile(path, "utf8"));
|
|
65
|
+
let resolved = profileName;
|
|
66
|
+
if (resolved === void 0) {
|
|
67
|
+
const envProfile = process.env.DATABRICKS_CONFIG_PROFILE ?? "";
|
|
68
|
+
if (envProfile !== "") resolved = envProfile;
|
|
69
|
+
}
|
|
70
|
+
if (resolved === void 0) {
|
|
71
|
+
const settings = data.get(SETTINGS_SECTION);
|
|
72
|
+
if (settings !== void 0) {
|
|
73
|
+
const dp = settings.get("default_profile") ?? "";
|
|
74
|
+
if (dp !== "") resolved = dp;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (resolved === SETTINGS_SECTION) throw new ProfileError("INVALID_PROFILE_NAME", `invalid profile name: "${resolved}" is a reserved section`);
|
|
78
|
+
const explicitProfile = resolved !== void 0;
|
|
79
|
+
resolved ??= "DEFAULT";
|
|
80
|
+
const section = data.get(resolved);
|
|
81
|
+
if (section === void 0 || isPhantomDefault(resolved, section)) {
|
|
82
|
+
if (explicitProfile) throw new ProfileError("PROFILE_NOT_FOUND", `profile not found: "${resolved}" in ${path}`);
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
const profile = { name: resolved };
|
|
86
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
87
|
+
for (const def of PROPERTY_DEFS) {
|
|
88
|
+
knownKeys.add(def.iniKey);
|
|
89
|
+
const value = section.get(def.iniKey);
|
|
90
|
+
if (value !== void 0) def.set(profile, value);
|
|
91
|
+
}
|
|
92
|
+
for (const [key, value] of section) if (!knownKeys.has(key)) {
|
|
93
|
+
profile.extra ??= {};
|
|
94
|
+
profile.extra[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return profile;
|
|
126
97
|
}
|
|
127
98
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
99
|
+
* Builds a profile from environment variables. Empty environment variables
|
|
100
|
+
* are treated as unset. Returns only the fields that were found.
|
|
101
|
+
*/
|
|
131
102
|
function loadEnv() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
return profile;
|
|
103
|
+
const profile = {};
|
|
104
|
+
for (const def of PROPERTY_DEFS) {
|
|
105
|
+
const value = process.env[def.envVar] ?? "";
|
|
106
|
+
if (value !== "") def.set(profile, value);
|
|
107
|
+
}
|
|
108
|
+
return profile;
|
|
140
109
|
}
|
|
141
110
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const shouldReadEnv = options?.disableEnv !== true;
|
|
165
|
-
const fileProfile = shouldReadFile
|
|
166
|
-
? await loadFile(options?.configFile, options?.profile)
|
|
167
|
-
: {};
|
|
168
|
-
const envProfile = shouldReadEnv ? loadEnv() : {};
|
|
169
|
-
return { ...fileProfile, ...envProfile };
|
|
111
|
+
* Creates a {@link Profile} from a databrickscfg file and/or environment
|
|
112
|
+
* variables.
|
|
113
|
+
*
|
|
114
|
+
* Both sources are read by default: the config file is loaded and DATABRICKS_*
|
|
115
|
+
* environment variables are overlaid on top (env takes precedence). This holds
|
|
116
|
+
* whether or not a specific {@link ProfileOptions.profile} or
|
|
117
|
+
* {@link ProfileOptions.configFile} is given. Disable the config file with
|
|
118
|
+
* {@link ProfileOptions.noProfile} and the environment overlay with
|
|
119
|
+
* {@link ProfileOptions.disableEnv}.
|
|
120
|
+
*/
|
|
121
|
+
async function resolve(options) {
|
|
122
|
+
if (options?.configFile === "") throw new ProfileError("EMPTY_PATH", "empty path");
|
|
123
|
+
if (options?.profile === "") throw new ProfileError("EMPTY_PROFILE", "empty profile");
|
|
124
|
+
if (options?.noProfile === true && (options.profile !== void 0 || options.configFile !== void 0)) throw new ProfileError("CONFLICTING_OPTIONS", "noProfile cannot be combined with profile or configFile");
|
|
125
|
+
const shouldReadFile = options?.noProfile !== true;
|
|
126
|
+
const shouldReadEnv = options?.disableEnv !== true;
|
|
127
|
+
const fileProfile = shouldReadFile ? await loadFile(options?.configFile, options?.profile) : {};
|
|
128
|
+
const envProfile = shouldReadEnv ? loadEnv() : {};
|
|
129
|
+
return {
|
|
130
|
+
...fileProfile,
|
|
131
|
+
...envProfile
|
|
132
|
+
};
|
|
170
133
|
}
|
|
171
134
|
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
return defaultConfigFilePath();
|
|
135
|
+
* Returns the path to the default databrickscfg file. Reads
|
|
136
|
+
* DATABRICKS_CONFIG_FILE from the environment, falling back to
|
|
137
|
+
* ~/.databrickscfg.
|
|
138
|
+
*/
|
|
139
|
+
function defaultConfigFile() {
|
|
140
|
+
const envPath = process.env.DATABRICKS_CONFIG_FILE ?? "";
|
|
141
|
+
if (envPath !== "") return envPath;
|
|
142
|
+
return defaultConfigFilePath();
|
|
182
143
|
}
|
|
183
144
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (name === SETTINGS_SECTION) {
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (isPhantomDefault(name, keys)) {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
names.push(name);
|
|
205
|
-
}
|
|
206
|
-
return names;
|
|
145
|
+
* Returns the names of all profiles (INI sections) in the given config
|
|
146
|
+
* file. The DEFAULT section is included only if it has keys.
|
|
147
|
+
*/
|
|
148
|
+
async function listProfiles(path) {
|
|
149
|
+
if (path === "") throw new ProfileError("CONFIG_FILE_NOT_FOUND", "config file not found: empty path");
|
|
150
|
+
if (!await fileExists(path)) throw new ProfileError("CONFIG_FILE_NOT_FOUND", `config file not found: ${path}`);
|
|
151
|
+
const data = parseIni(await readFile(path, "utf8"));
|
|
152
|
+
const names = [];
|
|
153
|
+
for (const [name, keys] of data) {
|
|
154
|
+
if (name === SETTINGS_SECTION) continue;
|
|
155
|
+
if (isPhantomDefault(name, keys)) continue;
|
|
156
|
+
names.push(name);
|
|
157
|
+
}
|
|
158
|
+
return names;
|
|
207
159
|
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
export { defaultConfigFile, listProfiles, resolve };
|
|
208
163
|
//# sourceMappingURL=resolve.js.map
|