@dbx-tools/lakebox 0.0.0-stage → 0.9.132
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/LICENSE +202 -0
- package/README.md +146 -2
- package/index.ts +18 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +15 -0
- package/lib/src/_ssh.d.ts +152 -0
- package/lib/src/_ssh.js +489 -0
- package/lib/src/_ssh_openssh.d.ts +18 -0
- package/lib/src/_ssh_openssh.js +382 -0
- package/lib/src/_ssh_ssh2.d.ts +16 -0
- package/lib/src/_ssh_ssh2.js +225 -0
- package/lib/src/key-store.d.ts +39 -0
- package/lib/src/key-store.js +145 -0
- package/lib/src/lifecycle.d.ts +18 -0
- package/lib/src/lifecycle.js +75 -0
- package/lib/src/rest.d.ts +81 -0
- package/lib/src/rest.js +199 -0
- package/lib/src/session.d.ts +89 -0
- package/lib/src/session.js +309 -0
- package/lib/src/transport.d.ts +15 -0
- package/lib/src/transport.js +16 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +117 -4
- package/src/_ssh.ts +610 -0
- package/src/_ssh_openssh.ts +471 -0
- package/src/_ssh_ssh2.ts +273 -0
- package/src/key-store.ts +177 -0
- package/src/lifecycle.ts +88 -0
- package/src/rest.ts +264 -0
- package/src/session.ts +371 -0
- package/src/transport.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dbx-tools/lakebox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect to, provision, and run commands on Databricks Lakeboxes.
|
|
4
|
+
|
|
5
|
+
## Provision a Lakebox
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { client as authClient } from "@dbx-tools/auth";
|
|
9
|
+
import { LakeboxClient } from "@dbx-tools/lakebox/rest";
|
|
10
|
+
import { ensureLakeboxRunning } from "@dbx-tools/lakebox/lifecycle";
|
|
11
|
+
|
|
12
|
+
const auth = await authClient.createAuthClient({ profile: "MY-PROFILE" });
|
|
13
|
+
const api = new LakeboxClient({
|
|
14
|
+
host: auth.host,
|
|
15
|
+
...(auth.workspaceId ? { workspaceId: auth.workspaceId } : {}),
|
|
16
|
+
authenticate: async (headers) => {
|
|
17
|
+
for (const [name, value] of Object.entries(await auth.headers())) {
|
|
18
|
+
headers.set(name, value);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const entry = await api.create();
|
|
23
|
+
await api.setIdleTimeout(entry.sandboxId, 3_600);
|
|
24
|
+
const running = await ensureLakeboxRunning(api, entry);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`LakeboxClient` accepts any credential object with `host` and
|
|
28
|
+
`authenticate(headers)`. AppKit and the Databricks SDK
|
|
29
|
+
`WorkspaceClient.config` satisfy this contract directly. The example adapts
|
|
30
|
+
`@dbx-tools/auth` for an explicit local profile. Use the app service principal
|
|
31
|
+
for lifecycle calls in a Databricks App.
|
|
32
|
+
|
|
33
|
+
## Connect and run a command
|
|
34
|
+
|
|
35
|
+
Create or load an SSH key, register it with the workspace, verify the gateway
|
|
36
|
+
host key, and close the session when work finishes:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { SshKeyStore } from "@dbx-tools/lakebox/key-store";
|
|
40
|
+
import type { LakeboxClient, LakeboxEntry } from "@dbx-tools/lakebox/rest";
|
|
41
|
+
import { SshSession } from "@dbx-tools/lakebox/session";
|
|
42
|
+
|
|
43
|
+
export async function runCommand(
|
|
44
|
+
api: LakeboxClient,
|
|
45
|
+
running: LakeboxEntry,
|
|
46
|
+
user: { name: string; home: string },
|
|
47
|
+
): Promise<void> {
|
|
48
|
+
const owner = "my-service";
|
|
49
|
+
const keys = new SshKeyStore();
|
|
50
|
+
const key = await keys.ensureRegistered(api, owner);
|
|
51
|
+
const gatewayHost = running.gatewayHost ?? key.gatewayHost;
|
|
52
|
+
if (!gatewayHost) {
|
|
53
|
+
throw new Error("The Lakebox API did not return an SSH gateway host");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const gatewayPort = 2_222;
|
|
57
|
+
const scope = await api.workspaceScope();
|
|
58
|
+
const knownHost = await keys.knownHost(scope, owner, gatewayHost, gatewayPort);
|
|
59
|
+
const session = new SshSession({
|
|
60
|
+
host: gatewayHost,
|
|
61
|
+
port: gatewayPort,
|
|
62
|
+
username: running.sandboxId,
|
|
63
|
+
privateKey: key.privateKey,
|
|
64
|
+
privateKeyPath: key.privateKeyPath,
|
|
65
|
+
knownHostsPath: keys.knownHostsPath(scope, owner, gatewayHost, gatewayPort),
|
|
66
|
+
connectTimeoutMs: 30_000,
|
|
67
|
+
sshTransport: "auto",
|
|
68
|
+
ssh2Patch: "auto",
|
|
69
|
+
...(knownHost ? { knownHost } : {}),
|
|
70
|
+
rememberHost: (fingerprint, hostKey) =>
|
|
71
|
+
keys.rememberHost(scope, owner, gatewayHost, gatewayPort, fingerprint, hostKey),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await session.connect();
|
|
76
|
+
const command = session.execute("sh", ["-lc", "uname -a"], {
|
|
77
|
+
user,
|
|
78
|
+
timeoutMs: 30_000,
|
|
79
|
+
});
|
|
80
|
+
const result = await command.result;
|
|
81
|
+
if (!result.success) {
|
|
82
|
+
throw new Error(result.stderr || `Command exited with ${result.exitCode}`);
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
await session.close();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Every command clears inherited Databricks credentials and SSH agent variables
|
|
91
|
+
before it runs. `execute()` returns a live `SshCommand`. Its `stdout` and
|
|
92
|
+
`stderr` fields are async iterables, awaiting the command returns its numeric
|
|
93
|
+
exit code, and `result` returns captured output and timing metadata.
|
|
94
|
+
|
|
95
|
+
The low-level package doesn't create Linux users. Pass an account that already
|
|
96
|
+
exists on the Lakebox. `@dbx-tools/appkit-lakebox` creates and isolates
|
|
97
|
+
application user accounts before it runs their commands.
|
|
98
|
+
|
|
99
|
+
`forwardOut(host, port)` opens a forwarded TCP stream through a separate pool.
|
|
100
|
+
Long-lived HTTP and WebSocket streams don't consume the warm command
|
|
101
|
+
connection.
|
|
102
|
+
|
|
103
|
+
## Stop or delete a Lakebox
|
|
104
|
+
|
|
105
|
+
Use lifecycle convergence when you need to wait for a terminal state:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { ensureLakeboxStopped } from "@dbx-tools/lakebox/lifecycle";
|
|
109
|
+
import type { LakeboxClient, LakeboxEntry } from "@dbx-tools/lakebox/rest";
|
|
110
|
+
|
|
111
|
+
export async function stopAndDelete(api: LakeboxClient, running: LakeboxEntry): Promise<void> {
|
|
112
|
+
const stopped = await ensureLakeboxStopped(api, running);
|
|
113
|
+
await api.delete(stopped.sandboxId);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`stop()` preserves the persistent Lakebox filesystem. `delete()` permanently
|
|
118
|
+
removes the Lakebox and its data.
|
|
119
|
+
|
|
120
|
+
## Configuration
|
|
121
|
+
|
|
122
|
+
| Field | Values | Default |
|
|
123
|
+
| -------------- | ------------------------- | ----------------------------------------- |
|
|
124
|
+
| `sshTransport` | `auto`, `openssh`, `ssh2` | `auto` prefers native OpenSSH with SOCKS5 |
|
|
125
|
+
| `ssh2Patch` | `auto`, `true`, `false` | `auto` patches only in development |
|
|
126
|
+
|
|
127
|
+
`SshSessionOptions` also requires the gateway host and port, Lakebox ID as the
|
|
128
|
+
SSH username, private key material, key and known-host paths, and a connection
|
|
129
|
+
timeout. `SshKeyStore` stores keys and gateway fingerprints under
|
|
130
|
+
`~/.dbx-tools/lakebox` unless you pass another root.
|
|
131
|
+
|
|
132
|
+
## Understand lifecycle and transport limits
|
|
133
|
+
|
|
134
|
+
- `ensureLakeboxRunning()` and `ensureLakeboxStopped()` poll for up to five
|
|
135
|
+
minutes.
|
|
136
|
+
- The REST client doesn't map users, persist app resource identity, or manage
|
|
137
|
+
services. Use [@dbx-tools/appkit-lakebox](../appkit-lakebox/README.md) for
|
|
138
|
+
those application-level capabilities.
|
|
139
|
+
- The command pool keeps one tested connection warm and grows to 10
|
|
140
|
+
connections. Forwarding uses a separate pool with no minimum.
|
|
141
|
+
- Each borrowed SSH resource handles one operation and is destroyed after that
|
|
142
|
+
command or forwarded stream. A failed forwarding open retries once with a new
|
|
143
|
+
resource. Established streams and commands aren't replayed.
|
|
144
|
+
- `auto` selects native OpenSSH when it is available and selects ssh2
|
|
145
|
+
otherwise. It doesn't switch transports after a runtime failure.
|
|
146
|
+
- `close()` cancels active commands, closes transport pools, and waits for an
|
|
147
|
+
in-progress connection attempt to settle.
|
package/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// GENERATED by projen watch - DO NOT EDIT.
|
|
2
|
+
// Regenerated from the exporting modules in ./src.
|
|
3
|
+
// Hand edits are overwritten on the next watch; this file is read-only.
|
|
4
|
+
|
|
5
|
+
export const PACKAGE_IDENTIFIER = "@dbx-tools/lakebox";
|
|
6
|
+
export const PACKAGE_VERSION = "0.9.132";
|
|
7
|
+
export * as keyStore from "./src/key-store.ts";
|
|
8
|
+
export * as lifecycle from "./src/lifecycle.ts";
|
|
9
|
+
export * as rest from "./src/rest.ts";
|
|
10
|
+
export * as session from "./src/session.ts";
|
|
11
|
+
export * as transport from "./src/transport.ts";
|
|
12
|
+
export { SshKeyStore } from "./src/key-store.ts";
|
|
13
|
+
export { LakeboxEntrySchema, LakeboxSshKeySchema, LakeboxApiError, LakeboxClient } from "./src/rest.ts";
|
|
14
|
+
export type { LakeboxEntry, LakeboxSshKey, LakeboxAuth } from "./src/rest.ts";
|
|
15
|
+
export { SshSession } from "./src/session.ts";
|
|
16
|
+
export type { SshSessionOptions } from "./src/session.ts";
|
|
17
|
+
export { SshTransportModeSchema, Ssh2PatchModeSchema } from "./src/transport.ts";
|
|
18
|
+
export type { SshTransportMode, Ssh2PatchMode } from "./src/transport.ts";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const PACKAGE_IDENTIFIER = "@dbx-tools/lakebox";
|
|
2
|
+
export declare const PACKAGE_VERSION = "0.9.132";
|
|
3
|
+
export * as keyStore from "./src/key-store.ts";
|
|
4
|
+
export * as lifecycle from "./src/lifecycle.ts";
|
|
5
|
+
export * as rest from "./src/rest.ts";
|
|
6
|
+
export * as session from "./src/session.ts";
|
|
7
|
+
export * as transport from "./src/transport.ts";
|
|
8
|
+
export { SshKeyStore } from "./src/key-store.ts";
|
|
9
|
+
export { LakeboxEntrySchema, LakeboxSshKeySchema, LakeboxApiError, LakeboxClient } from "./src/rest.ts";
|
|
10
|
+
export type { LakeboxEntry, LakeboxSshKey, LakeboxAuth } from "./src/rest.ts";
|
|
11
|
+
export { SshSession } from "./src/session.ts";
|
|
12
|
+
export type { SshSessionOptions } from "./src/session.ts";
|
|
13
|
+
export { SshTransportModeSchema, Ssh2PatchModeSchema } from "./src/transport.ts";
|
|
14
|
+
export type { SshTransportMode, Ssh2PatchMode } from "./src/transport.ts";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// GENERATED by projen watch - DO NOT EDIT.
|
|
2
|
+
// Regenerated from the exporting modules in ./src.
|
|
3
|
+
// Hand edits are overwritten on the next watch; this file is read-only.
|
|
4
|
+
export const PACKAGE_IDENTIFIER = "@dbx-tools/lakebox";
|
|
5
|
+
export const PACKAGE_VERSION = "0.9.132";
|
|
6
|
+
export * as keyStore from "./src/key-store.js";
|
|
7
|
+
export * as lifecycle from "./src/lifecycle.js";
|
|
8
|
+
export * as rest from "./src/rest.js";
|
|
9
|
+
export * as session from "./src/session.js";
|
|
10
|
+
export * as transport from "./src/transport.js";
|
|
11
|
+
export { SshKeyStore } from "./src/key-store.js";
|
|
12
|
+
export { LakeboxEntrySchema, LakeboxSshKeySchema, LakeboxApiError, LakeboxClient } from "./src/rest.js";
|
|
13
|
+
export { SshSession } from "./src/session.js";
|
|
14
|
+
export { SshTransportModeSchema, Ssh2PatchModeSchema } from "./src/transport.js";
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwyQ0FBMkM7QUFDM0MsbURBQW1EO0FBQ25ELHdFQUF3RTtBQUV4RSxNQUFNLENBQUMsTUFBTSxrQkFBa0IsR0FBRyxvQkFBb0IsQ0FBQztBQUN2RCxNQUFNLENBQUMsTUFBTSxlQUFlLEdBQUcsU0FBUyxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxRQUFRLE1BQU0sb0JBQW9CLENBQUM7QUFDL0MsT0FBTyxLQUFLLFNBQVMsTUFBTSxvQkFBb0IsQ0FBQztBQUNoRCxPQUFPLEtBQUssSUFBSSxNQUFNLGVBQWUsQ0FBQztBQUN0QyxPQUFPLEtBQUssT0FBTyxNQUFNLGtCQUFrQixDQUFDO0FBQzVDLE9BQU8sS0FBSyxTQUFTLE1BQU0sb0JBQW9CLENBQUM7QUFDaEQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ2pELE9BQU8sRUFBRSxrQkFBa0IsRUFBRSxtQkFBbUIsRUFBRSxlQUFlLEVBQUUsYUFBYSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRXhHLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUU5QyxPQUFPLEVBQUUsc0JBQXNCLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8vIEdFTkVSQVRFRCBieSBwcm9qZW4gd2F0Y2ggLSBETyBOT1QgRURJVC5cbi8vIFJlZ2VuZXJhdGVkIGZyb20gdGhlIGV4cG9ydGluZyBtb2R1bGVzIGluIC4vc3JjLlxuLy8gSGFuZCBlZGl0cyBhcmUgb3ZlcndyaXR0ZW4gb24gdGhlIG5leHQgd2F0Y2g7IHRoaXMgZmlsZSBpcyByZWFkLW9ubHkuXG5cbmV4cG9ydCBjb25zdCBQQUNLQUdFX0lERU5USUZJRVIgPSBcIkBkYngtdG9vbHMvbGFrZWJveFwiO1xuZXhwb3J0IGNvbnN0IFBBQ0tBR0VfVkVSU0lPTiA9IFwiMC45LjEzMlwiO1xuZXhwb3J0ICogYXMga2V5U3RvcmUgZnJvbSBcIi4vc3JjL2tleS1zdG9yZS50c1wiO1xuZXhwb3J0ICogYXMgbGlmZWN5Y2xlIGZyb20gXCIuL3NyYy9saWZlY3ljbGUudHNcIjtcbmV4cG9ydCAqIGFzIHJlc3QgZnJvbSBcIi4vc3JjL3Jlc3QudHNcIjtcbmV4cG9ydCAqIGFzIHNlc3Npb24gZnJvbSBcIi4vc3JjL3Nlc3Npb24udHNcIjtcbmV4cG9ydCAqIGFzIHRyYW5zcG9ydCBmcm9tIFwiLi9zcmMvdHJhbnNwb3J0LnRzXCI7XG5leHBvcnQgeyBTc2hLZXlTdG9yZSB9IGZyb20gXCIuL3NyYy9rZXktc3RvcmUudHNcIjtcbmV4cG9ydCB7IExha2Vib3hFbnRyeVNjaGVtYSwgTGFrZWJveFNzaEtleVNjaGVtYSwgTGFrZWJveEFwaUVycm9yLCBMYWtlYm94Q2xpZW50IH0gZnJvbSBcIi4vc3JjL3Jlc3QudHNcIjtcbmV4cG9ydCB0eXBlIHsgTGFrZWJveEVudHJ5LCBMYWtlYm94U3NoS2V5LCBMYWtlYm94QXV0aCB9IGZyb20gXCIuL3NyYy9yZXN0LnRzXCI7XG5leHBvcnQgeyBTc2hTZXNzaW9uIH0gZnJvbSBcIi4vc3JjL3Nlc3Npb24udHNcIjtcbmV4cG9ydCB0eXBlIHsgU3NoU2Vzc2lvbk9wdGlvbnMgfSBmcm9tIFwiLi9zcmMvc2Vzc2lvbi50c1wiO1xuZXhwb3J0IHsgU3NoVHJhbnNwb3J0TW9kZVNjaGVtYSwgU3NoMlBhdGNoTW9kZVNjaGVtYSB9IGZyb20gXCIuL3NyYy90cmFuc3BvcnQudHNcIjtcbmV4cG9ydCB0eXBlIHsgU3NoVHJhbnNwb3J0TW9kZSwgU3NoMlBhdGNoTW9kZSB9IGZyb20gXCIuL3NyYy90cmFuc3BvcnQudHNcIjtcbiJdfQ==
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type Duplex, type Readable } from "node:stream";
|
|
2
|
+
import type { LakeboxCommandResult } from "@dbx-tools/shared-lakebox";
|
|
3
|
+
import { type Options } from "generic-pool";
|
|
4
|
+
import type { Client as Ssh2Client } from "ssh2";
|
|
5
|
+
import type { Ssh2PatchMode, SshTransportMode } from "./transport.ts";
|
|
6
|
+
/** Maximum authenticated resources maintained by each SSH operation pool. */
|
|
7
|
+
export declare const SSH_POOL_MAX = 10;
|
|
8
|
+
/** One command execution request after the remote shell script is assembled. */
|
|
9
|
+
export interface SshExecutionOptions {
|
|
10
|
+
timeoutMs: number;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
/** Transport callbacks owned by one live SSH command. */
|
|
14
|
+
export interface SshCommandExecution {
|
|
15
|
+
readonly signal: AbortSignal;
|
|
16
|
+
stdout(chunk: Buffer | string): void;
|
|
17
|
+
stderr(chunk: Buffer | string): void;
|
|
18
|
+
setCancel(cancel: () => void | Promise<void>): void;
|
|
19
|
+
follow(command: SshCommand): Promise<number>;
|
|
20
|
+
}
|
|
21
|
+
/** Live SSH command that streams output and awaits to its numeric exit code. */
|
|
22
|
+
export declare class SshCommand implements Promise<number> {
|
|
23
|
+
readonly command: string;
|
|
24
|
+
readonly args: readonly string[];
|
|
25
|
+
readonly [Symbol.toStringTag] = "SshCommand";
|
|
26
|
+
/** Live standard output decoded as UTF-8 strings. */
|
|
27
|
+
readonly stdout: Readable & AsyncIterable<string>;
|
|
28
|
+
/** Live standard error decoded as UTF-8 strings. */
|
|
29
|
+
readonly stderr: Readable & AsyncIterable<string>;
|
|
30
|
+
/** Completed result with captured output, timing, and timeout metadata. */
|
|
31
|
+
readonly result: Promise<LakeboxCommandResult>;
|
|
32
|
+
/** Numeric exit code after completion. */
|
|
33
|
+
exitCode: number | undefined;
|
|
34
|
+
private readonly startedAt;
|
|
35
|
+
private readonly stdoutStream;
|
|
36
|
+
private readonly stderrStream;
|
|
37
|
+
private readonly stdoutDecoder;
|
|
38
|
+
private readonly stderrDecoder;
|
|
39
|
+
private readonly abortController;
|
|
40
|
+
private readonly completion;
|
|
41
|
+
private resolveCompletion;
|
|
42
|
+
private rejectCompletion;
|
|
43
|
+
private cancelBackend?;
|
|
44
|
+
private cancellation?;
|
|
45
|
+
private stdoutText;
|
|
46
|
+
private stderrText;
|
|
47
|
+
private settled;
|
|
48
|
+
private timedOut;
|
|
49
|
+
/** Creates a command and schedules its asynchronous setup and execution. */
|
|
50
|
+
constructor(command: string, args: readonly string[], options: SshExecutionOptions, start: (execution: SshCommandExecution) => Promise<number>);
|
|
51
|
+
/** Cancel the command once. Caller cancellation resolves with exit code 130. */
|
|
52
|
+
cancel(exitCode?: number): Promise<void>;
|
|
53
|
+
then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
54
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<number | TResult>;
|
|
55
|
+
finally(onfinally?: (() => void) | null): Promise<number>;
|
|
56
|
+
private invokeCancel;
|
|
57
|
+
private writeOutput;
|
|
58
|
+
private follow;
|
|
59
|
+
private pipe;
|
|
60
|
+
private finish;
|
|
61
|
+
private fail;
|
|
62
|
+
private closeOutput;
|
|
63
|
+
}
|
|
64
|
+
/** Connection details shared by native OpenSSH and the guarded ssh2 fallback. */
|
|
65
|
+
export interface SshTransportOptions {
|
|
66
|
+
host: string;
|
|
67
|
+
connectHost: string;
|
|
68
|
+
port: number;
|
|
69
|
+
username: string;
|
|
70
|
+
privateKeyPath: string;
|
|
71
|
+
knownHostsPath: string;
|
|
72
|
+
connectTimeoutMs: number;
|
|
73
|
+
ssh2Client: Ssh2Client;
|
|
74
|
+
createSsh2CommandClient: () => Promise<Ssh2Client>;
|
|
75
|
+
transport?: SshTransportMode;
|
|
76
|
+
ssh2Patch?: Ssh2PatchMode;
|
|
77
|
+
sshCommand?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Selected command and remote TCP transport for one verified SSH gateway. */
|
|
80
|
+
export interface SshTransport {
|
|
81
|
+
readonly kind: "openssh" | "ssh2";
|
|
82
|
+
run(script: string, execution: SshCommandExecution): Promise<number>;
|
|
83
|
+
connect(remoteHost: string, remotePort: number): Promise<Duplex>;
|
|
84
|
+
close(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/** Async lifecycle used by both native OpenSSH and ssh2 connection pools. */
|
|
87
|
+
export interface SshResourceLifecycle<T> {
|
|
88
|
+
create(): Promise<T>;
|
|
89
|
+
destroy(resource: T): Promise<void>;
|
|
90
|
+
test(resource: T): Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/** Optional pool overrides used by transport tests and constrained runtimes. */
|
|
93
|
+
export type SshPoolOptions = Pick<Options, "max" | "acquireTimeoutMillis" | "idleTimeoutMillis" | "evictionRunIntervalMillis" | "numTestsPerEvictionRun">;
|
|
94
|
+
/**
|
|
95
|
+
* Exclusive, single-operation SSH resource pool.
|
|
96
|
+
*
|
|
97
|
+
* The command pool keeps one authenticated resource warm. Forwarding uses a
|
|
98
|
+
* separate zero-minimum pool so long-lived WebSockets cannot consume the warm
|
|
99
|
+
* command connection. Every borrowed resource is destroyed after its command
|
|
100
|
+
* or forwarded stream because the Databricks Russh gateway may accept only one
|
|
101
|
+
* operation during a connection's lifetime.
|
|
102
|
+
*/
|
|
103
|
+
export declare abstract class PooledSshTransport<T> implements SshTransport {
|
|
104
|
+
private readonly lifecycle;
|
|
105
|
+
abstract readonly kind: "openssh" | "ssh2";
|
|
106
|
+
private readonly commandPool;
|
|
107
|
+
private readonly forwardingPool;
|
|
108
|
+
private readonly activeResources;
|
|
109
|
+
private readonly seededResources;
|
|
110
|
+
private lastCreateError;
|
|
111
|
+
private starting?;
|
|
112
|
+
private closing?;
|
|
113
|
+
private closed;
|
|
114
|
+
protected constructor(lifecycle: SshResourceLifecycle<T>, options?: SshPoolOptions);
|
|
115
|
+
/** Starts both pools and waits until one tested command resource is warm. */
|
|
116
|
+
start(): Promise<void>;
|
|
117
|
+
private startPools;
|
|
118
|
+
run(script: string, execution: SshCommandExecution): Promise<number>;
|
|
119
|
+
connect(remoteHost: string, remotePort: number): Promise<Duplex>;
|
|
120
|
+
close(): Promise<void>;
|
|
121
|
+
protected abstract runWithResource(resource: T, script: string, execution: SshCommandExecution): Promise<number>;
|
|
122
|
+
protected abstract connectWithResource(resource: T, remoteHost: string, remotePort: number): Promise<Duplex>;
|
|
123
|
+
private connectWithBorrowedResource;
|
|
124
|
+
private acquire;
|
|
125
|
+
private destroy;
|
|
126
|
+
private closePools;
|
|
127
|
+
}
|
|
128
|
+
/** Injectable transport constructors used to isolate policy selection in tests. */
|
|
129
|
+
export interface SshTransportFactories {
|
|
130
|
+
supportsOpenSsh(command: string): Promise<boolean>;
|
|
131
|
+
createOpenSsh(options: SshTransportOptions, command: string): Promise<SshTransport>;
|
|
132
|
+
createSsh2(options: SshTransportOptions): Promise<SshTransport>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Select one SSH transport from resolved policy and keep it for the session.
|
|
136
|
+
* Auto prefers native OpenSSH and otherwise selects ssh2.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createSshTransport(options: SshTransportOptions, overrides?: Partial<SshTransportFactories>): Promise<SshTransport>;
|
|
139
|
+
/**
|
|
140
|
+
* Account that runs one remote command.
|
|
141
|
+
*
|
|
142
|
+
* `user` targets a locked, non-sudo Lakebox account. `root` is reserved for
|
|
143
|
+
* fixed package-owned bootstrap scripts and is never reachable from REST,
|
|
144
|
+
* agent tools, or service definitions.
|
|
145
|
+
*/
|
|
146
|
+
export type SshCommandIdentity = {
|
|
147
|
+
kind: "user";
|
|
148
|
+
name: string;
|
|
149
|
+
home: string;
|
|
150
|
+
} | {
|
|
151
|
+
kind: "root";
|
|
152
|
+
};
|