@altertable/cli 1.0.0 → 1.1.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/cli.js +677 -913
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -916,9 +916,6 @@ function terminalDefaultHint(value) {
|
|
|
916
916
|
function terminalNotConfiguredStatus() {
|
|
917
917
|
return terminalMuted("not set");
|
|
918
918
|
}
|
|
919
|
-
function terminalDescription(text) {
|
|
920
|
-
return terminalSubtle(text);
|
|
921
|
-
}
|
|
922
919
|
function terminalSubtle(text) {
|
|
923
920
|
return applyTerminalStyle("subtle", text);
|
|
924
921
|
}
|
|
@@ -1322,6 +1319,8 @@ function chmodConfigFile(filePath) {
|
|
|
1322
1319
|
|
|
1323
1320
|
// src/lib/profile-store.ts
|
|
1324
1321
|
var DEFAULT_PROFILE_NAME = "default";
|
|
1322
|
+
var FROM_ENV_PSEUDOPROFILE_NAME = "_from_env";
|
|
1323
|
+
var RESERVED_PROFILE_NAMES = new Set([FROM_ENV_PSEUDOPROFILE_NAME]);
|
|
1325
1324
|
var PROFILE_CONFIG_KEYS = [
|
|
1326
1325
|
"user",
|
|
1327
1326
|
"api_key_env",
|
|
@@ -1339,10 +1338,6 @@ var PROFILE_CONFIG_KEYS = [
|
|
|
1339
1338
|
"oauth_expiry",
|
|
1340
1339
|
"lakehouse_credential_expiry"
|
|
1341
1340
|
];
|
|
1342
|
-
var PROFILE_SCOPED_KEYS = new Set(PROFILE_CONFIG_KEYS);
|
|
1343
|
-
function isProfileScopedConfigKey(key) {
|
|
1344
|
-
return PROFILE_SCOPED_KEYS.has(key);
|
|
1345
|
-
}
|
|
1346
1341
|
var SAFE_PROFILE_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
1347
1342
|
function profilesDir() {
|
|
1348
1343
|
return join2(configDir(), "profiles");
|
|
@@ -1360,6 +1355,9 @@ function assertSafeProfileName(name) {
|
|
|
1360
1355
|
if (!SAFE_PROFILE_NAME_PATTERN.test(name)) {
|
|
1361
1356
|
throw new ConfigurationError(`Invalid profile name: ${name}. Use only letters, digits, dots, underscores, and hyphens.`);
|
|
1362
1357
|
}
|
|
1358
|
+
if (RESERVED_PROFILE_NAMES.has(name)) {
|
|
1359
|
+
throw new ConfigurationError(`Profile name is reserved: ${name}`);
|
|
1360
|
+
}
|
|
1363
1361
|
const resolvedProfileDir = resolve(join2(profilesDir(), name));
|
|
1364
1362
|
const resolvedProfilesRoot = resolve(profilesDir());
|
|
1365
1363
|
const profilesRootPrefix = resolvedProfilesRoot.endsWith(sep) ? resolvedProfilesRoot : `${resolvedProfilesRoot}${sep}`;
|
|
@@ -1401,7 +1399,7 @@ function setActiveProfile(name) {
|
|
|
1401
1399
|
}
|
|
1402
1400
|
kvSet(configFile(), "active_profile", name);
|
|
1403
1401
|
}
|
|
1404
|
-
function
|
|
1402
|
+
function resolveWorkingProfile(override) {
|
|
1405
1403
|
ensureProfilesLayout();
|
|
1406
1404
|
const explicit = override ?? process.env.ALTERTABLE_PROFILE ?? "";
|
|
1407
1405
|
if (explicit.length > 0) {
|
|
@@ -1427,17 +1425,14 @@ function ensureProfileExists(name) {
|
|
|
1427
1425
|
mkdirSync2(profileDir(name), { recursive: true });
|
|
1428
1426
|
}
|
|
1429
1427
|
}
|
|
1430
|
-
function
|
|
1428
|
+
function configGet(key, profileName) {
|
|
1431
1429
|
return kvGet(profileConfigFile(profileName), key);
|
|
1432
1430
|
}
|
|
1433
|
-
function
|
|
1431
|
+
function configSet(key, value, profileName) {
|
|
1434
1432
|
assertSafeProfileName(profileName);
|
|
1435
1433
|
mkdirSync2(profileDir(profileName), { recursive: true });
|
|
1436
1434
|
kvSet(profileConfigFile(profileName), key, value);
|
|
1437
1435
|
}
|
|
1438
|
-
function unsetProfileConfig(profileName, key) {
|
|
1439
|
-
kvUnset(profileConfigFile(profileName), key);
|
|
1440
|
-
}
|
|
1441
1436
|
function readProfileConfigRecord(name) {
|
|
1442
1437
|
const config = Object.fromEntries(PROFILE_CONFIG_KEYS.map((key) => [key, undefined]));
|
|
1443
1438
|
for (const key of PROFILE_CONFIG_KEYS) {
|
|
@@ -1481,43 +1476,21 @@ function isQueryLayout(value) {
|
|
|
1481
1476
|
}
|
|
1482
1477
|
|
|
1483
1478
|
// src/lib/config.ts
|
|
1484
|
-
function
|
|
1485
|
-
return resolveProfileName(override ?? getCliContext().profile ?? process.env.ALTERTABLE_PROFILE);
|
|
1486
|
-
}
|
|
1487
|
-
function configGet(key) {
|
|
1488
|
-
ensureProfilesLayout();
|
|
1489
|
-
if (isProfileScopedConfigKey(key)) {
|
|
1490
|
-
return readProfileConfig(resolveConfigProfile(), key);
|
|
1491
|
-
}
|
|
1479
|
+
function configGetGlobal(key) {
|
|
1492
1480
|
return kvGet(configFile(), key);
|
|
1493
1481
|
}
|
|
1494
|
-
function
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
writeProfileConfig(resolveConfigProfile(), key, value);
|
|
1498
|
-
chmodConfigFile(profileConfigFile(resolveConfigProfile()));
|
|
1499
|
-
return;
|
|
1500
|
-
}
|
|
1501
|
-
const filePath = configFile();
|
|
1502
|
-
kvSet(filePath, key, value);
|
|
1503
|
-
chmodConfigFile(filePath);
|
|
1504
|
-
}
|
|
1505
|
-
function configUnset(key) {
|
|
1506
|
-
ensureProfilesLayout();
|
|
1507
|
-
if (isProfileScopedConfigKey(key)) {
|
|
1508
|
-
unsetProfileConfig(resolveConfigProfile(), key);
|
|
1509
|
-
return;
|
|
1510
|
-
}
|
|
1511
|
-
kvUnset(configFile(), key);
|
|
1482
|
+
function configSetGlobal(key, value) {
|
|
1483
|
+
kvSet(configFile(), key, value);
|
|
1484
|
+
chmodConfigFile(configFile());
|
|
1512
1485
|
}
|
|
1513
1486
|
function resolveAllowInsecureHttp() {
|
|
1514
1487
|
const envFlag = process.env.ALTERTABLE_ALLOW_INSECURE_HTTP ?? "";
|
|
1515
1488
|
return envFlag === "true" || envFlag === "1";
|
|
1516
1489
|
}
|
|
1517
|
-
function resolveApiBase() {
|
|
1490
|
+
function resolveApiBase(profileName) {
|
|
1518
1491
|
let base = process.env.ALTERTABLE_API_BASE ?? "";
|
|
1519
1492
|
if (!base) {
|
|
1520
|
-
base = configGet("api_base");
|
|
1493
|
+
base = configGet("api_base", profileName);
|
|
1521
1494
|
}
|
|
1522
1495
|
if (!base) {
|
|
1523
1496
|
base = "https://api.altertable.ai";
|
|
@@ -1526,10 +1499,10 @@ function resolveApiBase() {
|
|
|
1526
1499
|
assertAllowedApiBase(normalized, { allowInsecureHttp: resolveAllowInsecureHttp() });
|
|
1527
1500
|
return normalized;
|
|
1528
1501
|
}
|
|
1529
|
-
function resolveManagementApiRoot() {
|
|
1502
|
+
function resolveManagementApiRoot(profileName) {
|
|
1530
1503
|
let root = process.env.ALTERTABLE_MANAGEMENT_API_BASE ?? "";
|
|
1531
1504
|
if (!root) {
|
|
1532
|
-
root = configGet("management_api_base");
|
|
1505
|
+
root = configGet("management_api_base", profileName);
|
|
1533
1506
|
}
|
|
1534
1507
|
if (!root) {
|
|
1535
1508
|
root = "https://app.altertable.ai";
|
|
@@ -1538,16 +1511,16 @@ function resolveManagementApiRoot() {
|
|
|
1538
1511
|
assertAllowedApiBase(normalized, { allowInsecureHttp: resolveAllowInsecureHttp() });
|
|
1539
1512
|
return normalized;
|
|
1540
1513
|
}
|
|
1541
|
-
function resolveManagementApiBase() {
|
|
1542
|
-
return `${resolveManagementApiRoot()}/rest/v1`;
|
|
1514
|
+
function resolveManagementApiBase(profileName) {
|
|
1515
|
+
return `${resolveManagementApiRoot(profileName)}/rest/v1`;
|
|
1543
1516
|
}
|
|
1544
|
-
function resolveOAuthBase() {
|
|
1545
|
-
return `${resolveManagementApiRoot()}/oauth`;
|
|
1517
|
+
function resolveOAuthBase(profileName) {
|
|
1518
|
+
return `${resolveManagementApiRoot(profileName)}/oauth`;
|
|
1546
1519
|
}
|
|
1547
1520
|
var QUERY_PAGER_VALUES = new Set(["auto", "always", "never"]);
|
|
1548
1521
|
var MIN_QUERY_MAX_COL_WIDTH = 8;
|
|
1549
1522
|
function getQueryDefaultMaxColumnWidth() {
|
|
1550
|
-
const value =
|
|
1523
|
+
const value = configGetGlobal("query_max_width");
|
|
1551
1524
|
if (value.length === 0) {
|
|
1552
1525
|
return;
|
|
1553
1526
|
}
|
|
@@ -1558,7 +1531,7 @@ function getQueryDefaultMaxColumnWidth() {
|
|
|
1558
1531
|
return parsed;
|
|
1559
1532
|
}
|
|
1560
1533
|
function getQueryDefaultLayout() {
|
|
1561
|
-
const value =
|
|
1534
|
+
const value = configGetGlobal("query_layout");
|
|
1562
1535
|
if (value.length === 0) {
|
|
1563
1536
|
return;
|
|
1564
1537
|
}
|
|
@@ -1568,7 +1541,7 @@ function getQueryDefaultLayout() {
|
|
|
1568
1541
|
return;
|
|
1569
1542
|
}
|
|
1570
1543
|
function getQueryDefaultPager() {
|
|
1571
|
-
const value =
|
|
1544
|
+
const value = configGetGlobal("query_pager");
|
|
1572
1545
|
if (value.length === 0) {
|
|
1573
1546
|
return;
|
|
1574
1547
|
}
|
|
@@ -3059,297 +3032,10 @@ async function writeCommandOutput(mode, sink = getOutputSink()) {
|
|
|
3059
3032
|
}
|
|
3060
3033
|
}
|
|
3061
3034
|
|
|
3062
|
-
// src/lib/secrets.ts
|
|
3063
|
-
import { chmodSync as chmodSync2, statSync } from "fs";
|
|
3064
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
3065
|
-
|
|
3066
|
-
// src/lib/log.ts
|
|
3067
|
-
function logDebug(message) {
|
|
3068
|
-
if (getCliContext().debug) {
|
|
3069
|
-
console.error(`[DEBUG] ${message}`);
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3072
|
-
function logWarn(message) {
|
|
3073
|
-
console.error(`[WARN] ${message}`);
|
|
3074
|
-
}
|
|
3075
|
-
|
|
3076
|
-
// src/lib/secrets.ts
|
|
3077
|
-
var fileBackendWarned = false;
|
|
3078
|
-
function fileMode(filePath) {
|
|
3079
|
-
try {
|
|
3080
|
-
const stat = statSync(filePath);
|
|
3081
|
-
return (stat.mode & 511).toString(8);
|
|
3082
|
-
} catch {
|
|
3083
|
-
return "";
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
function requireSafeCredentialsFile() {
|
|
3087
|
-
const filePath = credentialsFile();
|
|
3088
|
-
try {
|
|
3089
|
-
statSync(filePath);
|
|
3090
|
-
} catch {
|
|
3091
|
-
return;
|
|
3092
|
-
}
|
|
3093
|
-
const mode = fileMode(filePath);
|
|
3094
|
-
if (!mode) {
|
|
3095
|
-
return;
|
|
3096
|
-
}
|
|
3097
|
-
const modeNumber = Number.parseInt(mode, 8);
|
|
3098
|
-
if (modeNumber & 63) {
|
|
3099
|
-
throw new CliError(`Refusing to read ${filePath}: permissions ${mode} are too open (group/other access). Run: chmod 600 ${filePath}`);
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
function warnFileBackendOnce() {
|
|
3103
|
-
if (!fileBackendWarned) {
|
|
3104
|
-
logWarn(`No macOS keychain; storing secrets at ${credentialsFile()} (chmod 600). Prefer environment variables in CI.`);
|
|
3105
|
-
fileBackendWarned = true;
|
|
3106
|
-
}
|
|
3107
|
-
}
|
|
3108
|
-
function hasSecurityCommand() {
|
|
3109
|
-
const result = runSpawnSync("security", ["help"], { stdio: "ignore" });
|
|
3110
|
-
return result.status === 0 || result.error === undefined;
|
|
3111
|
-
}
|
|
3112
|
-
function secretBackend() {
|
|
3113
|
-
const override = process.env.ALTERTABLE_SECRET_BACKEND ?? "";
|
|
3114
|
-
if (override === "file") {
|
|
3115
|
-
return "file";
|
|
3116
|
-
}
|
|
3117
|
-
if (override === "keychain") {
|
|
3118
|
-
if (process.platform === "darwin" && hasSecurityCommand()) {
|
|
3119
|
-
return "macos";
|
|
3120
|
-
}
|
|
3121
|
-
throw new CliError("ALTERTABLE_SECRET_BACKEND=keychain but the macOS keychain is unavailable.");
|
|
3122
|
-
}
|
|
3123
|
-
if (process.platform === "darwin" && hasSecurityCommand()) {
|
|
3124
|
-
return "macos";
|
|
3125
|
-
}
|
|
3126
|
-
return "file";
|
|
3127
|
-
}
|
|
3128
|
-
function resolveSecretAccount(account, profileName) {
|
|
3129
|
-
if (profileName) {
|
|
3130
|
-
assertSafeProfileName(profileName);
|
|
3131
|
-
return `profile/${profileName}/${account}`;
|
|
3132
|
-
}
|
|
3133
|
-
const profile = resolveProfileName(getCliContext().profile ?? process.env.ALTERTABLE_PROFILE);
|
|
3134
|
-
return `profile/${profile}/${account}`;
|
|
3135
|
-
}
|
|
3136
|
-
var spawnSyncOverride;
|
|
3137
|
-
function runSpawnSync(command, args, options) {
|
|
3138
|
-
const spawnFn = spawnSyncOverride ?? spawnSync2;
|
|
3139
|
-
return spawnFn(command, args, options);
|
|
3140
|
-
}
|
|
3141
|
-
function secretSetMacos(storageAccount, value) {
|
|
3142
|
-
const result = runSpawnSync("security", ["add-generic-password", "-U", "-s", "altertable", "-a", storageAccount, "-w", value], { stdio: "ignore" });
|
|
3143
|
-
if (result.status !== 0) {
|
|
3144
|
-
throw new CliError(`Failed to store secret in macOS keychain (${storageAccount}).`);
|
|
3145
|
-
}
|
|
3146
|
-
}
|
|
3147
|
-
function secretSet(account, value, profileName, options) {
|
|
3148
|
-
const storageAccount = resolveSecretAccount(account, profileName);
|
|
3149
|
-
const backend = secretBackend();
|
|
3150
|
-
if (backend === "macos" && !options?.fromArgv) {
|
|
3151
|
-
secretSetMacos(storageAccount, value);
|
|
3152
|
-
return;
|
|
3153
|
-
}
|
|
3154
|
-
const filePath = credentialsFile();
|
|
3155
|
-
kvSet(filePath, storageAccount, value);
|
|
3156
|
-
chmodSync2(filePath, 384);
|
|
3157
|
-
if (backend !== "macos") {
|
|
3158
|
-
warnFileBackendOnce();
|
|
3159
|
-
}
|
|
3160
|
-
}
|
|
3161
|
-
function secretGet(account, profileName) {
|
|
3162
|
-
const storageAccount = resolveSecretAccount(account, profileName);
|
|
3163
|
-
const backend = secretBackend();
|
|
3164
|
-
if (backend === "macos") {
|
|
3165
|
-
const result = runSpawnSync("security", ["find-generic-password", "-s", "altertable", "-a", storageAccount, "-w"], { encoding: "utf8" });
|
|
3166
|
-
const stdout = result.stdout;
|
|
3167
|
-
const keychainValue = result.status === 0 ? String(stdout).trim() : "";
|
|
3168
|
-
if (keychainValue !== "") {
|
|
3169
|
-
return keychainValue;
|
|
3170
|
-
}
|
|
3171
|
-
requireSafeCredentialsFile();
|
|
3172
|
-
return kvGet(credentialsFile(), storageAccount);
|
|
3173
|
-
}
|
|
3174
|
-
requireSafeCredentialsFile();
|
|
3175
|
-
return kvGet(credentialsFile(), storageAccount);
|
|
3176
|
-
}
|
|
3177
|
-
function secretExists(account, profileName) {
|
|
3178
|
-
const storageAccount = resolveSecretAccount(account, profileName);
|
|
3179
|
-
const backend = secretBackend();
|
|
3180
|
-
if (backend === "macos") {
|
|
3181
|
-
const result = runSpawnSync("security", ["find-generic-password", "-s", "altertable", "-a", storageAccount], { stdio: "ignore" });
|
|
3182
|
-
if (result.status === 0) {
|
|
3183
|
-
return true;
|
|
3184
|
-
}
|
|
3185
|
-
requireSafeCredentialsFile();
|
|
3186
|
-
return kvGet(credentialsFile(), storageAccount) !== "";
|
|
3187
|
-
}
|
|
3188
|
-
requireSafeCredentialsFile();
|
|
3189
|
-
return kvGet(credentialsFile(), storageAccount) !== "";
|
|
3190
|
-
}
|
|
3191
|
-
function secretDelete(account, profileName) {
|
|
3192
|
-
const storageAccount = resolveSecretAccount(account, profileName);
|
|
3193
|
-
const backend = secretBackend();
|
|
3194
|
-
if (backend === "macos") {
|
|
3195
|
-
runSpawnSync("security", ["delete-generic-password", "-s", "altertable", "-a", storageAccount], {
|
|
3196
|
-
stdio: "ignore"
|
|
3197
|
-
});
|
|
3198
|
-
kvUnset(credentialsFile(), storageAccount);
|
|
3199
|
-
return;
|
|
3200
|
-
}
|
|
3201
|
-
kvUnset(credentialsFile(), storageAccount);
|
|
3202
|
-
}
|
|
3203
|
-
function moveProfileSecrets(sourceProfile, targetProfile, accounts) {
|
|
3204
|
-
const prepared = [];
|
|
3205
|
-
try {
|
|
3206
|
-
for (const account of accounts) {
|
|
3207
|
-
const sourceValue = secretGet(account, sourceProfile);
|
|
3208
|
-
if (sourceValue.length === 0) {
|
|
3209
|
-
continue;
|
|
3210
|
-
}
|
|
3211
|
-
prepared.push({
|
|
3212
|
-
account,
|
|
3213
|
-
targetValue: secretGet(account, targetProfile)
|
|
3214
|
-
});
|
|
3215
|
-
secretSet(account, sourceValue, targetProfile);
|
|
3216
|
-
}
|
|
3217
|
-
} catch (error) {
|
|
3218
|
-
for (const entry of prepared.toReversed()) {
|
|
3219
|
-
try {
|
|
3220
|
-
if (entry.targetValue.length > 0) {
|
|
3221
|
-
secretSet(entry.account, entry.targetValue, targetProfile);
|
|
3222
|
-
} else {
|
|
3223
|
-
secretDelete(entry.account, targetProfile);
|
|
3224
|
-
}
|
|
3225
|
-
} catch {}
|
|
3226
|
-
}
|
|
3227
|
-
throw error;
|
|
3228
|
-
}
|
|
3229
|
-
for (const { account } of prepared) {
|
|
3230
|
-
secretDelete(account, sourceProfile);
|
|
3231
|
-
}
|
|
3232
|
-
}
|
|
3233
|
-
function secretStoreDisplay() {
|
|
3234
|
-
return secretBackend() === "macos" ? "MacOS keychain" : credentialsFile();
|
|
3235
|
-
}
|
|
3236
|
-
|
|
3237
|
-
// src/lib/auth.ts
|
|
3238
|
-
function basicAuthToken(user, password) {
|
|
3239
|
-
return Buffer.from(`${user}:${password}`).toString("base64");
|
|
3240
|
-
}
|
|
3241
|
-
function basicAuthHeader(token) {
|
|
3242
|
-
return `Authorization: Basic ${token}`;
|
|
3243
|
-
}
|
|
3244
|
-
function storedLakehouseCredentialsExpired() {
|
|
3245
|
-
const raw = configGet("lakehouse_credential_expiry");
|
|
3246
|
-
if (!raw) {
|
|
3247
|
-
return false;
|
|
3248
|
-
}
|
|
3249
|
-
const expiry = Number(raw);
|
|
3250
|
-
if (Number.isNaN(expiry)) {
|
|
3251
|
-
throw new CliError("Stored lakehouse credential expiry is corrupted. Run 'altertable logout' and try again.", { exitCode: EXIT_CONFIG });
|
|
3252
|
-
}
|
|
3253
|
-
return Date.now() >= expiry;
|
|
3254
|
-
}
|
|
3255
|
-
function lakehouseEnvAuthHeader() {
|
|
3256
|
-
const envToken = process.env.ALTERTABLE_BASIC_AUTH_TOKEN;
|
|
3257
|
-
if (envToken) {
|
|
3258
|
-
return basicAuthHeader(envToken);
|
|
3259
|
-
}
|
|
3260
|
-
const envUser = process.env.ALTERTABLE_LAKEHOUSE_USERNAME;
|
|
3261
|
-
const envPassword = process.env.ALTERTABLE_LAKEHOUSE_PASSWORD;
|
|
3262
|
-
if (envUser && envPassword) {
|
|
3263
|
-
return basicAuthHeader(basicAuthToken(envUser, envPassword));
|
|
3264
|
-
}
|
|
3265
|
-
return;
|
|
3266
|
-
}
|
|
3267
|
-
function hasLakehouseEnvCredentials() {
|
|
3268
|
-
return lakehouseEnvAuthHeader() !== undefined;
|
|
3269
|
-
}
|
|
3270
|
-
function getLakehouseAuthHeader() {
|
|
3271
|
-
const envHeader = lakehouseEnvAuthHeader();
|
|
3272
|
-
if (envHeader) {
|
|
3273
|
-
return envHeader;
|
|
3274
|
-
}
|
|
3275
|
-
if (!storedLakehouseCredentialsExpired()) {
|
|
3276
|
-
const storedToken = secretGet("lakehouse/basic-token");
|
|
3277
|
-
if (storedToken) {
|
|
3278
|
-
return basicAuthHeader(storedToken);
|
|
3279
|
-
}
|
|
3280
|
-
const user = configGet("user");
|
|
3281
|
-
const password = secretGet("lakehouse/password");
|
|
3282
|
-
if (user && password) {
|
|
3283
|
-
return basicAuthHeader(basicAuthToken(user, password));
|
|
3284
|
-
}
|
|
3285
|
-
}
|
|
3286
|
-
throw new ConfigurationError("No credentials. Run 'altertable login', 'altertable profile --configure', or set ALTERTABLE_LAKEHOUSE_USERNAME/PASSWORD (or ALTERTABLE_BASIC_AUTH_TOKEN).");
|
|
3287
|
-
}
|
|
3288
|
-
function decodeBasicToken(token) {
|
|
3289
|
-
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
3290
|
-
const [user, password] = decoded.split(":");
|
|
3291
|
-
if (!user || !password) {
|
|
3292
|
-
return;
|
|
3293
|
-
}
|
|
3294
|
-
return { user, password };
|
|
3295
|
-
}
|
|
3296
|
-
function getLoginLakehouseCredentials() {
|
|
3297
|
-
if (storedLakehouseCredentialsExpired()) {
|
|
3298
|
-
return;
|
|
3299
|
-
}
|
|
3300
|
-
const token = secretGet("lakehouse/basic-token");
|
|
3301
|
-
return token ? decodeBasicToken(token) : undefined;
|
|
3302
|
-
}
|
|
3303
|
-
function getManagementAuthHeader() {
|
|
3304
|
-
const envKey = process.env.ALTERTABLE_API_KEY ?? "";
|
|
3305
|
-
if (envKey) {
|
|
3306
|
-
return `Authorization: Bearer ${envKey}`;
|
|
3307
|
-
}
|
|
3308
|
-
const oauthToken = secretGet("oauth/access-token");
|
|
3309
|
-
if (oauthToken) {
|
|
3310
|
-
return `Authorization: Bearer ${oauthToken}`;
|
|
3311
|
-
}
|
|
3312
|
-
const key = secretGet("api-key");
|
|
3313
|
-
if (!key) {
|
|
3314
|
-
throw new ConfigurationError("No management credentials. Run 'altertable login', 'altertable profile --configure --api-key atm_xxx --env <name>', or set ALTERTABLE_API_KEY.");
|
|
3315
|
-
}
|
|
3316
|
-
return `Authorization: Bearer ${key}`;
|
|
3317
|
-
}
|
|
3318
|
-
function managementEnv() {
|
|
3319
|
-
return process.env.ALTERTABLE_ENV ?? configGet("api_key_env");
|
|
3320
|
-
}
|
|
3321
|
-
function requireManagementEnv() {
|
|
3322
|
-
const env = managementEnv();
|
|
3323
|
-
if (!env) {
|
|
3324
|
-
throw new ConfigurationError("No environment set. Run 'altertable profile --configure --api-key atm_xxx --env <name>' or set ALTERTABLE_ENV.");
|
|
3325
|
-
}
|
|
3326
|
-
return env;
|
|
3327
|
-
}
|
|
3328
|
-
|
|
3329
3035
|
// src/lib/cli-session.ts
|
|
3330
|
-
function tryAuthHeader(resolve2) {
|
|
3331
|
-
try {
|
|
3332
|
-
return resolve2();
|
|
3333
|
-
} catch (error) {
|
|
3334
|
-
if (error instanceof ConfigurationError) {
|
|
3335
|
-
return;
|
|
3336
|
-
}
|
|
3337
|
-
throw error;
|
|
3338
|
-
}
|
|
3339
|
-
}
|
|
3340
|
-
function resolveOptionalManagementEnv() {
|
|
3341
|
-
const env = process.env.ALTERTABLE_ENV ?? configGet("api_key_env");
|
|
3342
|
-
return env.length > 0 ? env : undefined;
|
|
3343
|
-
}
|
|
3344
3036
|
function createCliSession(context) {
|
|
3345
|
-
const profile = resolveProfileName(context.profile ?? process.env.ALTERTABLE_PROFILE);
|
|
3346
3037
|
return {
|
|
3347
|
-
profile
|
|
3348
|
-
apiBase: resolveApiBase(),
|
|
3349
|
-
managementApiBase: resolveManagementApiBase(),
|
|
3350
|
-
lakehouseAuthHeader: tryAuthHeader(getLakehouseAuthHeader),
|
|
3351
|
-
managementAuthHeader: tryAuthHeader(getManagementAuthHeader),
|
|
3352
|
-
managementEnv: resolveOptionalManagementEnv()
|
|
3038
|
+
profile: resolveWorkingProfile(context.profile)
|
|
3353
3039
|
};
|
|
3354
3040
|
}
|
|
3355
3041
|
|
|
@@ -3565,10 +3251,6 @@ function defineRootCommand(def) {
|
|
|
3565
3251
|
}
|
|
3566
3252
|
|
|
3567
3253
|
// src/lib/execution-context.ts
|
|
3568
|
-
var PLANE_AUTH_RESOLVERS = {
|
|
3569
|
-
lakehouse: getLakehouseAuthHeader,
|
|
3570
|
-
management: getManagementAuthHeader
|
|
3571
|
-
};
|
|
3572
3254
|
function optionalAuth(resolve2) {
|
|
3573
3255
|
try {
|
|
3574
3256
|
return resolve2();
|
|
@@ -3583,25 +3265,23 @@ function createExecutionContext(runtime) {
|
|
|
3583
3265
|
return {
|
|
3584
3266
|
cli: runtime.context,
|
|
3585
3267
|
output: runtime.output,
|
|
3586
|
-
profile: runtime.session?.profile
|
|
3587
|
-
endpoints: {
|
|
3588
|
-
lakehouse: runtime.session?.apiBase ?? resolveApiBase(),
|
|
3589
|
-
management: runtime.session?.managementApiBase ?? resolveManagementApiBase()
|
|
3590
|
-
},
|
|
3591
|
-
auth: {
|
|
3592
|
-
lakehouse: runtime.session?.lakehouseAuthHeader ?? optionalAuth(getLakehouseAuthHeader),
|
|
3593
|
-
management: runtime.session?.managementAuthHeader ?? optionalAuth(getManagementAuthHeader)
|
|
3594
|
-
},
|
|
3595
|
-
managementEnv: runtime.session?.managementEnv
|
|
3268
|
+
profile: runtime.session?.profile ?? resolveWorkingProfile(runtime.context.profile)
|
|
3596
3269
|
};
|
|
3597
3270
|
}
|
|
3598
|
-
function requirePlaneAuth(context, plane) {
|
|
3599
|
-
return context.auth[plane] ?? PLANE_AUTH_RESOLVERS[plane]();
|
|
3600
|
-
}
|
|
3601
3271
|
|
|
3602
3272
|
// src/lib/http.ts
|
|
3603
3273
|
import { appendFileSync } from "fs";
|
|
3604
3274
|
|
|
3275
|
+
// src/lib/log.ts
|
|
3276
|
+
function logDebug(message) {
|
|
3277
|
+
if (getCliContext().debug) {
|
|
3278
|
+
console.error(`[DEBUG] ${message}`);
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
function logWarn(message) {
|
|
3282
|
+
console.error(`[WARN] ${message}`);
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3605
3285
|
// src/lib/sleep.ts
|
|
3606
3286
|
function sleep(milliseconds) {
|
|
3607
3287
|
return new Promise((resolve2) => {
|
|
@@ -4063,6 +3743,257 @@ function encodeManagementEndpoint(endpoint) {
|
|
|
4063
3743
|
return `${encodeManagementPath(path)}${query}`;
|
|
4064
3744
|
}
|
|
4065
3745
|
|
|
3746
|
+
// src/lib/secrets.ts
|
|
3747
|
+
import { chmodSync as chmodSync2, statSync } from "fs";
|
|
3748
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
3749
|
+
var fileBackendWarned = false;
|
|
3750
|
+
function fileMode(filePath) {
|
|
3751
|
+
try {
|
|
3752
|
+
const stat = statSync(filePath);
|
|
3753
|
+
return (stat.mode & 511).toString(8);
|
|
3754
|
+
} catch {
|
|
3755
|
+
return "";
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
function requireSafeCredentialsFile() {
|
|
3759
|
+
const filePath = credentialsFile();
|
|
3760
|
+
try {
|
|
3761
|
+
statSync(filePath);
|
|
3762
|
+
} catch {
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3765
|
+
const mode = fileMode(filePath);
|
|
3766
|
+
if (!mode) {
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
const modeNumber = Number.parseInt(mode, 8);
|
|
3770
|
+
if (modeNumber & 63) {
|
|
3771
|
+
throw new CliError(`Refusing to read ${filePath}: permissions ${mode} are too open (group/other access). Run: chmod 600 ${filePath}`);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
function warnFileBackendOnce() {
|
|
3775
|
+
if (!fileBackendWarned) {
|
|
3776
|
+
logWarn(`No macOS keychain; storing secrets at ${credentialsFile()} (chmod 600). Prefer environment variables in CI.`);
|
|
3777
|
+
fileBackendWarned = true;
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
function hasSecurityCommand() {
|
|
3781
|
+
const result = runSpawnSync("security", ["help"], { stdio: "ignore" });
|
|
3782
|
+
return result.status === 0 || result.error === undefined;
|
|
3783
|
+
}
|
|
3784
|
+
function secretBackend() {
|
|
3785
|
+
const override = process.env.ALTERTABLE_SECRET_BACKEND ?? "";
|
|
3786
|
+
if (override === "file") {
|
|
3787
|
+
return "file";
|
|
3788
|
+
}
|
|
3789
|
+
if (override === "keychain") {
|
|
3790
|
+
if (process.platform === "darwin" && hasSecurityCommand()) {
|
|
3791
|
+
return "macos";
|
|
3792
|
+
}
|
|
3793
|
+
throw new CliError("ALTERTABLE_SECRET_BACKEND=keychain but the macOS keychain is unavailable.");
|
|
3794
|
+
}
|
|
3795
|
+
if (process.platform === "darwin" && hasSecurityCommand()) {
|
|
3796
|
+
return "macos";
|
|
3797
|
+
}
|
|
3798
|
+
return "file";
|
|
3799
|
+
}
|
|
3800
|
+
function resolveSecretKey(key, profileName) {
|
|
3801
|
+
assertSafeProfileName(profileName);
|
|
3802
|
+
return `profile/${profileName}/${key}`;
|
|
3803
|
+
}
|
|
3804
|
+
var spawnSyncOverride;
|
|
3805
|
+
function runSpawnSync(command, args, options) {
|
|
3806
|
+
const spawnFn = spawnSyncOverride ?? spawnSync2;
|
|
3807
|
+
return spawnFn(command, args, options);
|
|
3808
|
+
}
|
|
3809
|
+
function secretSetMacos(storageAccount, value) {
|
|
3810
|
+
const result = runSpawnSync("security", ["add-generic-password", "-U", "-s", "altertable", "-a", storageAccount, "-w", value], { stdio: "ignore" });
|
|
3811
|
+
if (result.status !== 0) {
|
|
3812
|
+
throw new CliError(`Failed to store secret in macOS keychain (${storageAccount}).`);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
function secretSet(account, value, profileName, options) {
|
|
3816
|
+
const storageAccount = resolveSecretKey(account, profileName);
|
|
3817
|
+
const backend = secretBackend();
|
|
3818
|
+
if (backend === "macos" && !options?.fromArgv) {
|
|
3819
|
+
secretSetMacos(storageAccount, value);
|
|
3820
|
+
return;
|
|
3821
|
+
}
|
|
3822
|
+
const filePath = credentialsFile();
|
|
3823
|
+
kvSet(filePath, storageAccount, value);
|
|
3824
|
+
chmodSync2(filePath, 384);
|
|
3825
|
+
if (backend !== "macos") {
|
|
3826
|
+
warnFileBackendOnce();
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
function secretGet(key, profileName) {
|
|
3830
|
+
const secretKey = resolveSecretKey(key, profileName);
|
|
3831
|
+
const backend = secretBackend();
|
|
3832
|
+
if (backend === "macos") {
|
|
3833
|
+
const result = runSpawnSync("security", ["find-generic-password", "-s", "altertable", "-a", secretKey, "-w"], { encoding: "utf8" });
|
|
3834
|
+
const stdout = result.stdout;
|
|
3835
|
+
const keychainValue = result.status === 0 ? String(stdout).trim() : "";
|
|
3836
|
+
if (keychainValue !== "") {
|
|
3837
|
+
return keychainValue;
|
|
3838
|
+
}
|
|
3839
|
+
requireSafeCredentialsFile();
|
|
3840
|
+
return kvGet(credentialsFile(), secretKey);
|
|
3841
|
+
}
|
|
3842
|
+
requireSafeCredentialsFile();
|
|
3843
|
+
return kvGet(credentialsFile(), secretKey);
|
|
3844
|
+
}
|
|
3845
|
+
function secretExists(key, profileName) {
|
|
3846
|
+
const secretKey = resolveSecretKey(key, profileName);
|
|
3847
|
+
const backend = secretBackend();
|
|
3848
|
+
if (backend === "macos") {
|
|
3849
|
+
const result = runSpawnSync("security", ["find-generic-password", "-s", "altertable", "-a", secretKey], { stdio: "ignore" });
|
|
3850
|
+
if (result.status === 0) {
|
|
3851
|
+
return true;
|
|
3852
|
+
}
|
|
3853
|
+
requireSafeCredentialsFile();
|
|
3854
|
+
return kvGet(credentialsFile(), secretKey) !== "";
|
|
3855
|
+
}
|
|
3856
|
+
requireSafeCredentialsFile();
|
|
3857
|
+
return kvGet(credentialsFile(), secretKey) !== "";
|
|
3858
|
+
}
|
|
3859
|
+
function secretDelete(key, profileName) {
|
|
3860
|
+
const secretKey = resolveSecretKey(key, profileName);
|
|
3861
|
+
const backend = secretBackend();
|
|
3862
|
+
if (backend === "macos") {
|
|
3863
|
+
runSpawnSync("security", ["delete-generic-password", "-s", "altertable", "-a", secretKey], {
|
|
3864
|
+
stdio: "ignore"
|
|
3865
|
+
});
|
|
3866
|
+
kvUnset(credentialsFile(), secretKey);
|
|
3867
|
+
return;
|
|
3868
|
+
}
|
|
3869
|
+
kvUnset(credentialsFile(), secretKey);
|
|
3870
|
+
}
|
|
3871
|
+
function moveProfileSecrets(sourceProfile, targetProfile, keys) {
|
|
3872
|
+
const prepared = [];
|
|
3873
|
+
try {
|
|
3874
|
+
for (const key of keys) {
|
|
3875
|
+
const sourceValue = secretGet(key, sourceProfile);
|
|
3876
|
+
if (sourceValue.length === 0) {
|
|
3877
|
+
continue;
|
|
3878
|
+
}
|
|
3879
|
+
prepared.push({
|
|
3880
|
+
key,
|
|
3881
|
+
targetValue: secretGet(key, targetProfile)
|
|
3882
|
+
});
|
|
3883
|
+
secretSet(key, sourceValue, targetProfile);
|
|
3884
|
+
}
|
|
3885
|
+
} catch (error) {
|
|
3886
|
+
for (const entry of prepared.toReversed()) {
|
|
3887
|
+
try {
|
|
3888
|
+
if (entry.targetValue.length > 0) {
|
|
3889
|
+
secretSet(entry.key, entry.targetValue, targetProfile);
|
|
3890
|
+
} else {
|
|
3891
|
+
secretDelete(entry.key, targetProfile);
|
|
3892
|
+
}
|
|
3893
|
+
} catch {}
|
|
3894
|
+
}
|
|
3895
|
+
throw error;
|
|
3896
|
+
}
|
|
3897
|
+
for (const { key } of prepared) {
|
|
3898
|
+
secretDelete(key, sourceProfile);
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
function secretStoreDisplay() {
|
|
3902
|
+
return secretBackend() === "macos" ? "MacOS keychain" : credentialsFile();
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
// src/lib/auth.ts
|
|
3906
|
+
function basicAuthToken(user, password) {
|
|
3907
|
+
return Buffer.from(`${user}:${password}`).toString("base64");
|
|
3908
|
+
}
|
|
3909
|
+
function basicAuthHeader(token) {
|
|
3910
|
+
return `Authorization: Basic ${token}`;
|
|
3911
|
+
}
|
|
3912
|
+
function storedLakehouseCredentialsExpired(profileName) {
|
|
3913
|
+
const raw = configGet("lakehouse_credential_expiry", profileName);
|
|
3914
|
+
if (!raw) {
|
|
3915
|
+
return false;
|
|
3916
|
+
}
|
|
3917
|
+
const expiry = Number(raw);
|
|
3918
|
+
if (Number.isNaN(expiry)) {
|
|
3919
|
+
throw new CliError("Stored lakehouse credential expiry is corrupted. Run 'altertable logout' and try again.", { exitCode: EXIT_CONFIG });
|
|
3920
|
+
}
|
|
3921
|
+
return Date.now() >= expiry;
|
|
3922
|
+
}
|
|
3923
|
+
function lakehouseEnvAuthHeader() {
|
|
3924
|
+
const envToken = process.env.ALTERTABLE_BASIC_AUTH_TOKEN;
|
|
3925
|
+
if (envToken) {
|
|
3926
|
+
return basicAuthHeader(envToken);
|
|
3927
|
+
}
|
|
3928
|
+
const envUser = process.env.ALTERTABLE_LAKEHOUSE_USERNAME;
|
|
3929
|
+
const envPassword = process.env.ALTERTABLE_LAKEHOUSE_PASSWORD;
|
|
3930
|
+
if (envUser && envPassword) {
|
|
3931
|
+
return basicAuthHeader(basicAuthToken(envUser, envPassword));
|
|
3932
|
+
}
|
|
3933
|
+
return;
|
|
3934
|
+
}
|
|
3935
|
+
function hasLakehouseEnvCredentials() {
|
|
3936
|
+
return lakehouseEnvAuthHeader() !== undefined;
|
|
3937
|
+
}
|
|
3938
|
+
function getLakehouseAuthHeader(profileName) {
|
|
3939
|
+
const envHeader = lakehouseEnvAuthHeader();
|
|
3940
|
+
if (envHeader) {
|
|
3941
|
+
return envHeader;
|
|
3942
|
+
}
|
|
3943
|
+
if (!storedLakehouseCredentialsExpired(profileName)) {
|
|
3944
|
+
const storedToken = secretGet("lakehouse/basic-token", profileName);
|
|
3945
|
+
if (storedToken) {
|
|
3946
|
+
return basicAuthHeader(storedToken);
|
|
3947
|
+
}
|
|
3948
|
+
const user = configGet("user", profileName);
|
|
3949
|
+
const password = secretGet("lakehouse/password", profileName);
|
|
3950
|
+
if (user && password) {
|
|
3951
|
+
return basicAuthHeader(basicAuthToken(user, password));
|
|
3952
|
+
}
|
|
3953
|
+
}
|
|
3954
|
+
throw new ConfigurationError("No credentials. Run 'altertable login', 'altertable profile --configure', or set ALTERTABLE_LAKEHOUSE_USERNAME/PASSWORD (or ALTERTABLE_BASIC_AUTH_TOKEN).");
|
|
3955
|
+
}
|
|
3956
|
+
function decodeBasicToken(token) {
|
|
3957
|
+
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
3958
|
+
const [user, password] = decoded.split(":");
|
|
3959
|
+
if (!user || !password) {
|
|
3960
|
+
return;
|
|
3961
|
+
}
|
|
3962
|
+
return { user, password };
|
|
3963
|
+
}
|
|
3964
|
+
function getLoginLakehouseCredentials(profileName) {
|
|
3965
|
+
if (storedLakehouseCredentialsExpired(profileName)) {
|
|
3966
|
+
return;
|
|
3967
|
+
}
|
|
3968
|
+
const token = secretGet("lakehouse/basic-token", profileName);
|
|
3969
|
+
return token ? decodeBasicToken(token) : undefined;
|
|
3970
|
+
}
|
|
3971
|
+
function getManagementAuthHeader(profileName) {
|
|
3972
|
+
const envKey = process.env.ALTERTABLE_API_KEY ?? "";
|
|
3973
|
+
if (envKey) {
|
|
3974
|
+
return `Authorization: Bearer ${envKey}`;
|
|
3975
|
+
}
|
|
3976
|
+
const oauthToken = secretGet("oauth/access-token", profileName);
|
|
3977
|
+
if (oauthToken) {
|
|
3978
|
+
return `Authorization: Bearer ${oauthToken}`;
|
|
3979
|
+
}
|
|
3980
|
+
const key = secretGet("api-key", profileName);
|
|
3981
|
+
if (!key) {
|
|
3982
|
+
throw new ConfigurationError("No management credentials. Run 'altertable login', 'altertable profile --configure --api-key atm_xxx --env <name>', or set ALTERTABLE_API_KEY.");
|
|
3983
|
+
}
|
|
3984
|
+
return `Authorization: Bearer ${key}`;
|
|
3985
|
+
}
|
|
3986
|
+
function managementEnv(profileName) {
|
|
3987
|
+
return process.env.ALTERTABLE_ENV ?? configGet("api_key_env", profileName);
|
|
3988
|
+
}
|
|
3989
|
+
function requireManagementEnv(profileName) {
|
|
3990
|
+
const env = managementEnv(profileName);
|
|
3991
|
+
if (!env) {
|
|
3992
|
+
throw new ConfigurationError("No environment set. Run 'altertable profile --configure --api-key atm_xxx --env <name>' or set ALTERTABLE_ENV.");
|
|
3993
|
+
}
|
|
3994
|
+
return env;
|
|
3995
|
+
}
|
|
3996
|
+
|
|
4066
3997
|
// node_modules/oauth4webapi/build/index.js
|
|
4067
3998
|
var USER_AGENT2;
|
|
4068
3999
|
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
|
|
@@ -5279,7 +5210,7 @@ function parseCallback(requestUrl, expectedState) {
|
|
|
5279
5210
|
}
|
|
5280
5211
|
return { ok: true, code };
|
|
5281
5212
|
}
|
|
5282
|
-
function buildAuthorizeUrl(params) {
|
|
5213
|
+
function buildAuthorizeUrl(params, oauthBase) {
|
|
5283
5214
|
const query = new URLSearchParams({
|
|
5284
5215
|
response_type: "code",
|
|
5285
5216
|
client_id: oauthClientId(),
|
|
@@ -5292,14 +5223,13 @@ function buildAuthorizeUrl(params) {
|
|
|
5292
5223
|
if (scope) {
|
|
5293
5224
|
query.set("scope", scope);
|
|
5294
5225
|
}
|
|
5295
|
-
return `${
|
|
5226
|
+
return `${oauthBase}/authorize?${query.toString()}`;
|
|
5296
5227
|
}
|
|
5297
|
-
function resolveAuthServer() {
|
|
5298
|
-
const base = resolveOAuthBase();
|
|
5228
|
+
function resolveAuthServer(oauthBase) {
|
|
5299
5229
|
return {
|
|
5300
|
-
issuer:
|
|
5301
|
-
authorization_endpoint: `${
|
|
5302
|
-
token_endpoint: `${
|
|
5230
|
+
issuer: oauthBase.replace(/\/oauth$/, ""),
|
|
5231
|
+
authorization_endpoint: `${oauthBase}/authorize`,
|
|
5232
|
+
token_endpoint: `${oauthBase}/token`
|
|
5303
5233
|
};
|
|
5304
5234
|
}
|
|
5305
5235
|
function resolveOauthClient() {
|
|
@@ -5323,9 +5253,9 @@ async function httpSendFetch(url, options) {
|
|
|
5323
5253
|
headers: { "content-type": "application/json" }
|
|
5324
5254
|
});
|
|
5325
5255
|
}
|
|
5326
|
-
function tokenRequestOptions() {
|
|
5256
|
+
function tokenRequestOptions(oauthBase) {
|
|
5327
5257
|
const options = { [customFetch]: httpSendFetch };
|
|
5328
|
-
if (
|
|
5258
|
+
if (oauthBase.startsWith("http://")) {
|
|
5329
5259
|
options[allowInsecureRequests] = true;
|
|
5330
5260
|
}
|
|
5331
5261
|
return options;
|
|
@@ -5338,17 +5268,17 @@ function toTokenResponse(result) {
|
|
|
5338
5268
|
token_type: result.token_type
|
|
5339
5269
|
};
|
|
5340
5270
|
}
|
|
5341
|
-
async function exchangeCode(params) {
|
|
5342
|
-
const authServer = resolveAuthServer();
|
|
5271
|
+
async function exchangeCode(params, oauthBase) {
|
|
5272
|
+
const authServer = resolveAuthServer(oauthBase);
|
|
5343
5273
|
const client = resolveOauthClient();
|
|
5344
5274
|
const callbackParameters = validateAuthResponse(authServer, client, new URLSearchParams({ code: params.code }), skipStateCheck);
|
|
5345
|
-
const response = await authorizationCodeGrantRequest(authServer, client, None(), callbackParameters, params.redirectUri, params.verifier, tokenRequestOptions());
|
|
5275
|
+
const response = await authorizationCodeGrantRequest(authServer, client, None(), callbackParameters, params.redirectUri, params.verifier, tokenRequestOptions(oauthBase));
|
|
5346
5276
|
return toTokenResponse(await processAuthorizationCodeResponse(authServer, client, response));
|
|
5347
5277
|
}
|
|
5348
|
-
async function refreshAccessToken(refreshToken) {
|
|
5349
|
-
const authServer = resolveAuthServer();
|
|
5278
|
+
async function refreshAccessToken(refreshToken, oauthBase) {
|
|
5279
|
+
const authServer = resolveAuthServer(oauthBase);
|
|
5350
5280
|
const client = resolveOauthClient();
|
|
5351
|
-
const response = await refreshTokenGrantRequest(authServer, client, None(), refreshToken, tokenRequestOptions());
|
|
5281
|
+
const response = await refreshTokenGrantRequest(authServer, client, None(), refreshToken, tokenRequestOptions(oauthBase));
|
|
5352
5282
|
return toTokenResponse(await processRefreshTokenResponse(authServer, client, response));
|
|
5353
5283
|
}
|
|
5354
5284
|
function redirectPort() {
|
|
@@ -5408,18 +5338,18 @@ function openBrowser(url) {
|
|
|
5408
5338
|
child.unref();
|
|
5409
5339
|
} catch {}
|
|
5410
5340
|
}
|
|
5411
|
-
async function runLoginFlow(sink) {
|
|
5341
|
+
async function runLoginFlow(sink, oauthBase) {
|
|
5412
5342
|
const verifier = generateRandomCodeVerifier();
|
|
5413
5343
|
const challenge = await calculatePKCECodeChallenge(verifier);
|
|
5414
5344
|
const state = generateRandomState();
|
|
5415
5345
|
const server = await startLoopbackServer(state);
|
|
5416
5346
|
try {
|
|
5417
|
-
const authorizeUrl = buildAuthorizeUrl({ redirectUri: server.redirectUri, challenge, state });
|
|
5347
|
+
const authorizeUrl = buildAuthorizeUrl({ redirectUri: server.redirectUri, challenge, state }, oauthBase);
|
|
5418
5348
|
sink.writeMetadata([terminalMetadata("Opening your browser to sign in\u2026")]);
|
|
5419
5349
|
sink.writeMetadata([terminalMetadata(`If it doesn't open, visit: ${authorizeUrl}`)]);
|
|
5420
5350
|
openBrowser(authorizeUrl);
|
|
5421
5351
|
const code = await server.waitForCode();
|
|
5422
|
-
return await exchangeCode({ code, redirectUri: server.redirectUri, verifier });
|
|
5352
|
+
return await exchangeCode({ code, redirectUri: server.redirectUri, verifier }, oauthBase);
|
|
5423
5353
|
} finally {
|
|
5424
5354
|
server.close();
|
|
5425
5355
|
}
|
|
@@ -5430,27 +5360,27 @@ var ACCESS_TOKEN_ACCOUNT = "oauth/access-token";
|
|
|
5430
5360
|
var REFRESH_TOKEN_ACCOUNT = "oauth/refresh-token";
|
|
5431
5361
|
var OAUTH_EXPIRY_KEY = "oauth_expiry";
|
|
5432
5362
|
var REFRESH_SKEW_MS = 60000;
|
|
5433
|
-
function storeOAuthTokens(oauthResponse) {
|
|
5434
|
-
secretSet(ACCESS_TOKEN_ACCOUNT, oauthResponse.access_token);
|
|
5363
|
+
function storeOAuthTokens(oauthResponse, profileName) {
|
|
5364
|
+
secretSet(ACCESS_TOKEN_ACCOUNT, oauthResponse.access_token, profileName);
|
|
5435
5365
|
if (oauthResponse.refresh_token) {
|
|
5436
|
-
secretSet(REFRESH_TOKEN_ACCOUNT, oauthResponse.refresh_token);
|
|
5366
|
+
secretSet(REFRESH_TOKEN_ACCOUNT, oauthResponse.refresh_token, profileName);
|
|
5437
5367
|
}
|
|
5438
5368
|
const expiresInMs = (oauthResponse.expires_in ?? 0) * 1000;
|
|
5439
|
-
configSet(OAUTH_EXPIRY_KEY, String(Date.now() + expiresInMs));
|
|
5369
|
+
configSet(OAUTH_EXPIRY_KEY, String(Date.now() + expiresInMs), profileName);
|
|
5440
5370
|
}
|
|
5441
|
-
function clearOAuthTokens() {
|
|
5442
|
-
secretDelete(ACCESS_TOKEN_ACCOUNT);
|
|
5443
|
-
secretDelete(REFRESH_TOKEN_ACCOUNT);
|
|
5444
|
-
|
|
5371
|
+
function clearOAuthTokens(profileName) {
|
|
5372
|
+
secretDelete(ACCESS_TOKEN_ACCOUNT, profileName);
|
|
5373
|
+
secretDelete(REFRESH_TOKEN_ACCOUNT, profileName);
|
|
5374
|
+
configSet(OAUTH_EXPIRY_KEY, "", profileName);
|
|
5445
5375
|
}
|
|
5446
|
-
function hasOAuthSession() {
|
|
5447
|
-
return configGet(OAUTH_EXPIRY_KEY) !== "";
|
|
5376
|
+
function hasOAuthSession(profileName) {
|
|
5377
|
+
return configGet(OAUTH_EXPIRY_KEY, profileName) !== "";
|
|
5448
5378
|
}
|
|
5449
|
-
async function ensureFreshAccessToken() {
|
|
5379
|
+
async function ensureFreshAccessToken(profileName) {
|
|
5450
5380
|
if (process.env.ALTERTABLE_API_KEY) {
|
|
5451
5381
|
return;
|
|
5452
5382
|
}
|
|
5453
|
-
const expiryRaw = configGet(OAUTH_EXPIRY_KEY);
|
|
5383
|
+
const expiryRaw = configGet(OAUTH_EXPIRY_KEY, profileName);
|
|
5454
5384
|
if (!expiryRaw) {
|
|
5455
5385
|
return;
|
|
5456
5386
|
}
|
|
@@ -5458,40 +5388,40 @@ async function ensureFreshAccessToken() {
|
|
|
5458
5388
|
if (Number.isNaN(expiry) || Date.now() < expiry - REFRESH_SKEW_MS) {
|
|
5459
5389
|
return;
|
|
5460
5390
|
}
|
|
5461
|
-
const refreshToken = secretGet(REFRESH_TOKEN_ACCOUNT);
|
|
5391
|
+
const refreshToken = secretGet(REFRESH_TOKEN_ACCOUNT, profileName);
|
|
5462
5392
|
if (!refreshToken) {
|
|
5463
5393
|
return;
|
|
5464
5394
|
}
|
|
5465
5395
|
let oauthResponse;
|
|
5466
5396
|
try {
|
|
5467
|
-
oauthResponse = await refreshAccessToken(refreshToken);
|
|
5397
|
+
oauthResponse = await refreshAccessToken(refreshToken, resolveOAuthBase(profileName));
|
|
5468
5398
|
} catch (error) {
|
|
5469
5399
|
if (error instanceof HttpError && (error.status === 400 || error.status === 401)) {
|
|
5470
|
-
clearOAuthTokens();
|
|
5400
|
+
clearOAuthTokens(profileName);
|
|
5471
5401
|
throw new ConfigurationError("Your login session expired or was revoked. Run 'altertable login' to sign in again.");
|
|
5472
5402
|
}
|
|
5473
5403
|
throw error;
|
|
5474
5404
|
}
|
|
5475
|
-
storeOAuthTokens(oauthResponse);
|
|
5405
|
+
storeOAuthTokens(oauthResponse, profileName);
|
|
5476
5406
|
}
|
|
5477
5407
|
|
|
5478
5408
|
// src/lib/lakehouse-provision.ts
|
|
5479
5409
|
var CREDENTIAL_LABEL = USER_AGENT;
|
|
5480
5410
|
var CREDENTIAL_TTL_MS = 2 * 60 * 60 * 1000;
|
|
5481
|
-
function hasManagementCredentials() {
|
|
5482
|
-
return optionalAuth(getManagementAuthHeader) !== undefined;
|
|
5411
|
+
function hasManagementCredentials(profileName) {
|
|
5412
|
+
return optionalAuth(() => getManagementAuthHeader(profileName)) !== undefined;
|
|
5483
5413
|
}
|
|
5484
|
-
function canRecoverLakehouseAuth() {
|
|
5485
|
-
return !hasLakehouseEnvCredentials() && configGet("lakehouse_credential_expiry") !== "" && hasManagementCredentials();
|
|
5414
|
+
function canRecoverLakehouseAuth(profileName) {
|
|
5415
|
+
return !hasLakehouseEnvCredentials() && configGet("lakehouse_credential_expiry", profileName) !== "" && hasManagementCredentials(profileName);
|
|
5486
5416
|
}
|
|
5487
5417
|
async function sendManagementRequest(context, method, endpoint, body) {
|
|
5488
|
-
if (hasOAuthSession()) {
|
|
5489
|
-
await ensureFreshAccessToken();
|
|
5418
|
+
if (hasOAuthSession(context.profile)) {
|
|
5419
|
+
await ensureFreshAccessToken(context.profile);
|
|
5490
5420
|
}
|
|
5491
5421
|
const response = await httpSend({
|
|
5492
5422
|
method,
|
|
5493
|
-
url: `${context.
|
|
5494
|
-
authHeader: getManagementAuthHeader(),
|
|
5423
|
+
url: `${resolveManagementApiBase(context.profile)}${encodeManagementEndpoint(endpoint)}`,
|
|
5424
|
+
authHeader: getManagementAuthHeader(context.profile),
|
|
5495
5425
|
body,
|
|
5496
5426
|
contentType: body === undefined ? undefined : "application/json",
|
|
5497
5427
|
authPlane: "management"
|
|
@@ -5500,7 +5430,7 @@ async function sendManagementRequest(context, method, endpoint, body) {
|
|
|
5500
5430
|
}
|
|
5501
5431
|
async function provisionLakehouseCredential(context) {
|
|
5502
5432
|
context.output.writeMetadata([terminalMuted("Refreshing lakehouse credentials...")]);
|
|
5503
|
-
const env = context.
|
|
5433
|
+
const env = requireManagementEnv(context.profile);
|
|
5504
5434
|
const whoami = await sendManagementRequest(context, "GET", "/whoami");
|
|
5505
5435
|
const principal = whoami.principal;
|
|
5506
5436
|
if (!principal?.id || principal.type !== "User") {
|
|
@@ -5518,30 +5448,34 @@ async function provisionLakehouseCredential(context) {
|
|
|
5518
5448
|
throw new ConfigurationError("Credential creation response was missing an expiry.");
|
|
5519
5449
|
}
|
|
5520
5450
|
const token = basicAuthToken(username, password);
|
|
5521
|
-
secretSet("lakehouse/basic-token", token);
|
|
5522
|
-
configSet("lakehouse_credential_expiry", String(expiryMs));
|
|
5451
|
+
secretSet("lakehouse/basic-token", token, context.profile);
|
|
5452
|
+
configSet("lakehouse_credential_expiry", String(expiryMs), context.profile);
|
|
5523
5453
|
return basicAuthHeader(token);
|
|
5524
5454
|
}
|
|
5525
5455
|
|
|
5526
5456
|
// src/lib/operation-transport.ts
|
|
5527
5457
|
var PLANE_URL_BUILDERS = {
|
|
5528
|
-
lakehouse: (endpoint, context) => `${context.
|
|
5529
|
-
management: (endpoint, context) => `${context.
|
|
5458
|
+
lakehouse: (endpoint, context) => `${resolveApiBase(context.profile)}${endpoint}`,
|
|
5459
|
+
management: (endpoint, context) => `${resolveManagementApiBase(context.profile)}${encodeManagementEndpoint(endpoint)}`
|
|
5530
5460
|
};
|
|
5531
5461
|
function resolvePlaneUrl(request, context) {
|
|
5532
5462
|
return PLANE_URL_BUILDERS[request.plane](request.endpoint, context);
|
|
5533
5463
|
}
|
|
5534
5464
|
async function resolveRequestAuthHeader(request, context) {
|
|
5535
|
-
if (request.plane === "management"
|
|
5536
|
-
|
|
5537
|
-
|
|
5465
|
+
if (request.plane === "management") {
|
|
5466
|
+
if (hasOAuthSession(context.profile)) {
|
|
5467
|
+
await ensureFreshAccessToken(context.profile);
|
|
5468
|
+
}
|
|
5469
|
+
return getManagementAuthHeader(context.profile);
|
|
5538
5470
|
}
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
return header;
|
|
5471
|
+
const existing = optionalAuth(() => getLakehouseAuthHeader(context.profile));
|
|
5472
|
+
if (existing) {
|
|
5473
|
+
return existing;
|
|
5543
5474
|
}
|
|
5544
|
-
|
|
5475
|
+
if (hasManagementCredentials(context.profile)) {
|
|
5476
|
+
return provisionLakehouseCredential(context);
|
|
5477
|
+
}
|
|
5478
|
+
return getLakehouseAuthHeader(context.profile);
|
|
5545
5479
|
}
|
|
5546
5480
|
async function toHttpSendOptions(request, context) {
|
|
5547
5481
|
return {
|
|
@@ -5558,19 +5492,18 @@ async function toHttpSendOptions(request, context) {
|
|
|
5558
5492
|
authPlane: request.plane
|
|
5559
5493
|
};
|
|
5560
5494
|
}
|
|
5561
|
-
function isRecoverableLakehouseAuthFailure(request, error) {
|
|
5562
|
-
return error instanceof HttpError && error.status === 401 && request.plane === "lakehouse" && !(request.body instanceof ReadableStream) && canRecoverLakehouseAuth();
|
|
5495
|
+
function isRecoverableLakehouseAuthFailure(request, error, profileName) {
|
|
5496
|
+
return error instanceof HttpError && error.status === 401 && request.plane === "lakehouse" && !(request.body instanceof ReadableStream) && canRecoverLakehouseAuth(profileName);
|
|
5563
5497
|
}
|
|
5564
5498
|
async function sendWithAuthRecovery(request, context, send) {
|
|
5565
5499
|
const options = await toHttpSendOptions(request, context);
|
|
5566
5500
|
try {
|
|
5567
5501
|
return await send(options);
|
|
5568
5502
|
} catch (error) {
|
|
5569
|
-
if (!isRecoverableLakehouseAuthFailure(request, error)) {
|
|
5503
|
+
if (!isRecoverableLakehouseAuthFailure(request, error, context.profile)) {
|
|
5570
5504
|
throw error;
|
|
5571
5505
|
}
|
|
5572
5506
|
const authHeader = await provisionLakehouseCredential(context);
|
|
5573
|
-
context.auth.lakehouse = authHeader;
|
|
5574
5507
|
return send({ ...options, authHeader });
|
|
5575
5508
|
}
|
|
5576
5509
|
}
|
|
@@ -5933,7 +5866,7 @@ function writeProfileUpdate(name, update) {
|
|
|
5933
5866
|
for (const profileField of Object.keys(PROFILE_UPDATE_CONFIG_KEYS)) {
|
|
5934
5867
|
const value = update[profileField];
|
|
5935
5868
|
if (value !== undefined) {
|
|
5936
|
-
|
|
5869
|
+
configSet(PROFILE_UPDATE_CONFIG_KEYS[profileField], value, name);
|
|
5937
5870
|
}
|
|
5938
5871
|
}
|
|
5939
5872
|
}
|
|
@@ -5943,6 +5876,10 @@ function profileAuth(name) {
|
|
|
5943
5876
|
lakehouse: secretExists("lakehouse/basic-token", name) ? "basic_token" : secretExists("lakehouse/password", name) ? "username_password" : "none"
|
|
5944
5877
|
};
|
|
5945
5878
|
}
|
|
5879
|
+
function profileHasAnyAuthConfigured(name) {
|
|
5880
|
+
const auth = profileAuth(name);
|
|
5881
|
+
return auth.management !== "none" || auth.lakehouse !== "none";
|
|
5882
|
+
}
|
|
5946
5883
|
function readProfileSnapshot(name) {
|
|
5947
5884
|
return {
|
|
5948
5885
|
config: readProfileConfigRecord(name),
|
|
@@ -6049,8 +5986,8 @@ function createEmptyProfile(name) {
|
|
|
6049
5986
|
}
|
|
6050
5987
|
ensureProfileExists(name);
|
|
6051
5988
|
const createdAt = nowIso();
|
|
6052
|
-
|
|
6053
|
-
|
|
5989
|
+
configSet("created_at", createdAt, name);
|
|
5990
|
+
configSet("updated_at", createdAt, name);
|
|
6054
5991
|
return inspectProfile(name);
|
|
6055
5992
|
}
|
|
6056
5993
|
function updateProfile(name, update) {
|
|
@@ -6060,7 +5997,7 @@ function updateProfile(name, update) {
|
|
|
6060
5997
|
throw new ConfigurationError(`Profile not found: ${name}`);
|
|
6061
5998
|
}
|
|
6062
5999
|
writeProfileUpdate(name, update);
|
|
6063
|
-
|
|
6000
|
+
configSet("updated_at", nowIso(), name);
|
|
6064
6001
|
return inspectProfile(name);
|
|
6065
6002
|
}
|
|
6066
6003
|
function renameProfile(source, target) {
|
|
@@ -6108,11 +6045,11 @@ function deleteProfile(name) {
|
|
|
6108
6045
|
function hasEnvManagementCredentials() {
|
|
6109
6046
|
return Boolean(process.env.ALTERTABLE_API_KEY);
|
|
6110
6047
|
}
|
|
6111
|
-
function hasStoredManagementCredentials() {
|
|
6112
|
-
return secretExists("api-key");
|
|
6048
|
+
function hasStoredManagementCredentials(profileName) {
|
|
6049
|
+
return secretExists("api-key", profileName);
|
|
6113
6050
|
}
|
|
6114
|
-
function hasOAuthLogin() {
|
|
6115
|
-
return secretExists("oauth/access-token");
|
|
6051
|
+
function hasOAuthLogin(profileName) {
|
|
6052
|
+
return secretExists("oauth/access-token", profileName);
|
|
6116
6053
|
}
|
|
6117
6054
|
function hasEnvLakehouseCredentials() {
|
|
6118
6055
|
if (process.env.ALTERTABLE_BASIC_AUTH_TOKEN) {
|
|
@@ -6120,61 +6057,72 @@ function hasEnvLakehouseCredentials() {
|
|
|
6120
6057
|
}
|
|
6121
6058
|
return Boolean(process.env.ALTERTABLE_LAKEHOUSE_USERNAME && process.env.ALTERTABLE_LAKEHOUSE_PASSWORD);
|
|
6122
6059
|
}
|
|
6123
|
-
function hasStoredLakehouseCredentials() {
|
|
6124
|
-
return secretExists("lakehouse/basic-token") || secretExists("lakehouse/password");
|
|
6060
|
+
function hasStoredLakehouseCredentials(profileName) {
|
|
6061
|
+
return secretExists("lakehouse/basic-token", profileName) || secretExists("lakehouse/password", profileName);
|
|
6062
|
+
}
|
|
6063
|
+
function hasCredentialsThroughEnv() {
|
|
6064
|
+
return hasEnvManagementCredentials() || hasEnvLakehouseCredentials();
|
|
6065
|
+
}
|
|
6066
|
+
function resolveActiveProfileName() {
|
|
6067
|
+
return hasCredentialsThroughEnv() ? FROM_ENV_PSEUDOPROFILE_NAME : resolveWorkingProfile(getCliContext().profile);
|
|
6125
6068
|
}
|
|
6126
|
-
function
|
|
6069
|
+
function assertProfileHasNoEnvCredentials(action) {
|
|
6070
|
+
if (resolveActiveProfileName() === FROM_ENV_PSEUDOPROFILE_NAME) {
|
|
6071
|
+
throw new ConfigurationError(`${action} is disabled while credentials come from the environment. Unset ALTERTABLE_API_KEY / ALTERTABLE_BASIC_AUTH_TOKEN / ALTERTABLE_LAKEHOUSE_USERNAME / ALTERTABLE_LAKEHOUSE_PASSWORD to manage stored profiles.`);
|
|
6072
|
+
}
|
|
6073
|
+
}
|
|
6074
|
+
function configureCredentialStatus(profileName) {
|
|
6127
6075
|
return {
|
|
6128
|
-
hasManagement: hasStoredManagementCredentials() || hasEnvManagementCredentials() || hasOAuthLogin(),
|
|
6129
|
-
hasLakehouse: hasStoredLakehouseCredentials() || hasEnvLakehouseCredentials()
|
|
6076
|
+
hasManagement: hasStoredManagementCredentials(profileName) || hasEnvManagementCredentials() || hasOAuthLogin(profileName),
|
|
6077
|
+
hasLakehouse: hasStoredLakehouseCredentials(profileName) || hasEnvLakehouseCredentials()
|
|
6130
6078
|
};
|
|
6131
6079
|
}
|
|
6132
|
-
function buildManagementCredential() {
|
|
6080
|
+
function buildManagementCredential(profileName) {
|
|
6133
6081
|
if (hasEnvManagementCredentials()) {
|
|
6134
6082
|
return {
|
|
6135
6083
|
configured: true,
|
|
6136
6084
|
mechanism: "management_api_key",
|
|
6137
6085
|
source: "environment",
|
|
6138
|
-
environment: process.env.ALTERTABLE_ENV ?? configGet("api_key_env") ?? undefined
|
|
6086
|
+
environment: process.env.ALTERTABLE_ENV ?? configGet("api_key_env", profileName) ?? undefined
|
|
6139
6087
|
};
|
|
6140
6088
|
}
|
|
6141
|
-
if (hasOAuthLogin()) {
|
|
6089
|
+
if (hasOAuthLogin(profileName)) {
|
|
6142
6090
|
return {
|
|
6143
6091
|
configured: true,
|
|
6144
6092
|
mechanism: "management_oauth",
|
|
6145
6093
|
source: "stored",
|
|
6146
|
-
environment: configGet("api_key_env") || undefined,
|
|
6094
|
+
environment: configGet("api_key_env", profileName) || undefined,
|
|
6147
6095
|
oauth: "set",
|
|
6148
|
-
expires: configGet("oauth_expiry") || undefined
|
|
6096
|
+
expires: configGet("oauth_expiry", profileName) || undefined
|
|
6149
6097
|
};
|
|
6150
6098
|
}
|
|
6151
|
-
if (hasStoredManagementCredentials()) {
|
|
6099
|
+
if (hasStoredManagementCredentials(profileName)) {
|
|
6152
6100
|
return {
|
|
6153
6101
|
configured: true,
|
|
6154
6102
|
mechanism: "management_api_key",
|
|
6155
6103
|
source: "stored",
|
|
6156
|
-
environment: configGet("api_key_env") || undefined,
|
|
6104
|
+
environment: configGet("api_key_env", profileName) || undefined,
|
|
6157
6105
|
api_key: "set"
|
|
6158
6106
|
};
|
|
6159
6107
|
}
|
|
6160
6108
|
return { configured: false };
|
|
6161
6109
|
}
|
|
6162
|
-
function buildLakehouseCredential() {
|
|
6163
|
-
if (hasStoredLakehouseCredentials()) {
|
|
6164
|
-
if (secretExists("lakehouse/basic-token")) {
|
|
6110
|
+
function buildLakehouseCredential(profileName) {
|
|
6111
|
+
if (hasStoredLakehouseCredentials(profileName)) {
|
|
6112
|
+
if (secretExists("lakehouse/basic-token", profileName)) {
|
|
6165
6113
|
return {
|
|
6166
6114
|
configured: true,
|
|
6167
6115
|
mechanism: "lakehouse_basic_token",
|
|
6168
6116
|
source: "stored",
|
|
6169
6117
|
basic_token: "set",
|
|
6170
|
-
expires: configGet("lakehouse_credential_expiry") || undefined
|
|
6118
|
+
expires: configGet("lakehouse_credential_expiry", profileName) || undefined
|
|
6171
6119
|
};
|
|
6172
6120
|
}
|
|
6173
6121
|
return {
|
|
6174
6122
|
configured: true,
|
|
6175
6123
|
mechanism: "lakehouse_username_password",
|
|
6176
6124
|
source: "stored",
|
|
6177
|
-
user: configGet("user") || undefined,
|
|
6125
|
+
user: configGet("user", profileName) || undefined,
|
|
6178
6126
|
password: "set"
|
|
6179
6127
|
};
|
|
6180
6128
|
}
|
|
@@ -6196,54 +6144,52 @@ function buildLakehouseCredential() {
|
|
|
6196
6144
|
}
|
|
6197
6145
|
return { configured: false };
|
|
6198
6146
|
}
|
|
6199
|
-
function buildConfigureShowOverrides() {
|
|
6147
|
+
function buildConfigureShowOverrides(profileName) {
|
|
6200
6148
|
const overrides = {};
|
|
6201
|
-
const storedApiKeyEnv = configGet("api_key_env");
|
|
6149
|
+
const storedApiKeyEnv = configGet("api_key_env", profileName);
|
|
6202
6150
|
const envOverride = process.env.ALTERTABLE_ENV;
|
|
6203
6151
|
if (envOverride && envOverride !== storedApiKeyEnv) {
|
|
6204
6152
|
overrides.environment = envOverride;
|
|
6205
6153
|
overrides.stored_environment = storedApiKeyEnv || null;
|
|
6206
6154
|
}
|
|
6207
|
-
if (process.env.ALTERTABLE_API_KEY && hasStoredManagementCredentials()) {
|
|
6155
|
+
if (process.env.ALTERTABLE_API_KEY && hasStoredManagementCredentials(profileName)) {
|
|
6208
6156
|
overrides.api_key = true;
|
|
6209
6157
|
}
|
|
6210
6158
|
return overrides;
|
|
6211
6159
|
}
|
|
6212
|
-
function buildConfigureShowData(
|
|
6213
|
-
const activeProfile = getActiveProfileName();
|
|
6214
|
-
const displayProfile = profileOverride ?? getCliContext().profile ?? activeProfile;
|
|
6160
|
+
function buildConfigureShowData(profileName) {
|
|
6215
6161
|
return {
|
|
6216
|
-
profile:
|
|
6162
|
+
profile: profileName,
|
|
6217
6163
|
config_dir: configDir(),
|
|
6218
|
-
config_file: profileConfigFile(
|
|
6164
|
+
config_file: profileConfigFile(profileName),
|
|
6219
6165
|
secret_store: secretStoreDisplay(),
|
|
6220
6166
|
organization: {
|
|
6221
|
-
slug: configGet("organization_slug") || undefined,
|
|
6222
|
-
name: configGet("organization_name") || undefined
|
|
6167
|
+
slug: configGet("organization_slug", profileName) || undefined,
|
|
6168
|
+
name: configGet("organization_name", profileName) || undefined
|
|
6223
6169
|
},
|
|
6224
|
-
data_plane: resolveApiBase(),
|
|
6225
|
-
control_plane: resolveManagementApiBase(),
|
|
6170
|
+
data_plane: resolveApiBase(profileName),
|
|
6171
|
+
control_plane: resolveManagementApiBase(profileName),
|
|
6226
6172
|
credentials: {
|
|
6227
|
-
management: buildManagementCredential(),
|
|
6228
|
-
lakehouse: buildLakehouseCredential()
|
|
6173
|
+
management: buildManagementCredential(profileName),
|
|
6174
|
+
lakehouse: buildLakehouseCredential(profileName)
|
|
6229
6175
|
},
|
|
6230
|
-
overrides: buildConfigureShowOverrides()
|
|
6176
|
+
overrides: buildConfigureShowOverrides(profileName)
|
|
6231
6177
|
};
|
|
6232
6178
|
}
|
|
6233
|
-
function managementPlaneStatusDetail() {
|
|
6179
|
+
function managementPlaneStatusDetail(profileName) {
|
|
6234
6180
|
if (hasEnvManagementCredentials()) {
|
|
6235
6181
|
return "via ALTERTABLE_API_KEY";
|
|
6236
6182
|
}
|
|
6237
|
-
if (hasOAuthLogin()) {
|
|
6238
|
-
const env = configGet("api_key_env");
|
|
6183
|
+
if (hasOAuthLogin(profileName)) {
|
|
6184
|
+
const env = configGet("api_key_env", profileName);
|
|
6239
6185
|
return env ? `OAuth login (${env})` : "OAuth login";
|
|
6240
6186
|
}
|
|
6241
|
-
if (!hasStoredManagementCredentials()) {
|
|
6187
|
+
if (!hasStoredManagementCredentials(profileName)) {
|
|
6242
6188
|
return null;
|
|
6243
6189
|
}
|
|
6244
|
-
return configGet("api_key_env") || "unknown";
|
|
6190
|
+
return configGet("api_key_env", profileName) || "unknown";
|
|
6245
6191
|
}
|
|
6246
|
-
function lakehousePlaneStatusDetail() {
|
|
6192
|
+
function lakehousePlaneStatusDetail(profileName) {
|
|
6247
6193
|
if (process.env.ALTERTABLE_BASIC_AUTH_TOKEN) {
|
|
6248
6194
|
return "via ALTERTABLE_BASIC_AUTH_TOKEN";
|
|
6249
6195
|
}
|
|
@@ -6251,74 +6197,30 @@ function lakehousePlaneStatusDetail() {
|
|
|
6251
6197
|
if (envUser && process.env.ALTERTABLE_LAKEHOUSE_PASSWORD) {
|
|
6252
6198
|
return envUser;
|
|
6253
6199
|
}
|
|
6254
|
-
if (!hasStoredLakehouseCredentials()) {
|
|
6200
|
+
if (!hasStoredLakehouseCredentials(profileName)) {
|
|
6255
6201
|
return null;
|
|
6256
|
-
}
|
|
6257
|
-
if (secretExists("lakehouse/basic-token")) {
|
|
6258
|
-
return "basic token";
|
|
6259
|
-
}
|
|
6260
|
-
return configGet("user") || "unknown";
|
|
6261
|
-
}
|
|
6262
|
-
function withProfileContextSync(profileName, run) {
|
|
6263
|
-
if (!profileName) {
|
|
6264
|
-
return run();
|
|
6265
|
-
}
|
|
6266
|
-
ensureProfileExists(profileName);
|
|
6267
|
-
const previous = getCliContext();
|
|
6268
|
-
setCliContext({ ...previous, profile: profileName });
|
|
6269
|
-
try {
|
|
6270
|
-
return run();
|
|
6271
|
-
} finally {
|
|
6272
|
-
setCliContext(previous);
|
|
6273
|
-
}
|
|
6274
|
-
}
|
|
6275
|
-
function resolveEnvironment(showData) {
|
|
6276
|
-
const envOverride = process.env.ALTERTABLE_ENV;
|
|
6277
|
-
if (envOverride && envOverride.length > 0) {
|
|
6278
|
-
return envOverride;
|
|
6279
|
-
}
|
|
6280
|
-
const managementCredential = showData.credentials.management;
|
|
6281
|
-
return managementCredential.configured ? managementCredential.environment : undefined;
|
|
6282
|
-
}
|
|
6283
|
-
function buildActiveContext(profileOverride) {
|
|
6284
|
-
const profile = profileOverride ?? getCliContext().profile;
|
|
6285
|
-
return withProfileContextSync(profile, () => {
|
|
6286
|
-
const showData = buildConfigureShowData(profileOverride);
|
|
6287
|
-
const credentialStatus = configureCredentialStatus();
|
|
6288
|
-
return {
|
|
6289
|
-
profile: showData.profile,
|
|
6290
|
-
environment: resolveEnvironment(showData),
|
|
6291
|
-
data_plane: showData.data_plane,
|
|
6292
|
-
control_plane: showData.control_plane,
|
|
6293
|
-
management: managementPlaneStatusDetail(),
|
|
6294
|
-
lakehouse: lakehousePlaneStatusDetail(),
|
|
6295
|
-
credentialStatus,
|
|
6296
|
-
credentials: showData.credentials,
|
|
6297
|
-
overrides: showData.overrides
|
|
6298
|
-
};
|
|
6299
|
-
});
|
|
6300
|
-
}
|
|
6301
|
-
function withAuthenticatedIdentity(context, whoami) {
|
|
6302
|
-
return {
|
|
6303
|
-
...context,
|
|
6304
|
-
principal: whoami.principal,
|
|
6305
|
-
organization: whoami.organization
|
|
6306
|
-
};
|
|
6202
|
+
}
|
|
6203
|
+
if (secretExists("lakehouse/basic-token", profileName)) {
|
|
6204
|
+
return "basic token";
|
|
6205
|
+
}
|
|
6206
|
+
return configGet("user", profileName) || "unknown";
|
|
6307
6207
|
}
|
|
6308
6208
|
|
|
6309
6209
|
// src/lib/profile-configure-core.ts
|
|
6310
6210
|
var ARGV_SECRET_WARNING = "Warning: passing secrets on the command line is visible in process listings. Prefer --password-stdin / --api-key-stdin.";
|
|
6311
6211
|
var AUTO_PROFILE_NAME = "auto";
|
|
6312
|
-
function markCurrentProfileUpdated() {
|
|
6212
|
+
function markCurrentProfileUpdated(profileName) {
|
|
6313
6213
|
const timestamp = new Date().toISOString();
|
|
6314
|
-
if (!configGet("created_at")) {
|
|
6315
|
-
configSet("created_at", timestamp);
|
|
6214
|
+
if (!configGet("created_at", profileName)) {
|
|
6215
|
+
configSet("created_at", timestamp, profileName);
|
|
6316
6216
|
}
|
|
6317
|
-
configSet("updated_at", timestamp);
|
|
6217
|
+
configSet("updated_at", timestamp, profileName);
|
|
6218
|
+
}
|
|
6219
|
+
function clearProfileEndpoint(key, profileName) {
|
|
6220
|
+
kvUnset(profileConfigFile(profileName), key);
|
|
6318
6221
|
}
|
|
6319
|
-
function resolveConfigureProfile(options) {
|
|
6222
|
+
function resolveConfigureProfile(options, org) {
|
|
6320
6223
|
const explicitProfile = options.profile;
|
|
6321
|
-
const org = options.org ?? "";
|
|
6322
6224
|
const env = options.env ?? "";
|
|
6323
6225
|
if (explicitProfile && explicitProfile !== AUTO_PROFILE_NAME) {
|
|
6324
6226
|
return explicitProfile;
|
|
@@ -6329,36 +6231,27 @@ function resolveConfigureProfile(options) {
|
|
|
6329
6231
|
if (explicitProfile === AUTO_PROFILE_NAME) {
|
|
6330
6232
|
throw new CliError("--profile auto is only supported by interactive configure.");
|
|
6331
6233
|
}
|
|
6332
|
-
return;
|
|
6234
|
+
return resolveWorkingProfile(getCliContext().profile);
|
|
6333
6235
|
}
|
|
6334
6236
|
async function withConfigureProfileContext(profileName, run) {
|
|
6335
|
-
if (!profileName) {
|
|
6336
|
-
return await run();
|
|
6337
|
-
}
|
|
6338
6237
|
ensureProfileExists(profileName);
|
|
6339
|
-
|
|
6340
|
-
setCliContext({ ...previous, profile: profileName });
|
|
6341
|
-
try {
|
|
6342
|
-
return await run();
|
|
6343
|
-
} finally {
|
|
6344
|
-
setCliContext(previous);
|
|
6345
|
-
}
|
|
6238
|
+
return await run(profileName);
|
|
6346
6239
|
}
|
|
6347
6240
|
function configureClearLakehouseCredentials(profileName) {
|
|
6348
6241
|
secretDelete("lakehouse/password", profileName);
|
|
6349
6242
|
secretDelete("lakehouse/basic-token", profileName);
|
|
6350
|
-
|
|
6351
|
-
|
|
6243
|
+
configSet("user", "", profileName);
|
|
6244
|
+
configSet("lakehouse_credential_expiry", "", profileName);
|
|
6352
6245
|
}
|
|
6353
6246
|
function configureClearManagementCredentials(profileName) {
|
|
6354
6247
|
secretDelete("api-key", profileName);
|
|
6355
6248
|
secretDelete("oauth/access-token", profileName);
|
|
6356
6249
|
secretDelete("oauth/refresh-token", profileName);
|
|
6357
|
-
|
|
6358
|
-
|
|
6250
|
+
configSet("api_key_env", "", profileName);
|
|
6251
|
+
configSet("oauth_expiry", "", profileName);
|
|
6359
6252
|
}
|
|
6360
|
-
async function configureRunSet(options, sink = getOutputSink()) {
|
|
6361
|
-
return withConfigureProfileContext(resolveConfigureProfile(options), async () => {
|
|
6253
|
+
async function configureRunSet(options, sink = getOutputSink(), org = "") {
|
|
6254
|
+
return withConfigureProfileContext(resolveConfigureProfile(options, org), async (profileName) => {
|
|
6362
6255
|
let user = options.user ?? "";
|
|
6363
6256
|
let password = options.password ?? "";
|
|
6364
6257
|
let apiKey = options.apiKey ?? "";
|
|
@@ -6366,7 +6259,6 @@ async function configureRunSet(options, sink = getOutputSink()) {
|
|
|
6366
6259
|
const env = options.env ?? "";
|
|
6367
6260
|
const dataPlaneUrl = options.dataPlaneUrl ?? "";
|
|
6368
6261
|
const controlPlaneUrl = options.controlPlaneUrl ?? "";
|
|
6369
|
-
const org = options.org ?? "";
|
|
6370
6262
|
const allowInsecureHttp = options.allowInsecureHttp ?? false;
|
|
6371
6263
|
const passwordFromArgv = Boolean(options.password) && !options.passwordStdin && !options.interactive;
|
|
6372
6264
|
const apiKeyFromArgv = Boolean(options.apiKey) && !options.apiKeyStdin && !options.interactive;
|
|
@@ -6383,15 +6275,15 @@ async function configureRunSet(options, sink = getOutputSink()) {
|
|
|
6383
6275
|
if (options.apiKeyStdin) {
|
|
6384
6276
|
apiKey = (await Bun.stdin.text()).replace(/\n$/, "");
|
|
6385
6277
|
}
|
|
6386
|
-
const
|
|
6387
|
-
const
|
|
6278
|
+
const hasLakehouseCredentials = Boolean(user || password);
|
|
6279
|
+
const hasLakehouseBasicToken = Boolean(basicToken);
|
|
6388
6280
|
const hasApiKey = Boolean(apiKey);
|
|
6389
|
-
const lakehouseMechanismCount = Number(
|
|
6390
|
-
const hasAnyCredential =
|
|
6281
|
+
const lakehouseMechanismCount = Number(hasLakehouseCredentials) + Number(hasLakehouseBasicToken);
|
|
6282
|
+
const hasAnyCredential = hasLakehouseCredentials || hasLakehouseBasicToken || hasApiKey;
|
|
6391
6283
|
if (lakehouseMechanismCount > 1) {
|
|
6392
6284
|
throw new CliError("Choose a single lakehouse authentication mechanism: --user/--password or --basic-token.");
|
|
6393
6285
|
}
|
|
6394
|
-
if (hasApiKey && (
|
|
6286
|
+
if (hasApiKey && (hasLakehouseCredentials || hasLakehouseBasicToken)) {
|
|
6395
6287
|
throw new CliError("Choose a single authentication mechanism per configure invocation: lakehouse credentials or --api-key.");
|
|
6396
6288
|
}
|
|
6397
6289
|
if (controlPlaneUrl && !hasAnyCredential) {
|
|
@@ -6403,50 +6295,50 @@ async function configureRunSet(options, sink = getOutputSink()) {
|
|
|
6403
6295
|
if (!hasAnyCredential && !dataPlaneUrl) {
|
|
6404
6296
|
throw new CliError("Nothing to configure. Use --user/--password, --basic-token, or --api-key --env <name>.");
|
|
6405
6297
|
}
|
|
6406
|
-
if (
|
|
6298
|
+
if (hasLakehouseCredentials && (!user || !password)) {
|
|
6407
6299
|
throw new CliError("--user and --password must be provided together.");
|
|
6408
6300
|
}
|
|
6409
6301
|
if (hasApiKey && !env) {
|
|
6410
6302
|
throw new CliError("--api-key requires --env <name>.");
|
|
6411
6303
|
}
|
|
6412
6304
|
if (hasApiKey) {
|
|
6413
|
-
configureClearManagementCredentials();
|
|
6414
|
-
secretSet("api-key", apiKey,
|
|
6415
|
-
configSet("api_key_env", env);
|
|
6305
|
+
configureClearManagementCredentials(profileName);
|
|
6306
|
+
secretSet("api-key", apiKey, profileName, { fromArgv: apiKeyFromArgv });
|
|
6307
|
+
configSet("api_key_env", env, profileName);
|
|
6416
6308
|
if (org) {
|
|
6417
|
-
configSet("organization_slug", org);
|
|
6309
|
+
configSet("organization_slug", org, profileName);
|
|
6418
6310
|
}
|
|
6419
6311
|
}
|
|
6420
|
-
if (
|
|
6421
|
-
configureClearLakehouseCredentials();
|
|
6422
|
-
secretSet("lakehouse/basic-token", basicToken);
|
|
6423
|
-
} else if (
|
|
6424
|
-
configureClearLakehouseCredentials();
|
|
6425
|
-
configSet("user", user);
|
|
6426
|
-
secretSet("lakehouse/password", password,
|
|
6312
|
+
if (hasLakehouseBasicToken) {
|
|
6313
|
+
configureClearLakehouseCredentials(profileName);
|
|
6314
|
+
secretSet("lakehouse/basic-token", basicToken, profileName);
|
|
6315
|
+
} else if (hasLakehouseCredentials) {
|
|
6316
|
+
configureClearLakehouseCredentials(profileName);
|
|
6317
|
+
configSet("user", user, profileName);
|
|
6318
|
+
secretSet("lakehouse/password", password, profileName, { fromArgv: passwordFromArgv });
|
|
6427
6319
|
}
|
|
6428
6320
|
if (dataPlaneUrl) {
|
|
6429
6321
|
assertAllowedApiBase(dataPlaneUrl, { allowInsecureHttp });
|
|
6430
|
-
configSet("api_base", dataPlaneUrl);
|
|
6322
|
+
configSet("api_base", dataPlaneUrl, profileName);
|
|
6431
6323
|
} else if (hasAnyCredential) {
|
|
6432
|
-
|
|
6324
|
+
clearProfileEndpoint("api_base", profileName);
|
|
6433
6325
|
}
|
|
6434
6326
|
if (controlPlaneUrl) {
|
|
6435
6327
|
assertAllowedApiBase(controlPlaneUrl, { allowInsecureHttp });
|
|
6436
|
-
configSet("management_api_base", controlPlaneUrl);
|
|
6328
|
+
configSet("management_api_base", controlPlaneUrl, profileName);
|
|
6437
6329
|
} else if (hasAnyCredential) {
|
|
6438
|
-
|
|
6330
|
+
clearProfileEndpoint("management_api_base", profileName);
|
|
6439
6331
|
}
|
|
6440
6332
|
if (hasApiKey) {
|
|
6441
6333
|
sink.writeMetadata([terminalMetadata(`Saved management API key for environment ${env}.`)]);
|
|
6442
|
-
} else if (
|
|
6334
|
+
} else if (hasLakehouseBasicToken) {
|
|
6443
6335
|
sink.writeMetadata([terminalMetadata("Saved lakehouse Basic token.")]);
|
|
6444
|
-
} else if (
|
|
6336
|
+
} else if (hasLakehouseCredentials) {
|
|
6445
6337
|
sink.writeMetadata([terminalMetadata(`Saved lakehouse credentials for user ${user}.`)]);
|
|
6446
6338
|
} else if (dataPlaneUrl) {
|
|
6447
6339
|
sink.writeMetadata([terminalMetadata(`Saved data plane URL ${dataPlaneUrl}.`)]);
|
|
6448
6340
|
}
|
|
6449
|
-
markCurrentProfileUpdated();
|
|
6341
|
+
markCurrentProfileUpdated(profileName);
|
|
6450
6342
|
});
|
|
6451
6343
|
}
|
|
6452
6344
|
function configureRunClear(sink = getOutputSink()) {
|
|
@@ -6485,10 +6377,13 @@ function loginProfileName(whoami, environment, fallback) {
|
|
|
6485
6377
|
return organizationSlug ? deriveProfileName(organizationSlug, environment) : fallback;
|
|
6486
6378
|
}
|
|
6487
6379
|
function selectLoginProfile(whoami, environment, replaceCurrentProfile) {
|
|
6488
|
-
const currentProfile =
|
|
6380
|
+
const currentProfile = resolveWorkingProfile(getCliContext().profile);
|
|
6489
6381
|
if (replaceCurrentProfile) {
|
|
6490
6382
|
return { profileName: currentProfile, profileAction: "replaced" };
|
|
6491
6383
|
}
|
|
6384
|
+
if (!profileHasAnyAuthConfigured(currentProfile)) {
|
|
6385
|
+
return { profileName: currentProfile, profileAction: "unchanged" };
|
|
6386
|
+
}
|
|
6492
6387
|
const targetProfile = loginProfileName(whoami, environment, currentProfile);
|
|
6493
6388
|
if (targetProfile === currentProfile) {
|
|
6494
6389
|
return { profileName: targetProfile, profileAction: "unchanged" };
|
|
@@ -6544,19 +6439,37 @@ function applyControlPlaneOverride(args) {
|
|
|
6544
6439
|
assertAllowedApiBase(url, { allowInsecureHttp: Boolean(args["allow-insecure-http"]) });
|
|
6545
6440
|
process.env.ALTERTABLE_MANAGEMENT_API_BASE = url;
|
|
6546
6441
|
}
|
|
6547
|
-
async function fetchLoginWhoami(oauthResponse) {
|
|
6548
|
-
const
|
|
6549
|
-
|
|
6550
|
-
|
|
6442
|
+
async function fetchLoginWhoami(oauthResponse, managementApiBase) {
|
|
6443
|
+
const body = await httpSend({
|
|
6444
|
+
method: "GET",
|
|
6445
|
+
url: `${managementApiBase}${encodeManagementEndpoint("/whoami")}`,
|
|
6446
|
+
authHeader: `Authorization: Bearer ${oauthResponse.access_token}`,
|
|
6447
|
+
authPlane: "management"
|
|
6448
|
+
});
|
|
6449
|
+
return JSON.parse(body);
|
|
6450
|
+
}
|
|
6451
|
+
async function fetchCurrentProfileWhoami() {
|
|
6452
|
+
return JSON.parse(await managementRequest("GET", "/whoami"));
|
|
6453
|
+
}
|
|
6454
|
+
function sameWhoamiContext(a, b) {
|
|
6455
|
+
return a.principal?.type === b.principal?.type && a.principal?.slug === b.principal?.slug && a.principal?.email === b.principal?.email && a.organization?.slug === b.organization?.slug && a.environment_slug === b.environment_slug;
|
|
6551
6456
|
}
|
|
6552
6457
|
async function runLogin(args, sink) {
|
|
6458
|
+
assertProfileHasNoEnvCredentials("altertable login");
|
|
6553
6459
|
assertInteractiveLogin();
|
|
6554
6460
|
applyControlPlaneOverride(args);
|
|
6555
|
-
const
|
|
6556
|
-
const
|
|
6461
|
+
const currentProfile = resolveWorkingProfile(getCliContext().profile);
|
|
6462
|
+
const oauthBase = resolveOAuthBase(currentProfile);
|
|
6463
|
+
const managementApiBase = resolveManagementApiBase(currentProfile);
|
|
6464
|
+
const oauthResponse = await runLoginFlow(sink, oauthBase);
|
|
6465
|
+
const whoami = await fetchLoginWhoami(oauthResponse, managementApiBase);
|
|
6557
6466
|
const { environment, profileName, profileAction } = storeLoginProfileMetadata(whoami, args);
|
|
6558
|
-
storeOAuthTokens(oauthResponse);
|
|
6467
|
+
storeOAuthTokens(oauthResponse, profileName);
|
|
6559
6468
|
refreshCliRuntimeContext(getCliContext());
|
|
6469
|
+
const refreshedWhoami = await fetchCurrentProfileWhoami();
|
|
6470
|
+
if (!sameWhoamiContext(whoami, refreshedWhoami)) {
|
|
6471
|
+
throw new Error("Login failed: the identity before and after profile persistence do not match.");
|
|
6472
|
+
}
|
|
6560
6473
|
const identity = formatWhoamiPrincipalLine(whoami);
|
|
6561
6474
|
const profileMessages = {
|
|
6562
6475
|
created: `created profile "${profileName}"`,
|
|
@@ -6803,7 +6716,7 @@ async function verifyPlane(plane, context) {
|
|
|
6803
6716
|
async function configureVerify(planes) {
|
|
6804
6717
|
refreshCliRuntimeContext(getCliContext());
|
|
6805
6718
|
const result = {
|
|
6806
|
-
profile:
|
|
6719
|
+
profile: resolveWorkingProfile(getCliContext().profile),
|
|
6807
6720
|
configured: [...planes],
|
|
6808
6721
|
verified: { management: false, lakehouse: false },
|
|
6809
6722
|
errors: []
|
|
@@ -6822,9 +6735,9 @@ async function configureVerify(planes) {
|
|
|
6822
6735
|
}
|
|
6823
6736
|
return result;
|
|
6824
6737
|
}
|
|
6825
|
-
function formatConfigureVerifyRemediation(plane) {
|
|
6738
|
+
function formatConfigureVerifyRemediation(plane, profileName) {
|
|
6826
6739
|
if (plane === "management") {
|
|
6827
|
-
const env = configGet("api_key_env") || "<name>";
|
|
6740
|
+
const env = configGet("api_key_env", profileName) || "<name>";
|
|
6828
6741
|
return `Check your API key and environment. Run: altertable profile --configure --scope management or altertable profile --configure --api-key atm_xxx --env ${env}`;
|
|
6829
6742
|
}
|
|
6830
6743
|
return "Check your lakehouse username and password. Run: altertable profile --configure --scope lakehouse or altertable profile --configure --user <u> --password <p>";
|
|
@@ -6951,92 +6864,6 @@ function buildProfileDirenvView(profileName) {
|
|
|
6951
6864
|
comments: ["Generated by: altertable profile direnv"]
|
|
6952
6865
|
};
|
|
6953
6866
|
}
|
|
6954
|
-
function whoamiPrincipalValue(identity, configuration) {
|
|
6955
|
-
const principal = identity?.principal;
|
|
6956
|
-
if (principal?.type === "ServiceAccount") {
|
|
6957
|
-
return `${principal.name ?? ""} (${principal.slug ?? ""})`;
|
|
6958
|
-
}
|
|
6959
|
-
if (principal?.email) {
|
|
6960
|
-
return principal.name ? `${principal.name} <${principal.email}>` : principal.email;
|
|
6961
|
-
}
|
|
6962
|
-
if (principal?.name) {
|
|
6963
|
-
return principal.name;
|
|
6964
|
-
}
|
|
6965
|
-
return lakehouseUserValue(configuration) ?? terminalNotConfiguredStatus();
|
|
6966
|
-
}
|
|
6967
|
-
function whoamiOrganizationValue(identity, configuration) {
|
|
6968
|
-
const organization = identity?.organization;
|
|
6969
|
-
if (organization?.name && organization?.slug) {
|
|
6970
|
-
return `${organization.name} (${organization.slug})`;
|
|
6971
|
-
}
|
|
6972
|
-
if (organization?.name || organization?.slug) {
|
|
6973
|
-
return organization.name ?? organization.slug ?? "";
|
|
6974
|
-
}
|
|
6975
|
-
const configured = configuration.organization;
|
|
6976
|
-
if (configured.name && configured.slug) {
|
|
6977
|
-
return `${configured.name} (${configured.slug})`;
|
|
6978
|
-
}
|
|
6979
|
-
return configured.name ?? configured.slug ?? terminalNotConfiguredStatus();
|
|
6980
|
-
}
|
|
6981
|
-
function managementEnvironmentValue(configuration) {
|
|
6982
|
-
const credential = configuration.credentials.management;
|
|
6983
|
-
return credential.configured ? credential.environment : undefined;
|
|
6984
|
-
}
|
|
6985
|
-
function lakehouseUserValue(configuration) {
|
|
6986
|
-
const credential = configuration.credentials.lakehouse;
|
|
6987
|
-
return credential.configured && credential.mechanism === "lakehouse_username_password" ? credential.user : undefined;
|
|
6988
|
-
}
|
|
6989
|
-
function profileEnvironmentValue(configuration) {
|
|
6990
|
-
return managementEnvironmentValue(configuration) ?? process.env.ALTERTABLE_ENV ?? terminalNotConfiguredStatus();
|
|
6991
|
-
}
|
|
6992
|
-
function cliConfigRows(configuration) {
|
|
6993
|
-
return [
|
|
6994
|
-
{ label: "Config dir:", value: configuration.config_dir },
|
|
6995
|
-
{ label: "Profile config file:", value: configuration.config_file },
|
|
6996
|
-
{ label: "Secret store:", value: configuration.secret_store }
|
|
6997
|
-
];
|
|
6998
|
-
}
|
|
6999
|
-
function principalLabel(identity) {
|
|
7000
|
-
return identity?.principal?.type === "ServiceAccount" ? "Service account:" : "User:";
|
|
7001
|
-
}
|
|
7002
|
-
function profileIdentityRows(result) {
|
|
7003
|
-
return [
|
|
7004
|
-
{ label: "Profile:", value: terminalStrong(result.configuration.profile) },
|
|
7005
|
-
{ label: "Environment:", value: profileEnvironmentValue(result.configuration) },
|
|
7006
|
-
{
|
|
7007
|
-
label: principalLabel(result.identity),
|
|
7008
|
-
value: whoamiPrincipalValue(result.identity, result.configuration)
|
|
7009
|
-
},
|
|
7010
|
-
{
|
|
7011
|
-
label: "Organization:",
|
|
7012
|
-
value: whoamiOrganizationValue(result.identity, result.configuration)
|
|
7013
|
-
}
|
|
7014
|
-
];
|
|
7015
|
-
}
|
|
7016
|
-
function profileDetailBlocks(configuration) {
|
|
7017
|
-
const blocks = [
|
|
7018
|
-
rows([
|
|
7019
|
-
{ label: "Data plane:", value: configuration.data_plane, linkifyUrls: true },
|
|
7020
|
-
{ label: "Control plane:", value: configuration.control_plane, linkifyUrls: true },
|
|
7021
|
-
...configureAuthenticationRows(configuration, undefined)
|
|
7022
|
-
])
|
|
7023
|
-
];
|
|
7024
|
-
const hints = configureSetupHintLines({
|
|
7025
|
-
hasManagement: configuration.credentials.management.configured,
|
|
7026
|
-
hasLakehouse: configuration.credentials.lakehouse.configured
|
|
7027
|
-
});
|
|
7028
|
-
if (hints.length > 0) {
|
|
7029
|
-
blocks.push(text(hints));
|
|
7030
|
-
}
|
|
7031
|
-
const overrides = configureOverrideRows(configuration.overrides);
|
|
7032
|
-
if (overrides.length > 0) {
|
|
7033
|
-
blocks.push(rows(overrides));
|
|
7034
|
-
}
|
|
7035
|
-
return blocks;
|
|
7036
|
-
}
|
|
7037
|
-
function buildProfileShowView(result, options = {}) {
|
|
7038
|
-
return document(...options.config ? [section(rows(cliConfigRows(result.configuration)))] : [], section(rows(profileIdentityRows(result))), section(...profileDetailBlocks(result.configuration)));
|
|
7039
|
-
}
|
|
7040
6867
|
function verificationPlaneLabel(plane) {
|
|
7041
6868
|
return plane === "management" ? "Management:" : "Lakehouse:";
|
|
7042
6869
|
}
|
|
@@ -7060,34 +6887,12 @@ function verificationRows(result) {
|
|
|
7060
6887
|
}
|
|
7061
6888
|
function buildProfileStatusView(result) {
|
|
7062
6889
|
const errors = result.verification.errors.map((error) => ` ${error.plane}: ${error.message}
|
|
7063
|
-
${formatConfigureVerifyRemediation(error.plane)}`);
|
|
7064
|
-
return document(...
|
|
7065
|
-
}
|
|
7066
|
-
function profileShowToJson(result) {
|
|
7067
|
-
const environment = managementEnvironmentValue(result.configuration) ?? process.env.ALTERTABLE_ENV ?? null;
|
|
7068
|
-
return {
|
|
7069
|
-
cli_config: {
|
|
7070
|
-
config_dir: result.configuration.config_dir,
|
|
7071
|
-
config_file: result.configuration.config_file,
|
|
7072
|
-
secret_store: result.configuration.secret_store
|
|
7073
|
-
},
|
|
7074
|
-
profile: {
|
|
7075
|
-
name: result.configuration.profile,
|
|
7076
|
-
environment,
|
|
7077
|
-
user: result.identity?.principal ?? null,
|
|
7078
|
-
organization: result.identity?.organization ?? null
|
|
7079
|
-
},
|
|
7080
|
-
details: {
|
|
7081
|
-
data_plane: result.configuration.data_plane,
|
|
7082
|
-
control_plane: result.configuration.control_plane,
|
|
7083
|
-
credentials: result.configuration.credentials,
|
|
7084
|
-
overrides: result.configuration.overrides
|
|
7085
|
-
}
|
|
7086
|
-
};
|
|
6890
|
+
${formatConfigureVerifyRemediation(error.plane, result.verification.profile)}`);
|
|
6891
|
+
return document(...buildProfileInspectView(result.profile).sections, section(rows(verificationRows(result.verification)), ...errors.length > 0 ? [text(errors)] : []));
|
|
7087
6892
|
}
|
|
7088
6893
|
function profileStatusToJson(result) {
|
|
7089
6894
|
return {
|
|
7090
|
-
|
|
6895
|
+
profile: result.profile,
|
|
7091
6896
|
verification: {
|
|
7092
6897
|
configured: result.verification.configured,
|
|
7093
6898
|
verified: result.verification.verified,
|
|
@@ -7174,22 +6979,6 @@ function lakehouseCredentialRows(credential) {
|
|
|
7174
6979
|
}
|
|
7175
6980
|
];
|
|
7176
6981
|
}
|
|
7177
|
-
function configureOverrideRows(overrides) {
|
|
7178
|
-
const rows2 = [];
|
|
7179
|
-
if (overrides.environment) {
|
|
7180
|
-
rows2.push({
|
|
7181
|
-
label: "Environment override:",
|
|
7182
|
-
value: `ALTERTABLE_ENV=${overrides.environment} (stored: ${overrides.stored_environment ?? "none"})`
|
|
7183
|
-
});
|
|
7184
|
-
}
|
|
7185
|
-
if (overrides.api_key) {
|
|
7186
|
-
rows2.push({
|
|
7187
|
-
label: "API key override:",
|
|
7188
|
-
value: "ALTERTABLE_API_KEY is set via environment"
|
|
7189
|
-
});
|
|
7190
|
-
}
|
|
7191
|
-
return rows2;
|
|
7192
|
-
}
|
|
7193
6982
|
function configureAuthenticationRows(data, planes) {
|
|
7194
6983
|
const includePlane = (plane) => planes === undefined || planes.includes(plane);
|
|
7195
6984
|
return [
|
|
@@ -7197,33 +6986,11 @@ function configureAuthenticationRows(data, planes) {
|
|
|
7197
6986
|
...includePlane("lakehouse") ? lakehouseCredentialRows(data.credentials.lakehouse) : []
|
|
7198
6987
|
];
|
|
7199
6988
|
}
|
|
7200
|
-
function configureSetupHintLines(status) {
|
|
7201
|
-
if (!status.hasManagement && !status.hasLakehouse) {
|
|
7202
|
-
return [
|
|
7203
|
-
terminalDescription(`${TERMINAL_INDENT}No credentials configured. Run: altertable profile --configure`),
|
|
7204
|
-
terminalHighlightCommands(`${TERMINAL_INDENT}Hint: run 'altertable profile --configure --scope management' (or 'altertable profile --configure --api-key atm_xxx --env <name>') for management commands, then 'altertable profile --configure --scope lakehouse' (or 'altertable profile --configure --user <u> --password <p>') for lakehouse queries.`)
|
|
7205
|
-
];
|
|
7206
|
-
}
|
|
7207
|
-
if (status.hasManagement && !status.hasLakehouse) {
|
|
7208
|
-
return [
|
|
7209
|
-
terminalHighlightCommands(`${TERMINAL_INDENT}Hint: run 'altertable profile --configure --scope lakehouse' or 'altertable profile --configure --user <u> --password <p>' for lakehouse query, upload, upsert, and append commands.`)
|
|
7210
|
-
];
|
|
7211
|
-
}
|
|
7212
|
-
if (status.hasLakehouse && !status.hasManagement) {
|
|
7213
|
-
return [
|
|
7214
|
-
terminalHighlightCommands(`${TERMINAL_INDENT}Hint: run 'altertable profile --configure --scope management' or 'altertable profile --configure --api-key atm_xxx --env <name>' for profile show, catalogs, and other management commands.`)
|
|
7215
|
-
];
|
|
7216
|
-
}
|
|
7217
|
-
return [];
|
|
7218
|
-
}
|
|
7219
6989
|
|
|
7220
6990
|
// src/features/profile/render.ts
|
|
7221
6991
|
function formatProfileInspect(profile) {
|
|
7222
6992
|
return renderDocumentText(buildProfileInspectView(profile));
|
|
7223
6993
|
}
|
|
7224
|
-
function formatProfileShow(result, options = {}) {
|
|
7225
|
-
return renderDocumentText(buildProfileShowView(result, options));
|
|
7226
|
-
}
|
|
7227
6994
|
function formatProfileStatus(result) {
|
|
7228
6995
|
return renderDocumentText(buildProfileStatusView(result));
|
|
7229
6996
|
}
|
|
@@ -7238,11 +7005,11 @@ function renderConfigureRows(rows2, options) {
|
|
|
7238
7005
|
nestedLabelWidth: TERMINAL_NESTED_LABEL_WIDTH
|
|
7239
7006
|
});
|
|
7240
7007
|
}
|
|
7241
|
-
function formatConfigureAuthenticationLines(options = {}) {
|
|
7242
|
-
return renderConfigureRows(configureAuthenticationRows(buildConfigureShowData(), options.planes), options);
|
|
7008
|
+
function formatConfigureAuthenticationLines(profileName, options = {}) {
|
|
7009
|
+
return renderConfigureRows(configureAuthenticationRows(buildConfigureShowData(profileName), options.planes), options);
|
|
7243
7010
|
}
|
|
7244
|
-
function formatConfigureSessionSummary(configuredPlanes) {
|
|
7245
|
-
return formatConfigureAuthenticationLines({ planes: configuredPlanes });
|
|
7011
|
+
function formatConfigureSessionSummary(profileName, configuredPlanes) {
|
|
7012
|
+
return formatConfigureAuthenticationLines(profileName, { planes: configuredPlanes });
|
|
7246
7013
|
}
|
|
7247
7014
|
|
|
7248
7015
|
// node_modules/@clack/core/dist/index.mjs
|
|
@@ -8824,49 +8591,55 @@ var SCOPE_SELECT_TITLE = "What to configure?";
|
|
|
8824
8591
|
var CONFIGURE_SCOPE_SELECT_OPTIONS = {
|
|
8825
8592
|
leadingNewline: false
|
|
8826
8593
|
};
|
|
8827
|
-
function formatScopeSelectLabel(plane) {
|
|
8594
|
+
function formatScopeSelectLabel(plane, profileName) {
|
|
8828
8595
|
const name = plane === "management" ? "Management" : "Lakehouse";
|
|
8829
|
-
const detail = plane === "management" ? managementPlaneStatusDetail() : lakehousePlaneStatusDetail();
|
|
8596
|
+
const detail = plane === "management" ? managementPlaneStatusDetail(profileName) : lakehousePlaneStatusDetail(profileName);
|
|
8830
8597
|
if (!detail) {
|
|
8831
8598
|
return `${terminalStrong(name)} ${terminalNotConfiguredStatus()}`;
|
|
8832
8599
|
}
|
|
8833
8600
|
return `${terminalStrong(name)} ${terminalSubtle(detail)}`;
|
|
8834
8601
|
}
|
|
8835
|
-
function toScopePromptOption(value) {
|
|
8602
|
+
function toScopePromptOption(value, profileName) {
|
|
8836
8603
|
if (value === "both") {
|
|
8837
8604
|
return { value, label: terminalStrong("Both") };
|
|
8838
8605
|
}
|
|
8839
|
-
return { value, label: formatScopeSelectLabel(value) };
|
|
8606
|
+
return { value, label: formatScopeSelectLabel(value, profileName) };
|
|
8840
8607
|
}
|
|
8841
|
-
function buildScopePromptModel(hasManagement, hasLakehouse) {
|
|
8608
|
+
function buildScopePromptModel(hasManagement, hasLakehouse, profileName) {
|
|
8842
8609
|
if (hasManagement && hasLakehouse) {
|
|
8843
8610
|
return {
|
|
8844
8611
|
defaultValue: "both",
|
|
8845
8612
|
options: [
|
|
8846
|
-
toScopePromptOption("management"),
|
|
8847
|
-
toScopePromptOption("lakehouse"),
|
|
8848
|
-
toScopePromptOption("both")
|
|
8613
|
+
toScopePromptOption("management", profileName),
|
|
8614
|
+
toScopePromptOption("lakehouse", profileName),
|
|
8615
|
+
toScopePromptOption("both", profileName)
|
|
8849
8616
|
]
|
|
8850
8617
|
};
|
|
8851
8618
|
}
|
|
8852
8619
|
if (hasManagement) {
|
|
8853
8620
|
return {
|
|
8854
8621
|
defaultValue: "lakehouse",
|
|
8855
|
-
options: [
|
|
8622
|
+
options: [
|
|
8623
|
+
toScopePromptOption("lakehouse", profileName),
|
|
8624
|
+
toScopePromptOption("management", profileName)
|
|
8625
|
+
]
|
|
8856
8626
|
};
|
|
8857
8627
|
}
|
|
8858
8628
|
if (hasLakehouse) {
|
|
8859
8629
|
return {
|
|
8860
8630
|
defaultValue: "management",
|
|
8861
|
-
options: [
|
|
8631
|
+
options: [
|
|
8632
|
+
toScopePromptOption("management", profileName),
|
|
8633
|
+
toScopePromptOption("lakehouse", profileName)
|
|
8634
|
+
]
|
|
8862
8635
|
};
|
|
8863
8636
|
}
|
|
8864
8637
|
return {
|
|
8865
8638
|
defaultValue: "both",
|
|
8866
8639
|
options: [
|
|
8867
|
-
toScopePromptOption("both"),
|
|
8868
|
-
toScopePromptOption("management"),
|
|
8869
|
-
toScopePromptOption("lakehouse")
|
|
8640
|
+
toScopePromptOption("both", profileName),
|
|
8641
|
+
toScopePromptOption("management", profileName),
|
|
8642
|
+
toScopePromptOption("lakehouse", profileName)
|
|
8870
8643
|
]
|
|
8871
8644
|
};
|
|
8872
8645
|
}
|
|
@@ -8876,12 +8649,12 @@ function parseScopeSelection(selection) {
|
|
|
8876
8649
|
}
|
|
8877
8650
|
throw new CliError(`Unexpected scope selection: ${selection}`);
|
|
8878
8651
|
}
|
|
8879
|
-
async function promptConfigureScope(prompts, requestedScope) {
|
|
8880
|
-
const { hasManagement, hasLakehouse } = configureCredentialStatus();
|
|
8652
|
+
async function promptConfigureScope(prompts, requestedScope, profileName) {
|
|
8653
|
+
const { hasManagement, hasLakehouse } = configureCredentialStatus(profileName);
|
|
8881
8654
|
if (requestedScope !== DEFAULT_SCOPE) {
|
|
8882
8655
|
return requestedScope;
|
|
8883
8656
|
}
|
|
8884
|
-
const scopePromptModel = buildScopePromptModel(hasManagement, hasLakehouse);
|
|
8657
|
+
const scopePromptModel = buildScopePromptModel(hasManagement, hasLakehouse, profileName);
|
|
8885
8658
|
const selectedScope = await prompts.readSelect(SCOPE_SELECT_TITLE, scopePromptModel.options, scopePromptModel.defaultValue, CONFIGURE_SCOPE_SELECT_OPTIONS);
|
|
8886
8659
|
return parseScopeSelection(selectedScope);
|
|
8887
8660
|
}
|
|
@@ -8905,27 +8678,27 @@ async function readRequiredPassword(prompts, prompt, requiredMessage) {
|
|
|
8905
8678
|
}
|
|
8906
8679
|
return password2;
|
|
8907
8680
|
}
|
|
8908
|
-
async function readSecretWithOptionalReuse(args) {
|
|
8681
|
+
async function readSecretWithOptionalReuse(args, profileName) {
|
|
8909
8682
|
const { prompts, secretKey, keepPrompt, passwordPrompt, requiredMessage } = args;
|
|
8910
|
-
if (secretExists(secretKey)) {
|
|
8683
|
+
if (secretExists(secretKey, profileName)) {
|
|
8911
8684
|
const keepExistingValue = await prompts.readConfirm(keepPrompt, true);
|
|
8912
8685
|
if (keepExistingValue) {
|
|
8913
|
-
return secretGet(secretKey);
|
|
8686
|
+
return secretGet(secretKey, profileName);
|
|
8914
8687
|
}
|
|
8915
8688
|
}
|
|
8916
8689
|
return await readRequiredPassword(prompts, passwordPrompt, requiredMessage);
|
|
8917
8690
|
}
|
|
8918
|
-
async function collectManagementCredentials(prompts, options) {
|
|
8691
|
+
async function collectManagementCredentials(prompts, options, profileName) {
|
|
8919
8692
|
prompts.writePrompt(`
|
|
8920
8693
|
${terminalAccent("Management")}
|
|
8921
8694
|
`);
|
|
8922
|
-
const currentEnv = configGet("api_key_env");
|
|
8695
|
+
const currentEnv = configGet("api_key_env", profileName);
|
|
8923
8696
|
const envDefault = currentEnv || "production";
|
|
8924
8697
|
const envPrompt = `Environment ${terminalDefaultHint(envDefault)}: `;
|
|
8925
8698
|
const env = await readLineWithDefault(prompts, envPrompt, envDefault);
|
|
8926
8699
|
let org = options.org ?? "";
|
|
8927
8700
|
if (!org && options.profile === AUTO_PROFILE_NAME2) {
|
|
8928
|
-
const currentOrg = configGet("organization_slug");
|
|
8701
|
+
const currentOrg = configGet("organization_slug", profileName);
|
|
8929
8702
|
const orgPrompt = currentOrg ? `Organization slug ${terminalDefaultHint(currentOrg)}: ` : `${terminalAccent("Organization slug")}: `;
|
|
8930
8703
|
org = currentOrg ? await readLineWithDefault(prompts, orgPrompt, currentOrg) : await prompts.readLine(orgPrompt);
|
|
8931
8704
|
if (!org) {
|
|
@@ -8938,12 +8711,11 @@ ${terminalAccent("Management")}
|
|
|
8938
8711
|
keepPrompt: "Keep existing API key?",
|
|
8939
8712
|
passwordPrompt: `${terminalAccent("API key")} ${HIDDEN_PROMPT_HINT}: `,
|
|
8940
8713
|
requiredMessage: "API key is required."
|
|
8941
|
-
});
|
|
8714
|
+
}, profileName);
|
|
8942
8715
|
const useDefaultControlPlane = await prompts.readConfirm(`Default control plane ${formatTerminalUrls(DEFAULT_CONTROL_PLANE_URL)}?`, true);
|
|
8943
8716
|
const configureOptions = {
|
|
8944
8717
|
apiKey,
|
|
8945
8718
|
env,
|
|
8946
|
-
org,
|
|
8947
8719
|
profile: options.profile,
|
|
8948
8720
|
allowInsecureHttp: options.allowInsecureHttp
|
|
8949
8721
|
};
|
|
@@ -8951,9 +8723,9 @@ ${terminalAccent("Management")}
|
|
|
8951
8723
|
const controlPlaneUrl = await prompts.readLine(`Control plane ${terminalDefaultHint(formatTerminalUrls(DEFAULT_CONTROL_PLANE_URL))}: `);
|
|
8952
8724
|
configureOptions.controlPlaneUrl = controlPlaneUrl || DEFAULT_CONTROL_PLANE_URL;
|
|
8953
8725
|
}
|
|
8954
|
-
return configureOptions;
|
|
8726
|
+
return { options: configureOptions, org };
|
|
8955
8727
|
}
|
|
8956
|
-
async function collectLakehouseCredentials(prompts, options) {
|
|
8728
|
+
async function collectLakehouseCredentials(prompts, options, profileName) {
|
|
8957
8729
|
const method = await prompts.readSelect(`${terminalAccent("Lakehouse")} ${terminalSubtle("auth")}`, [
|
|
8958
8730
|
{ value: "user-password", label: "Username and password" },
|
|
8959
8731
|
{ value: "basic-token", label: "Basic token" }
|
|
@@ -8967,7 +8739,7 @@ async function collectLakehouseCredentials(prompts, options) {
|
|
|
8967
8739
|
configureOptions.basicToken = basicToken;
|
|
8968
8740
|
return configureOptions;
|
|
8969
8741
|
}
|
|
8970
|
-
const currentUser = configGet("user");
|
|
8742
|
+
const currentUser = configGet("user", profileName);
|
|
8971
8743
|
const userPrompt = currentUser ? `Username ${terminalDefaultHint(currentUser)}: ` : `${terminalAccent("Username")}: `;
|
|
8972
8744
|
const user = currentUser ? await readLineWithDefault(prompts, userPrompt, currentUser) : await prompts.readLine(userPrompt);
|
|
8973
8745
|
if (!user) {
|
|
@@ -8979,7 +8751,7 @@ async function collectLakehouseCredentials(prompts, options) {
|
|
|
8979
8751
|
keepPrompt: "Keep existing password?",
|
|
8980
8752
|
passwordPrompt: `${terminalAccent("Password")} ${HIDDEN_PROMPT_HINT}: `,
|
|
8981
8753
|
requiredMessage: "Password is required."
|
|
8982
|
-
});
|
|
8754
|
+
}, profileName);
|
|
8983
8755
|
const useDefaultDataPlane = await prompts.readConfirm(`Default data plane ${formatTerminalUrls(DEFAULT_DATA_PLANE_URL)}?`, true);
|
|
8984
8756
|
configureOptions.user = user;
|
|
8985
8757
|
configureOptions.password = password2;
|
|
@@ -8993,8 +8765,8 @@ async function collectLakehouseCredentials(prompts, options) {
|
|
|
8993
8765
|
// src/lib/profile-configure.ts
|
|
8994
8766
|
var DEFAULT_SCOPE2 = "both";
|
|
8995
8767
|
var AUTO_PROFILE_NAME3 = "auto";
|
|
8996
|
-
async function saveCredentials(configureOptions, sink) {
|
|
8997
|
-
await configureRunSet({ ...configureOptions, interactive: true }, sink);
|
|
8768
|
+
async function saveCredentials(configureOptions, sink, org = "") {
|
|
8769
|
+
await configureRunSet({ ...configureOptions, interactive: true }, sink, org);
|
|
8998
8770
|
}
|
|
8999
8771
|
function formatNextCommandsLine(commands) {
|
|
9000
8772
|
if (commands.length === 0) {
|
|
@@ -9008,8 +8780,8 @@ function formatNextCommandsLine(commands) {
|
|
|
9008
8780
|
}
|
|
9009
8781
|
return renderDocumentText(document(section(text([terminalMuted("Next:"), ...commands.map((command) => ` ${command}`)]))));
|
|
9010
8782
|
}
|
|
9011
|
-
function writeOutro(sink, configuredPlanes) {
|
|
9012
|
-
const summaryLines = formatConfigureSessionSummary(configuredPlanes);
|
|
8783
|
+
function writeOutro(sink, configuredPlanes, profileName) {
|
|
8784
|
+
const summaryLines = formatConfigureSessionSummary(profileName, configuredPlanes);
|
|
9013
8785
|
const nextCommands = [];
|
|
9014
8786
|
if (configuredPlanes.includes("management")) {
|
|
9015
8787
|
nextCommands.push(terminalAccent("altertable profile show"));
|
|
@@ -9025,7 +8797,7 @@ function configureNonTtyErrorMessage() {
|
|
|
9025
8797
|
` + ` altertable profile --configure --api-key atm_xxx --env production
|
|
9026
8798
|
` + ` printf '%s' "$PASS" | altertable profile --configure --user alice --password-stdin`;
|
|
9027
8799
|
}
|
|
9028
|
-
async function runConfigureWizardInCurrentProfile(options
|
|
8800
|
+
async function runConfigureWizardInCurrentProfile(options, profileName) {
|
|
9029
8801
|
const sink = options.sink ?? getOutputSink();
|
|
9030
8802
|
const prompts = options.prompts ?? defaultConfigurePrompts;
|
|
9031
8803
|
if (isJsonOutput(getCliContext())) {
|
|
@@ -9035,33 +8807,29 @@ async function runConfigureWizardInCurrentProfile(options = {}) {
|
|
|
9035
8807
|
throw new ConfigurationError(configureNonTtyErrorMessage());
|
|
9036
8808
|
}
|
|
9037
8809
|
try {
|
|
9038
|
-
const scope = await promptConfigureScope(prompts, options.scope ?? DEFAULT_SCOPE2);
|
|
8810
|
+
const scope = await promptConfigureScope(prompts, options.scope ?? DEFAULT_SCOPE2, profileName);
|
|
9039
8811
|
const planes = planesForConfigureScope(scope);
|
|
9040
8812
|
const configuredPlanes = [];
|
|
9041
8813
|
let activeProfile = options.profile;
|
|
8814
|
+
let targetProfile = profileName;
|
|
9042
8815
|
if (activeProfile === AUTO_PROFILE_NAME3 && !planes.includes("management")) {
|
|
9043
8816
|
throw new CliError("--profile auto requires management configuration so the environment is known.");
|
|
9044
8817
|
}
|
|
9045
8818
|
if (planes.includes("management")) {
|
|
9046
|
-
const managementOptions = await collectManagementCredentials(prompts, {
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
if (activeProfile === AUTO_PROFILE_NAME3 && managementOptions.org && managementOptions.env) {
|
|
9052
|
-
activeProfile = deriveProfileName(managementOptions.org, managementOptions.env);
|
|
8819
|
+
const { options: managementOptions, org } = await collectManagementCredentials(prompts, { ...options, profile: activeProfile }, targetProfile);
|
|
8820
|
+
await saveCredentials(managementOptions, sink, org);
|
|
8821
|
+
if (activeProfile === AUTO_PROFILE_NAME3 && org && managementOptions.env) {
|
|
8822
|
+
activeProfile = deriveProfileName(org, managementOptions.env);
|
|
8823
|
+
targetProfile = activeProfile;
|
|
9053
8824
|
}
|
|
9054
8825
|
configuredPlanes.push("management");
|
|
9055
8826
|
}
|
|
9056
8827
|
if (planes.includes("lakehouse")) {
|
|
9057
|
-
const lakehouseOptions = await collectLakehouseCredentials(prompts, {
|
|
9058
|
-
...options,
|
|
9059
|
-
profile: activeProfile
|
|
9060
|
-
});
|
|
8828
|
+
const lakehouseOptions = await collectLakehouseCredentials(prompts, { ...options, profile: activeProfile }, targetProfile);
|
|
9061
8829
|
await saveCredentials(lakehouseOptions, sink);
|
|
9062
8830
|
configuredPlanes.push("lakehouse");
|
|
9063
8831
|
}
|
|
9064
|
-
writeOutro(sink, configuredPlanes);
|
|
8832
|
+
writeOutro(sink, configuredPlanes, targetProfile);
|
|
9065
8833
|
} catch (error) {
|
|
9066
8834
|
if (error instanceof ConfigurePromptCancelled) {
|
|
9067
8835
|
sink.writeMetadata([terminalMetadata("Configuration cancelled.")]);
|
|
@@ -9071,9 +8839,9 @@ async function runConfigureWizardInCurrentProfile(options = {}) {
|
|
|
9071
8839
|
}
|
|
9072
8840
|
}
|
|
9073
8841
|
async function runConfigureWizard(options = {}) {
|
|
9074
|
-
const contextProfile = options.profile
|
|
9075
|
-
await withConfigureProfileContext(contextProfile, async () => {
|
|
9076
|
-
await runConfigureWizardInCurrentProfile(options);
|
|
8842
|
+
const contextProfile = options.profile && options.profile !== AUTO_PROFILE_NAME3 ? options.profile : resolveWorkingProfile(getCliContext().profile);
|
|
8843
|
+
await withConfigureProfileContext(contextProfile, async (profileName) => {
|
|
8844
|
+
await runConfigureWizardInCurrentProfile(options, profileName);
|
|
9077
8845
|
});
|
|
9078
8846
|
}
|
|
9079
8847
|
function hasConfigureCredentialFlags(options) {
|
|
@@ -9131,8 +8899,11 @@ function resolveWizardScope(scope) {
|
|
|
9131
8899
|
}
|
|
9132
8900
|
throw new CliError(`Invalid --scope "${scope}". Use management or lakehouse.`);
|
|
9133
8901
|
}
|
|
9134
|
-
async function runProfileConfigure(args, sink) {
|
|
8902
|
+
async function runProfileConfigure(args, sink, profileName) {
|
|
9135
8903
|
const options = buildConfigureOptions(args);
|
|
8904
|
+
if (profileName) {
|
|
8905
|
+
options.profile = profileName;
|
|
8906
|
+
}
|
|
9136
8907
|
if (hasConfigureCredentialFlags(options)) {
|
|
9137
8908
|
if (args.scope) {
|
|
9138
8909
|
throw new CliError("--scope only applies to the interactive wizard, not flag-based configure.");
|
|
@@ -9143,82 +8914,11 @@ async function runProfileConfigure(args, sink) {
|
|
|
9143
8914
|
await runConfigureWizard({
|
|
9144
8915
|
scope: resolveWizardScope(args.scope),
|
|
9145
8916
|
allowInsecureHttp: options.allowInsecureHttp,
|
|
8917
|
+
profile: profileName,
|
|
9146
8918
|
sink
|
|
9147
8919
|
});
|
|
9148
8920
|
}
|
|
9149
8921
|
|
|
9150
|
-
// src/lib/catalog-rows.ts
|
|
9151
|
-
function buildCatalogRowsFromResponses(databasesResponse, connectionsResponse) {
|
|
9152
|
-
const databases = parseApiJson(databasesResponse);
|
|
9153
|
-
const connections = parseApiJson(connectionsResponse);
|
|
9154
|
-
const rows2 = [];
|
|
9155
|
-
for (const database of databases.databases ?? []) {
|
|
9156
|
-
rows2.push({
|
|
9157
|
-
type: "database",
|
|
9158
|
-
name: database.name ?? "",
|
|
9159
|
-
slug: database.slug ?? "",
|
|
9160
|
-
engine: "altertable",
|
|
9161
|
-
catalog: database.catalog ?? ""
|
|
9162
|
-
});
|
|
9163
|
-
}
|
|
9164
|
-
for (const connection of connections.connections ?? []) {
|
|
9165
|
-
rows2.push({
|
|
9166
|
-
type: "connection",
|
|
9167
|
-
name: connection.name ?? "",
|
|
9168
|
-
slug: connection.slug ?? "",
|
|
9169
|
-
engine: connection.engine ?? "",
|
|
9170
|
-
catalog: connection.catalog ?? ""
|
|
9171
|
-
});
|
|
9172
|
-
}
|
|
9173
|
-
return rows2;
|
|
9174
|
-
}
|
|
9175
|
-
|
|
9176
|
-
// src/lib/management-operations.ts
|
|
9177
|
-
var managementWhoamiOperation = defineHttpOperation({
|
|
9178
|
-
id: "management.whoami",
|
|
9179
|
-
request: () => ({
|
|
9180
|
-
plane: "management",
|
|
9181
|
-
method: "GET",
|
|
9182
|
-
endpoint: "/whoami"
|
|
9183
|
-
}),
|
|
9184
|
-
decode: (response, _context, activeContext) => withAuthenticatedIdentity(activeContext, parseApiJson(response))
|
|
9185
|
-
});
|
|
9186
|
-
var managementCatalogCreateOperation = defineHttpOperation({
|
|
9187
|
-
id: "management.catalogs.create",
|
|
9188
|
-
request: (input2) => ({
|
|
9189
|
-
plane: "management",
|
|
9190
|
-
method: "POST",
|
|
9191
|
-
endpoint: `/environments/${input2.env}/databases`,
|
|
9192
|
-
body: input2.body,
|
|
9193
|
-
contentType: "application/json"
|
|
9194
|
-
}),
|
|
9195
|
-
decode: (response, _context, input2) => ({
|
|
9196
|
-
response,
|
|
9197
|
-
env: input2.env,
|
|
9198
|
-
fallbackName: input2.name
|
|
9199
|
-
})
|
|
9200
|
-
});
|
|
9201
|
-
var managementCatalogDatabasesOperation = defineHttpOperation({
|
|
9202
|
-
id: "management.catalogs.databases.list",
|
|
9203
|
-
request: (env) => ({
|
|
9204
|
-
plane: "management",
|
|
9205
|
-
method: "GET",
|
|
9206
|
-
endpoint: `/environments/${env}/databases`
|
|
9207
|
-
})
|
|
9208
|
-
});
|
|
9209
|
-
var managementCatalogConnectionsOperation = defineHttpOperation({
|
|
9210
|
-
id: "management.catalogs.connections.list",
|
|
9211
|
-
request: (env) => ({
|
|
9212
|
-
plane: "management",
|
|
9213
|
-
method: "GET",
|
|
9214
|
-
endpoint: `/environments/${env}/connections`
|
|
9215
|
-
})
|
|
9216
|
-
});
|
|
9217
|
-
function buildManagementCatalogRows(responses) {
|
|
9218
|
-
const [databasesResponse, connectionsResponse] = responses;
|
|
9219
|
-
return buildCatalogRowsFromResponses(String(databasesResponse), String(connectionsResponse));
|
|
9220
|
-
}
|
|
9221
|
-
|
|
9222
8922
|
// src/lib/command-delegation.ts
|
|
9223
8923
|
function valueFlagsFor(args) {
|
|
9224
8924
|
const flags = new Set;
|
|
@@ -9331,12 +9031,12 @@ function existingProfileName(name) {
|
|
|
9331
9031
|
function profileNameArgOrActive(args) {
|
|
9332
9032
|
return args.name ? requireProfileName(args.name) : getActiveProfileName();
|
|
9333
9033
|
}
|
|
9334
|
-
function configuredVerificationPlanes(
|
|
9034
|
+
function configuredVerificationPlanes(profile) {
|
|
9335
9035
|
const planes = [];
|
|
9336
|
-
if (
|
|
9036
|
+
if (profile.auth.management !== "none") {
|
|
9337
9037
|
planes.push("management");
|
|
9338
9038
|
}
|
|
9339
|
-
if (
|
|
9039
|
+
if (profile.auth.lakehouse !== "none") {
|
|
9340
9040
|
planes.push("lakehouse");
|
|
9341
9041
|
}
|
|
9342
9042
|
return planes;
|
|
@@ -9388,7 +9088,7 @@ var profileCreateCommand = defineLocalCommand({
|
|
|
9388
9088
|
},
|
|
9389
9089
|
async local(input2, context) {
|
|
9390
9090
|
createEmptyProfile(input2.name);
|
|
9391
|
-
await
|
|
9091
|
+
await runProfileConfigure(input2.configure, context.sink, input2.name);
|
|
9392
9092
|
setActiveProfile(input2.name);
|
|
9393
9093
|
return inspectProfile(input2.name);
|
|
9394
9094
|
},
|
|
@@ -9407,57 +9107,28 @@ function profileShowTargetName(args) {
|
|
|
9407
9107
|
}
|
|
9408
9108
|
return getCliContext().profile ?? getActiveProfileName();
|
|
9409
9109
|
}
|
|
9410
|
-
async function fetchProfileIdentity(context) {
|
|
9411
|
-
try {
|
|
9412
|
-
const enriched = await runOperationPlan(managementWhoamiOperation.plan(buildActiveContext(), context), context);
|
|
9413
|
-
if (enriched.principal === undefined && enriched.organization === undefined) {
|
|
9414
|
-
return;
|
|
9415
|
-
}
|
|
9416
|
-
return { principal: enriched.principal ?? {}, organization: enriched.organization ?? {} };
|
|
9417
|
-
} catch {
|
|
9418
|
-
return;
|
|
9419
|
-
}
|
|
9420
|
-
}
|
|
9421
9110
|
var profileShowCommand = defineLocalCommand({
|
|
9422
9111
|
id: "profile.show",
|
|
9423
9112
|
localConfig: true,
|
|
9424
9113
|
output: "normalized",
|
|
9425
9114
|
meta: {
|
|
9426
9115
|
name: "show",
|
|
9427
|
-
description: "Show
|
|
9116
|
+
description: "Show a profile's stored identity, auth, and endpoints"
|
|
9428
9117
|
},
|
|
9429
9118
|
args: {
|
|
9430
|
-
name: { type: "string", description: "Profile name (default: active profile)" }
|
|
9431
|
-
config: {
|
|
9432
|
-
type: "boolean",
|
|
9433
|
-
description: "Include CLI config paths (config dir, profile config file, secret store)"
|
|
9434
|
-
}
|
|
9119
|
+
name: { type: "string", description: "Profile name (default: active profile)" }
|
|
9435
9120
|
},
|
|
9436
9121
|
parse({ args }) {
|
|
9437
|
-
return {
|
|
9438
|
-
profileName: existingProfileName(profileShowTargetName(args)),
|
|
9439
|
-
config: Boolean(args.config)
|
|
9440
|
-
};
|
|
9122
|
+
return { profileName: existingProfileName(profileShowTargetName(args)) };
|
|
9441
9123
|
},
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
try {
|
|
9445
|
-
const next = { ...previous, profile: input2.profileName };
|
|
9446
|
-
setCliContext(next);
|
|
9447
|
-
refreshCliRuntimeContext(next);
|
|
9448
|
-
const configuration = buildConfigureShowData();
|
|
9449
|
-
const identity = configureCredentialStatus().hasManagement ? await fetchProfileIdentity(context) : undefined;
|
|
9450
|
-
return { configuration, identity, config: input2.config };
|
|
9451
|
-
} finally {
|
|
9452
|
-
setCliContext(previous);
|
|
9453
|
-
refreshCliRuntimeContext(previous);
|
|
9454
|
-
}
|
|
9124
|
+
local(input2) {
|
|
9125
|
+
return inspectProfile(input2.profileName);
|
|
9455
9126
|
},
|
|
9456
9127
|
present(result) {
|
|
9457
9128
|
return {
|
|
9458
9129
|
kind: "normalized",
|
|
9459
|
-
data:
|
|
9460
|
-
humanText:
|
|
9130
|
+
data: { profile: result },
|
|
9131
|
+
humanText: formatProfileInspect(result)
|
|
9461
9132
|
};
|
|
9462
9133
|
}
|
|
9463
9134
|
});
|
|
@@ -9475,6 +9146,7 @@ function createProfileUseCommand(id, name, hidden = false) {
|
|
|
9475
9146
|
return requireProfileName(args.name);
|
|
9476
9147
|
},
|
|
9477
9148
|
local(profileName) {
|
|
9149
|
+
assertProfileHasNoEnvCredentials("Switching profiles");
|
|
9478
9150
|
setActiveProfile(profileName);
|
|
9479
9151
|
return profileName;
|
|
9480
9152
|
},
|
|
@@ -9501,6 +9173,7 @@ var profileSwitchCommand = defineLocalCommand({
|
|
|
9501
9173
|
return args.name ? requireProfileName(args.name) : undefined;
|
|
9502
9174
|
},
|
|
9503
9175
|
async local(profileName) {
|
|
9176
|
+
assertProfileHasNoEnvCredentials("Switching profiles");
|
|
9504
9177
|
if (!profileName) {
|
|
9505
9178
|
if (isJsonOutput(getCliContext()) || getCliContext().agent || process.stdin.isTTY !== true) {
|
|
9506
9179
|
throw new CliError("Interactive profile switch requires a TTY. Pass a profile name.");
|
|
@@ -9594,16 +9267,15 @@ var profileStatusCommand = defineLocalCommand({
|
|
|
9594
9267
|
parse({ args }) {
|
|
9595
9268
|
return existingProfileName(profileShowTargetName(args));
|
|
9596
9269
|
},
|
|
9597
|
-
async local(profileName
|
|
9270
|
+
async local(profileName) {
|
|
9598
9271
|
const previous = getCliContext();
|
|
9599
9272
|
try {
|
|
9600
9273
|
const next = { ...previous, profile: profileName };
|
|
9601
9274
|
setCliContext(next);
|
|
9602
9275
|
refreshCliRuntimeContext(next);
|
|
9603
|
-
const
|
|
9604
|
-
const
|
|
9605
|
-
|
|
9606
|
-
return { configuration, identity, verification };
|
|
9276
|
+
const profile = inspectProfile(profileName);
|
|
9277
|
+
const verification = await configureVerify(configuredVerificationPlanes(profile));
|
|
9278
|
+
return { profile, verification };
|
|
9607
9279
|
} finally {
|
|
9608
9280
|
setCliContext(previous);
|
|
9609
9281
|
refreshCliRuntimeContext(previous);
|
|
@@ -9745,6 +9417,74 @@ function buildCreateCatalogBody(options) {
|
|
|
9745
9417
|
return JSON.stringify({ name: options.name, engine: "altertable" });
|
|
9746
9418
|
}
|
|
9747
9419
|
|
|
9420
|
+
// src/lib/catalog-rows.ts
|
|
9421
|
+
function buildCatalogRowsFromResponses(databasesResponse, connectionsResponse) {
|
|
9422
|
+
const databases = parseApiJson(databasesResponse);
|
|
9423
|
+
const connections = parseApiJson(connectionsResponse);
|
|
9424
|
+
const rows2 = [];
|
|
9425
|
+
for (const database of databases.databases ?? []) {
|
|
9426
|
+
rows2.push({
|
|
9427
|
+
type: "database",
|
|
9428
|
+
name: database.name ?? "",
|
|
9429
|
+
slug: database.slug ?? "",
|
|
9430
|
+
engine: "altertable",
|
|
9431
|
+
catalog: database.catalog ?? ""
|
|
9432
|
+
});
|
|
9433
|
+
}
|
|
9434
|
+
for (const connection of connections.connections ?? []) {
|
|
9435
|
+
rows2.push({
|
|
9436
|
+
type: "connection",
|
|
9437
|
+
name: connection.name ?? "",
|
|
9438
|
+
slug: connection.slug ?? "",
|
|
9439
|
+
engine: connection.engine ?? "",
|
|
9440
|
+
catalog: connection.catalog ?? ""
|
|
9441
|
+
});
|
|
9442
|
+
}
|
|
9443
|
+
return rows2;
|
|
9444
|
+
}
|
|
9445
|
+
|
|
9446
|
+
// src/lib/management-operations.ts
|
|
9447
|
+
var managementCatalogCreateOperation = defineHttpOperation({
|
|
9448
|
+
id: "management.catalogs.create",
|
|
9449
|
+
request: (input2) => ({
|
|
9450
|
+
plane: "management",
|
|
9451
|
+
method: "POST",
|
|
9452
|
+
endpoint: `/environments/${input2.env}/databases`,
|
|
9453
|
+
body: input2.body,
|
|
9454
|
+
contentType: "application/json"
|
|
9455
|
+
}),
|
|
9456
|
+
decode: (response, _context, input2) => ({
|
|
9457
|
+
response,
|
|
9458
|
+
env: input2.env,
|
|
9459
|
+
fallbackName: input2.name
|
|
9460
|
+
})
|
|
9461
|
+
});
|
|
9462
|
+
var managementCatalogDatabasesOperation = defineHttpOperation({
|
|
9463
|
+
id: "management.catalogs.databases.list",
|
|
9464
|
+
request: (env) => ({
|
|
9465
|
+
plane: "management",
|
|
9466
|
+
method: "GET",
|
|
9467
|
+
endpoint: `/environments/${env}/databases`
|
|
9468
|
+
})
|
|
9469
|
+
});
|
|
9470
|
+
var managementCatalogConnectionsOperation = defineHttpOperation({
|
|
9471
|
+
id: "management.catalogs.connections.list",
|
|
9472
|
+
request: (env) => ({
|
|
9473
|
+
plane: "management",
|
|
9474
|
+
method: "GET",
|
|
9475
|
+
endpoint: `/environments/${env}/connections`
|
|
9476
|
+
})
|
|
9477
|
+
});
|
|
9478
|
+
function buildManagementCatalogRows(responses) {
|
|
9479
|
+
const [databasesResponse, connectionsResponse] = responses;
|
|
9480
|
+
return buildCatalogRowsFromResponses(String(databasesResponse), String(connectionsResponse));
|
|
9481
|
+
}
|
|
9482
|
+
async function fetchManagementCatalogRows(env, context) {
|
|
9483
|
+
const databasesResponse = await runOperationEffect(managementCatalogDatabasesOperation.effect(env, context), context);
|
|
9484
|
+
const connectionsResponse = await runOperationEffect(managementCatalogConnectionsOperation.effect(env, context), context);
|
|
9485
|
+
return buildManagementCatalogRows([databasesResponse, connectionsResponse]);
|
|
9486
|
+
}
|
|
9487
|
+
|
|
9748
9488
|
// src/commands/catalogs.ts
|
|
9749
9489
|
var catalogsCreateCommand = defineHttpCommand({
|
|
9750
9490
|
id: "catalogs.create",
|
|
@@ -9766,11 +9506,11 @@ var catalogsCreateCommand = defineHttpCommand({
|
|
|
9766
9506
|
},
|
|
9767
9507
|
name: { type: "string", description: "Catalog name", required: true }
|
|
9768
9508
|
},
|
|
9769
|
-
parse({ args }) {
|
|
9509
|
+
parse({ args, execution }) {
|
|
9770
9510
|
if (args.engine !== "altertable") {
|
|
9771
9511
|
throw new CliError(`Only the 'altertable' engine is supported (got '${String(args.engine)}').`);
|
|
9772
9512
|
}
|
|
9773
|
-
const env = requireManagementEnv();
|
|
9513
|
+
const env = requireManagementEnv(execution.profile);
|
|
9774
9514
|
const name = String(args.name);
|
|
9775
9515
|
return {
|
|
9776
9516
|
env,
|
|
@@ -9801,12 +9541,8 @@ var catalogsListCommand = defineOperationCommand({
|
|
|
9801
9541
|
examples: ["altertable catalogs list", "altertable --json catalogs list"]
|
|
9802
9542
|
},
|
|
9803
9543
|
run(_input, context) {
|
|
9804
|
-
const env = requireManagementEnv();
|
|
9805
|
-
return localPlan(
|
|
9806
|
-
const databasesResponse = await runOperationEffect(managementCatalogDatabasesOperation.effect(env, context), context);
|
|
9807
|
-
const connectionsResponse = await runOperationEffect(managementCatalogConnectionsOperation.effect(env, context), context);
|
|
9808
|
-
return buildManagementCatalogRows([databasesResponse, connectionsResponse]);
|
|
9809
|
-
});
|
|
9544
|
+
const env = requireManagementEnv(context.execution.profile);
|
|
9545
|
+
return localPlan(() => fetchManagementCatalogRows(env, context));
|
|
9810
9546
|
},
|
|
9811
9547
|
present(rows2) {
|
|
9812
9548
|
const summary = formatCatalogsSummary(rows2);
|
|
@@ -9870,15 +9606,36 @@ function escapeSql(value) {
|
|
|
9870
9606
|
function quoteIdentifier(value) {
|
|
9871
9607
|
return `"${value.replaceAll('"', '""')}"`;
|
|
9872
9608
|
}
|
|
9873
|
-
function
|
|
9609
|
+
function attachStatement(credentials, catalog) {
|
|
9874
9610
|
const connection = `user=${escapeSql(credentials.user)} password=${escapeSql(credentials.password)} catalog=${escapeSql(catalog)}`;
|
|
9875
|
-
return `
|
|
9876
|
-
LOAD altertable;
|
|
9877
|
-
ATTACH
|
|
9611
|
+
return `ATTACH
|
|
9878
9612
|
'${connection}'
|
|
9879
9613
|
AS ${quoteIdentifier(catalog)} (TYPE ALTERTABLE);`;
|
|
9880
9614
|
}
|
|
9881
|
-
|
|
9615
|
+
function buildDuckdbAttachSnippet(credentials, catalogs) {
|
|
9616
|
+
return [
|
|
9617
|
+
"INSTALL altertable FROM community;",
|
|
9618
|
+
"LOAD altertable;",
|
|
9619
|
+
...catalogs.map((catalog) => attachStatement(credentials, catalog))
|
|
9620
|
+
].join(`
|
|
9621
|
+
`);
|
|
9622
|
+
}
|
|
9623
|
+
function selectCatalogsToAttach(rows2, requested) {
|
|
9624
|
+
const available = [
|
|
9625
|
+
...new Set(rows2.map((row) => row.catalog).filter((catalog) => catalog.length > 0))
|
|
9626
|
+
];
|
|
9627
|
+
if (requested !== undefined) {
|
|
9628
|
+
if (!available.includes(requested)) {
|
|
9629
|
+
throw new ConfigurationError(`Catalog "${requested}" not found. Available catalogs: ${available.join(", ") || "none"}.`);
|
|
9630
|
+
}
|
|
9631
|
+
return [requested];
|
|
9632
|
+
}
|
|
9633
|
+
if (available.length === 0) {
|
|
9634
|
+
throw new ConfigurationError("No catalogs found in this environment.");
|
|
9635
|
+
}
|
|
9636
|
+
return available;
|
|
9637
|
+
}
|
|
9638
|
+
async function runDuckdb(input2, context) {
|
|
9882
9639
|
if (!Bun.which("duckdb")) {
|
|
9883
9640
|
throw new ConfigurationError("duckdb is not installed. Install it from https://duckdb.org/install/ and try again.");
|
|
9884
9641
|
}
|
|
@@ -9886,11 +9643,13 @@ async function runDuckdb(input2) {
|
|
|
9886
9643
|
if (!verify.verified.lakehouse) {
|
|
9887
9644
|
throw new ConfigurationError(LOGIN_PROMPT);
|
|
9888
9645
|
}
|
|
9889
|
-
const credentials = getLoginLakehouseCredentials();
|
|
9646
|
+
const credentials = getLoginLakehouseCredentials(context.execution.profile);
|
|
9890
9647
|
if (!credentials) {
|
|
9891
9648
|
throw new ConfigurationError(LOGIN_PROMPT);
|
|
9892
9649
|
}
|
|
9893
|
-
const
|
|
9650
|
+
const rows2 = await fetchManagementCatalogRows(requireManagementEnv(context.execution.profile), context);
|
|
9651
|
+
const catalogs = selectCatalogsToAttach(rows2, input2.catalog);
|
|
9652
|
+
const snippet = buildDuckdbAttachSnippet(credentials, catalogs);
|
|
9894
9653
|
const result = spawnSync3("duckdb", ["-cmd", snippet], { stdio: "inherit" });
|
|
9895
9654
|
if (result.error) {
|
|
9896
9655
|
throw new ConfigurationError(`Failed to launch duckdb: ${result.error.message}`);
|
|
@@ -9899,18 +9658,23 @@ async function runDuckdb(input2) {
|
|
|
9899
9658
|
var duckdbCommand = defineLocalCommand({
|
|
9900
9659
|
id: "duckdb",
|
|
9901
9660
|
output: "none",
|
|
9661
|
+
capabilities: ["management-http"],
|
|
9902
9662
|
meta: {
|
|
9903
9663
|
name: "duckdb",
|
|
9904
|
-
description: "Open a DuckDB shell attached to
|
|
9905
|
-
examples: ["altertable duckdb my_catalog"]
|
|
9664
|
+
description: "Open a DuckDB shell attached to lakehouse catalogs (all of them by default).",
|
|
9665
|
+
examples: ["altertable duckdb", "altertable duckdb my_catalog"]
|
|
9906
9666
|
},
|
|
9907
9667
|
args: {
|
|
9908
|
-
catalog: {
|
|
9668
|
+
catalog: {
|
|
9669
|
+
type: "positional",
|
|
9670
|
+
description: "Catalog to attach (defaults to all catalogs)",
|
|
9671
|
+
required: false
|
|
9672
|
+
}
|
|
9909
9673
|
},
|
|
9910
9674
|
parse({ args }) {
|
|
9911
|
-
return { catalog:
|
|
9675
|
+
return { catalog: optionalStringArg(args, "catalog") };
|
|
9912
9676
|
},
|
|
9913
|
-
local: (input2) => runDuckdb(input2)
|
|
9677
|
+
local: (input2, context) => runDuckdb(input2, context)
|
|
9914
9678
|
});
|
|
9915
9679
|
|
|
9916
9680
|
// src/commands/lakehouse-args.ts
|
|
@@ -13999,11 +13763,11 @@ function parseUpdateCheckInterval(value) {
|
|
|
13999
13763
|
return;
|
|
14000
13764
|
}
|
|
14001
13765
|
function getUpdateCheckInterval() {
|
|
14002
|
-
const fromConfig = parseUpdateCheckInterval(
|
|
13766
|
+
const fromConfig = parseUpdateCheckInterval(configGetGlobal(UpdaterConfig.configKeys.checkInterval));
|
|
14003
13767
|
return fromConfig ?? UpdaterConfig.defaults.checkInterval;
|
|
14004
13768
|
}
|
|
14005
13769
|
function setUpdateCheckInterval(interval) {
|
|
14006
|
-
|
|
13770
|
+
configSetGlobal(UpdaterConfig.configKeys.checkInterval, interval);
|
|
14007
13771
|
}
|
|
14008
13772
|
function parseUpdateSource(value) {
|
|
14009
13773
|
if (isAllowedValue(UpdaterSources, value)) {
|