@ dbx 工具/ lakebox
在 Databricks Lakeboxs 上连接、提供和运行命令.
提供湖箱
import { client as authClient } from "@dbx-tools/auth";
import { LakeboxClient } from "@dbx-tools/lakebox/rest";
import { ensureLakeboxRunning } from "@dbx-tools/lakebox/lifecycle";
const auth = await authClient.createAuthClient({ profile: "MY-PROFILE" });
const api = new LakeboxClient({
host: auth.host,
...(auth.workspaceId ? { workspaceId: auth.workspaceId } : {}),
authenticate: async (headers) => {
for (const [name, value] of Object.entries(await auth.headers())) {
headers.set(name, value);
}
},
});
const entry = await api.create();
await api.setIdleTimeout(entry.sandboxId, 3_600);
const running = await ensureLakeboxRunning(api, entry);
LakeboxClient 接受任何证书对象 host 财务报告和审定财务报表
authenticate(headers). AppKit和Databricks SDK
WorkspaceClient.config 直接履行合同。 示例适应
@dbx-tools/auth 以明确本地概况。 使用应用程序服务主机
用于在 Databricks App 中的生命周期呼叫.
连接并运行命令
创建或装入 SSH 密钥, 在工作空间注册, 验证网关 主机密钥, 当工作结束时关闭会话 :
import { SshKeyStore } from "@dbx-tools/lakebox/key-store";
import type { LakeboxClient, LakeboxEntry } from "@dbx-tools/lakebox/rest";
import { SshSession } from "@dbx-tools/lakebox/session";
export async function runCommand(
api: LakeboxClient,
running: LakeboxEntry,
user: { name: string; home: string },
): Promise<void> {
const owner = "my-service";
const keys = new SshKeyStore();
const key = await keys.ensureRegistered(api, owner);
const gatewayHost = running.gatewayHost ?? key.gatewayHost;
if (!gatewayHost) {
throw new Error("The Lakebox API did not return an SSH gateway host");
}
const gatewayPort = 2_222;
const scope = await api.workspaceScope();
const knownHost = await keys.knownHost(scope, owner, gatewayHost, gatewayPort);
const session = new SshSession({
host: gatewayHost,
port: gatewayPort,
username: running.sandboxId,
privateKey: key.privateKey,
privateKeyPath: key.privateKeyPath,
knownHostsPath: keys.knownHostsPath(scope, owner, gatewayHost, gatewayPort),
connectTimeoutMs: 30_000,
sshTransport: "auto",
ssh2Patch: "auto",
...(knownHost ? { knownHost } : {}),
rememberHost: (fingerprint, hostKey) =>
keys.rememberHost(scope, owner, gatewayHost, gatewayPort, fingerprint, hostKey),
});
try {
await session.connect();
const command = session.execute("sh", ["-lc", "uname -a"], {
user,
timeoutMs: 30_000,
});
const result = await command.result;
if (!result.success) {
throw new Error(result.stderr || `Command exited with ${result.exitCode}`);
}
} finally {
await session.close();
}
}
每个命令清除继承的 Databricks 证书和 SSH 代理变量
在它运行之前. execute() 返回一个活字 SshCommand。 。 stdout 财务报告和审定财务报表
stderr 字段是协同可移动的,等待命令返回其数字
退出代码,和 result 返回抓取的输出和计时元数据.
低等包不创建Linux用户. 通过一个账户已经
存在于湖框中. @dbx-tools/appkit-lakebox 创建和隔离
程序用户账户在运行其命令前 .
forwardOut(host, port) 通过单独的池来打开转发的 TCP 流.
长寿的HTTP和WebSocket流不会消耗温暖的命令
连接.
停止或删除湖框
需要等待终止状态时使用生命周期趋同:
import { ensureLakeboxStopped } from "@dbx-tools/lakebox/lifecycle";
import type { LakeboxClient, LakeboxEntry } from "@dbx-tools/lakebox/rest";
export async function stopAndDelete(api: LakeboxClient, running: LakeboxEntry): Promise<void> {
const stopped = await ensureLakeboxStopped(api, running);
await api.delete(stopped.sandboxId);
}
stop() 保留持久的Lakebox文件系统. delete() 永久
删除"湖箱"及其数据.
配置
| 外地 | 数值 | 默认 |
|---|---|---|
sshTransport | auto, (中文(简体) ), openssh, (中文(简体) ), ssh2 | auto 倾向于使用 SOCKS5 的本地 OpenSSH |
ssh2Patch | auto, (中文(简体) ), true, (中文(简体) ), false | auto 只在开发中补丁 |
SshSessionOptions 还需要网关主机和端口,Lakebox ID作为
SSH 用户名、 私有密钥材料、 密钥和已知主机路径以及连接
暂停 . SshKeyStore 将密钥和网关指纹保存在
~/.dbx-tools/lakebox 除非你通过另一个根.
了解生命周期和运输限制
ensureLakeboxRunning()财务报告和审定财务报表ensureLakeboxStopped()5人以下的民意调查 几分钟.- REST 客户端不映射用户,不坚持应用资源身份,也不管理 服务。 使用 @dbx-工具/appkit-lakebox 页:1 这些应用层面的能力.
- 指挥池保持一个测试的连接温度 并增长到10 连接。 转发使用一个单独的没有最小值的池.
- 每个被借用的SSH资源处理一个操作,然后被销毁 命令或转发流。 发送失败的打开重试, 一次带新的 资源。 既定的流和命令没有被重放.
auto在可用时选择本地 OpenSSH 并选择 ssh2 否则。 它在运行时间故障后不会切换运输.close()取消活动命令、关闭传输池并等待一个 正在进行中的连接试图解决.