@positronic/cli 0.0.57 → 0.0.59
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/src/cli.js +9 -0
- package/dist/src/commands/auth.js +13 -0
- package/dist/src/commands/helpers.js +60 -27
- package/dist/src/components/auth-format-jwk-key.js +457 -0
- package/dist/src/components/auth-login.js +3 -3
- package/dist/src/components/auth-logout.js +3 -3
- package/dist/src/hooks/useApi.js +183 -49
- package/dist/src/lib/jwt-auth.js +364 -0
- package/dist/src/lib/ssh-key-utils.js +0 -9
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/commands/auth.d.ts +8 -0
- package/dist/types/commands/auth.d.ts.map +1 -1
- package/dist/types/commands/helpers.d.ts +4 -0
- package/dist/types/commands/helpers.d.ts.map +1 -1
- package/dist/types/components/auth-format-jwk-key.d.ts +6 -0
- package/dist/types/components/auth-format-jwk-key.d.ts.map +1 -0
- package/dist/types/hooks/useApi.d.ts.map +1 -1
- package/dist/types/lib/jwt-auth.d.ts +51 -0
- package/dist/types/lib/jwt-auth.d.ts.map +1 -0
- package/dist/types/lib/ssh-key-utils.d.ts +0 -4
- package/dist/types/lib/ssh-key-utils.d.ts.map +1 -1
- package/package.json +5 -4
- package/dist/src/lib/request-signer.js +0 -208
- package/dist/types/lib/request-signer.d.ts +0 -51
- package/dist/types/lib/request-signer.d.ts.map +0 -1
package/dist/src/cli.js
CHANGED
|
@@ -986,6 +986,15 @@ export function buildCli(options) {
|
|
|
986
986
|
}).command('list', 'List available SSH keys\n', function() {}, function() {
|
|
987
987
|
var element = authCommand.list();
|
|
988
988
|
render(element);
|
|
989
|
+
}).command('format-jwk-key', 'Convert an SSH public key to JWK format for ROOT_PUBLIC_KEY\n', function(yargsFormatJwkKey) {
|
|
990
|
+
return yargsFormatJwkKey.option('pubkey', {
|
|
991
|
+
describe: 'Path to SSH public key file',
|
|
992
|
+
type: 'string',
|
|
993
|
+
alias: 'p'
|
|
994
|
+
}).example('$0 auth format-jwk-key', 'Interactive public key selection').example('$0 auth format-jwk-key --pubkey ~/.ssh/id_ed25519.pub', 'Convert specific key');
|
|
995
|
+
}, function(argv) {
|
|
996
|
+
var element = authCommand.formatJwkKey(argv);
|
|
997
|
+
render(element);
|
|
989
998
|
}).command('$0', false, function() {}, function() {
|
|
990
999
|
// Default to status when just 'px auth' is run
|
|
991
1000
|
var element = authCommand.status();
|
|
@@ -35,6 +35,7 @@ import { AuthStatus } from '../components/auth-status.js';
|
|
|
35
35
|
import { AuthLogin } from '../components/auth-login.js';
|
|
36
36
|
import { AuthLogout } from '../components/auth-logout.js';
|
|
37
37
|
import { AuthList } from '../components/auth-list.js';
|
|
38
|
+
import { AuthFormatJwkKey } from '../components/auth-format-jwk-key.js';
|
|
38
39
|
import { ProjectConfigManager } from './project-config-manager.js';
|
|
39
40
|
export var AuthCommand = /*#__PURE__*/ function() {
|
|
40
41
|
"use strict";
|
|
@@ -92,6 +93,18 @@ export var AuthCommand = /*#__PURE__*/ function() {
|
|
|
92
93
|
configManager: this.configManager
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
/**
|
|
99
|
+
* Handles the 'px auth format-jwk-key' command.
|
|
100
|
+
* Convert an SSH public key to JWK format for ROOT_PUBLIC_KEY configuration.
|
|
101
|
+
*/ key: "formatJwkKey",
|
|
102
|
+
value: function formatJwkKey(param) {
|
|
103
|
+
var pubkey = param.pubkey;
|
|
104
|
+
return React.createElement(AuthFormatJwkKey, {
|
|
105
|
+
pubkeyPath: pubkey
|
|
106
|
+
});
|
|
107
|
+
}
|
|
95
108
|
}
|
|
96
109
|
]);
|
|
97
110
|
return AuthCommand;
|
|
@@ -233,7 +233,7 @@ import * as https from 'https';
|
|
|
233
233
|
import { URL } from 'url';
|
|
234
234
|
import { createRequire } from 'module';
|
|
235
235
|
import * as dotenv from 'dotenv';
|
|
236
|
-
import {
|
|
236
|
+
import { getAuthHeader } from '../lib/jwt-auth.js';
|
|
237
237
|
// API client configuration
|
|
238
238
|
var apiBaseUrl = null;
|
|
239
239
|
var isLocalDevMode = true;
|
|
@@ -267,7 +267,63 @@ var isLocalDevMode = true;
|
|
|
267
267
|
export var apiClient = {
|
|
268
268
|
fetch: function(apiPath, options) {
|
|
269
269
|
return _async_to_generator(function() {
|
|
270
|
-
var baseUrl, port, fullUrl, requestOptions,
|
|
270
|
+
var baseUrl, port, fullUrl, requestOptions, existingHeaders, headersObj, authHeader;
|
|
271
|
+
return _ts_generator(this, function(_state) {
|
|
272
|
+
switch(_state.label){
|
|
273
|
+
case 0:
|
|
274
|
+
if (apiBaseUrl) {
|
|
275
|
+
baseUrl = apiBaseUrl;
|
|
276
|
+
} else {
|
|
277
|
+
// Fallback to localhost (for backwards compatibility and testing)
|
|
278
|
+
port = process.env.POSITRONIC_PORT || '8787';
|
|
279
|
+
baseUrl = "http://localhost:".concat(port);
|
|
280
|
+
}
|
|
281
|
+
fullUrl = "".concat(baseUrl).concat(apiPath.startsWith('/') ? apiPath : '/' + apiPath);
|
|
282
|
+
// Add auth header when not in local dev mode
|
|
283
|
+
requestOptions = options || {};
|
|
284
|
+
if (!!isLocalDevMode) return [
|
|
285
|
+
3,
|
|
286
|
+
2
|
|
287
|
+
];
|
|
288
|
+
existingHeaders = (options === null || options === void 0 ? void 0 : options.headers) || {};
|
|
289
|
+
headersObj = {};
|
|
290
|
+
// Convert headers to plain object
|
|
291
|
+
if (_instanceof(existingHeaders, Headers)) {
|
|
292
|
+
existingHeaders.forEach(function(value, key) {
|
|
293
|
+
headersObj[key] = value;
|
|
294
|
+
});
|
|
295
|
+
} else if (Array.isArray(existingHeaders)) {
|
|
296
|
+
existingHeaders.forEach(function(param) {
|
|
297
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
298
|
+
headersObj[key] = value;
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
Object.assign(headersObj, existingHeaders);
|
|
302
|
+
}
|
|
303
|
+
return [
|
|
304
|
+
4,
|
|
305
|
+
getAuthHeader()
|
|
306
|
+
];
|
|
307
|
+
case 1:
|
|
308
|
+
authHeader = _state.sent();
|
|
309
|
+
requestOptions = _object_spread_props(_object_spread({}, options), {
|
|
310
|
+
headers: _object_spread({}, headersObj, authHeader)
|
|
311
|
+
});
|
|
312
|
+
_state.label = 2;
|
|
313
|
+
case 2:
|
|
314
|
+
return [
|
|
315
|
+
2,
|
|
316
|
+
fetch(fullUrl, requestOptions)
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
})();
|
|
321
|
+
},
|
|
322
|
+
/**
|
|
323
|
+
* Fetch without authentication - used for unauthenticated endpoints like /auth/setup
|
|
324
|
+
*/ fetchUnauthenticated: function(apiPath, options) {
|
|
325
|
+
return _async_to_generator(function() {
|
|
326
|
+
var baseUrl, port, fullUrl;
|
|
271
327
|
return _ts_generator(this, function(_state) {
|
|
272
328
|
if (apiBaseUrl) {
|
|
273
329
|
baseUrl = apiBaseUrl;
|
|
@@ -277,33 +333,10 @@ export var apiClient = {
|
|
|
277
333
|
baseUrl = "http://localhost:".concat(port);
|
|
278
334
|
}
|
|
279
335
|
fullUrl = "".concat(baseUrl).concat(apiPath.startsWith('/') ? apiPath : '/' + apiPath);
|
|
280
|
-
//
|
|
281
|
-
requestOptions = options || {};
|
|
282
|
-
if (!isLocalDevMode) {
|
|
283
|
-
method = ((options === null || options === void 0 ? void 0 : options.method) || 'GET').toUpperCase();
|
|
284
|
-
existingHeaders = (options === null || options === void 0 ? void 0 : options.headers) || {};
|
|
285
|
-
headersObj = {};
|
|
286
|
-
// Convert headers to plain object
|
|
287
|
-
if (_instanceof(existingHeaders, Headers)) {
|
|
288
|
-
existingHeaders.forEach(function(value, key) {
|
|
289
|
-
headersObj[key] = value;
|
|
290
|
-
});
|
|
291
|
-
} else if (Array.isArray(existingHeaders)) {
|
|
292
|
-
existingHeaders.forEach(function(param) {
|
|
293
|
-
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
294
|
-
headersObj[key] = value;
|
|
295
|
-
});
|
|
296
|
-
} else {
|
|
297
|
-
Object.assign(headersObj, existingHeaders);
|
|
298
|
-
}
|
|
299
|
-
signatureHeaders = maybeSignRequest(method, fullUrl, headersObj);
|
|
300
|
-
requestOptions = _object_spread_props(_object_spread({}, options), {
|
|
301
|
-
headers: _object_spread({}, headersObj, signatureHeaders)
|
|
302
|
-
});
|
|
303
|
-
}
|
|
336
|
+
// Don't sign the request - this is for unauthenticated endpoints
|
|
304
337
|
return [
|
|
305
338
|
2,
|
|
306
|
-
fetch(fullUrl,
|
|
339
|
+
fetch(fullUrl, options)
|
|
307
340
|
];
|
|
308
341
|
});
|
|
309
342
|
})();
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterable_to_array_limit(arr, i) {
|
|
39
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
+
if (_i == null) return;
|
|
41
|
+
var _arr = [];
|
|
42
|
+
var _n = true;
|
|
43
|
+
var _d = false;
|
|
44
|
+
var _s, _e;
|
|
45
|
+
try {
|
|
46
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
+
_arr.push(_s.value);
|
|
48
|
+
if (i && _arr.length === i) break;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_d = true;
|
|
52
|
+
_e = err;
|
|
53
|
+
} finally{
|
|
54
|
+
try {
|
|
55
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
+
} finally{
|
|
57
|
+
if (_d) throw _e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return _arr;
|
|
61
|
+
}
|
|
62
|
+
function _non_iterable_rest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _sliced_to_array(arr, i) {
|
|
66
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
|
+
}
|
|
68
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
69
|
+
if (!o) return;
|
|
70
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
71
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
72
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
73
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
74
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
75
|
+
}
|
|
76
|
+
function _ts_generator(thisArg, body) {
|
|
77
|
+
var f, y, t, _ = {
|
|
78
|
+
label: 0,
|
|
79
|
+
sent: function() {
|
|
80
|
+
if (t[0] & 1) throw t[1];
|
|
81
|
+
return t[1];
|
|
82
|
+
},
|
|
83
|
+
trys: [],
|
|
84
|
+
ops: []
|
|
85
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
86
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
87
|
+
return this;
|
|
88
|
+
}), g;
|
|
89
|
+
function verb(n) {
|
|
90
|
+
return function(v) {
|
|
91
|
+
return step([
|
|
92
|
+
n,
|
|
93
|
+
v
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function step(op) {
|
|
98
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
99
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
100
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
101
|
+
if (y = 0, t) op = [
|
|
102
|
+
op[0] & 2,
|
|
103
|
+
t.value
|
|
104
|
+
];
|
|
105
|
+
switch(op[0]){
|
|
106
|
+
case 0:
|
|
107
|
+
case 1:
|
|
108
|
+
t = op;
|
|
109
|
+
break;
|
|
110
|
+
case 4:
|
|
111
|
+
_.label++;
|
|
112
|
+
return {
|
|
113
|
+
value: op[1],
|
|
114
|
+
done: false
|
|
115
|
+
};
|
|
116
|
+
case 5:
|
|
117
|
+
_.label++;
|
|
118
|
+
y = op[1];
|
|
119
|
+
op = [
|
|
120
|
+
0
|
|
121
|
+
];
|
|
122
|
+
continue;
|
|
123
|
+
case 7:
|
|
124
|
+
op = _.ops.pop();
|
|
125
|
+
_.trys.pop();
|
|
126
|
+
continue;
|
|
127
|
+
default:
|
|
128
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
129
|
+
_ = 0;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
133
|
+
_.label = op[1];
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
137
|
+
_.label = t[1];
|
|
138
|
+
t = op;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (t && _.label < t[2]) {
|
|
142
|
+
_.label = t[2];
|
|
143
|
+
_.ops.push(op);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (t[2]) _.ops.pop();
|
|
147
|
+
_.trys.pop();
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
op = body.call(thisArg, _);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
op = [
|
|
153
|
+
6,
|
|
154
|
+
e
|
|
155
|
+
];
|
|
156
|
+
y = 0;
|
|
157
|
+
} finally{
|
|
158
|
+
f = t = 0;
|
|
159
|
+
}
|
|
160
|
+
if (op[0] & 5) throw op[1];
|
|
161
|
+
return {
|
|
162
|
+
value: op[0] ? op[1] : void 0,
|
|
163
|
+
done: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
import React, { useState, useEffect } from 'react';
|
|
168
|
+
import { Box, Text, useApp } from 'ink';
|
|
169
|
+
import { existsSync, readdirSync } from 'fs';
|
|
170
|
+
import { homedir } from 'os';
|
|
171
|
+
import { join } from 'path';
|
|
172
|
+
import { convertSSHPubKeyToJWK, expandPath } from '../lib/ssh-key-utils.js';
|
|
173
|
+
import { SelectList } from './select-list.js';
|
|
174
|
+
/**
|
|
175
|
+
* Discover available SSH public keys in ~/.ssh
|
|
176
|
+
*/ function discoverSSHPubKeys() {
|
|
177
|
+
var sshDir = join(homedir(), '.ssh');
|
|
178
|
+
if (!existsSync(sshDir)) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
var pubKeys = [];
|
|
182
|
+
try {
|
|
183
|
+
var files = readdirSync(sshDir);
|
|
184
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
185
|
+
try {
|
|
186
|
+
for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
187
|
+
var file = _step.value;
|
|
188
|
+
if (file.endsWith('.pub')) {
|
|
189
|
+
var fullPath = join(sshDir, file);
|
|
190
|
+
pubKeys.push({
|
|
191
|
+
path: fullPath,
|
|
192
|
+
displayPath: "~/.ssh/".concat(file)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
_didIteratorError = true;
|
|
198
|
+
_iteratorError = err;
|
|
199
|
+
} finally{
|
|
200
|
+
try {
|
|
201
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
202
|
+
_iterator.return();
|
|
203
|
+
}
|
|
204
|
+
} finally{
|
|
205
|
+
if (_didIteratorError) {
|
|
206
|
+
throw _iteratorError;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
return pubKeys;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Copy text to clipboard using pbcopy (macOS) or xclip (Linux)
|
|
217
|
+
*/ function copyToClipboard(text) {
|
|
218
|
+
return _async_to_generator(function() {
|
|
219
|
+
var spawn;
|
|
220
|
+
return _ts_generator(this, function(_state) {
|
|
221
|
+
switch(_state.label){
|
|
222
|
+
case 0:
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
import('child_process')
|
|
226
|
+
];
|
|
227
|
+
case 1:
|
|
228
|
+
spawn = _state.sent().spawn;
|
|
229
|
+
return [
|
|
230
|
+
2,
|
|
231
|
+
new Promise(function(resolve) {
|
|
232
|
+
var _proc_stdin, _proc_stdin1;
|
|
233
|
+
// Try pbcopy first (macOS)
|
|
234
|
+
var proc = spawn('pbcopy', [], {
|
|
235
|
+
stdio: [
|
|
236
|
+
'pipe',
|
|
237
|
+
'ignore',
|
|
238
|
+
'ignore'
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
proc.on('error', function() {
|
|
242
|
+
var _proc_stdin, _proc_stdin1;
|
|
243
|
+
// Try xclip (Linux)
|
|
244
|
+
proc = spawn('xclip', [
|
|
245
|
+
'-selection',
|
|
246
|
+
'clipboard'
|
|
247
|
+
], {
|
|
248
|
+
stdio: [
|
|
249
|
+
'pipe',
|
|
250
|
+
'ignore',
|
|
251
|
+
'ignore'
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
proc.on('error', function() {
|
|
255
|
+
resolve(false);
|
|
256
|
+
});
|
|
257
|
+
proc.on('close', function(code) {
|
|
258
|
+
resolve(code === 0);
|
|
259
|
+
});
|
|
260
|
+
(_proc_stdin = proc.stdin) === null || _proc_stdin === void 0 ? void 0 : _proc_stdin.write(text);
|
|
261
|
+
(_proc_stdin1 = proc.stdin) === null || _proc_stdin1 === void 0 ? void 0 : _proc_stdin1.end();
|
|
262
|
+
});
|
|
263
|
+
proc.on('close', function(code) {
|
|
264
|
+
resolve(code === 0);
|
|
265
|
+
});
|
|
266
|
+
(_proc_stdin = proc.stdin) === null || _proc_stdin === void 0 ? void 0 : _proc_stdin.write(text);
|
|
267
|
+
(_proc_stdin1 = proc.stdin) === null || _proc_stdin1 === void 0 ? void 0 : _proc_stdin1.end();
|
|
268
|
+
})
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
})();
|
|
273
|
+
}
|
|
274
|
+
export var AuthFormatJwkKey = function(param) {
|
|
275
|
+
var pubkeyPath = param.pubkeyPath;
|
|
276
|
+
var exit = useApp().exit;
|
|
277
|
+
var _useState = _sliced_to_array(useState(pubkeyPath ? 'success' : 'selecting'), 2), state = _useState[0], setState = _useState[1];
|
|
278
|
+
var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
|
|
279
|
+
var _useState2 = _sliced_to_array(useState(null), 2), jwkOutput = _useState2[0], setJwkOutput = _useState2[1];
|
|
280
|
+
var _useState3 = _sliced_to_array(useState(null), 2), fingerprint = _useState3[0], setFingerprint = _useState3[1];
|
|
281
|
+
var _useState4 = _sliced_to_array(useState(false), 2), copiedToClipboard = _useState4[0], setCopiedToClipboard = _useState4[1];
|
|
282
|
+
var _useState5 = _sliced_to_array(useState(pubkeyPath || null), 2), selectedPath = _useState5[0], setSelectedPath = _useState5[1];
|
|
283
|
+
// Handle direct path provided via --pubkey
|
|
284
|
+
useEffect(function() {
|
|
285
|
+
if (pubkeyPath && state === 'success' && !jwkOutput) {
|
|
286
|
+
processKey(pubkeyPath);
|
|
287
|
+
}
|
|
288
|
+
}, [
|
|
289
|
+
pubkeyPath,
|
|
290
|
+
state,
|
|
291
|
+
jwkOutput
|
|
292
|
+
]);
|
|
293
|
+
var processKey = function(keyPath) {
|
|
294
|
+
return _async_to_generator(function() {
|
|
295
|
+
var expandedPath, keyInfo, jwkString, copied, err;
|
|
296
|
+
return _ts_generator(this, function(_state) {
|
|
297
|
+
switch(_state.label){
|
|
298
|
+
case 0:
|
|
299
|
+
_state.trys.push([
|
|
300
|
+
0,
|
|
301
|
+
2,
|
|
302
|
+
,
|
|
303
|
+
3
|
|
304
|
+
]);
|
|
305
|
+
expandedPath = expandPath(keyPath);
|
|
306
|
+
if (!existsSync(expandedPath)) {
|
|
307
|
+
setError("Public key file not found: ".concat(keyPath));
|
|
308
|
+
setState('error');
|
|
309
|
+
return [
|
|
310
|
+
2
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
keyInfo = convertSSHPubKeyToJWK(expandedPath);
|
|
314
|
+
jwkString = JSON.stringify(keyInfo.jwk, null, 2);
|
|
315
|
+
setJwkOutput(jwkString);
|
|
316
|
+
setFingerprint(keyInfo.fingerprint);
|
|
317
|
+
setSelectedPath(keyPath);
|
|
318
|
+
return [
|
|
319
|
+
4,
|
|
320
|
+
copyToClipboard(jwkString)
|
|
321
|
+
];
|
|
322
|
+
case 1:
|
|
323
|
+
copied = _state.sent();
|
|
324
|
+
setCopiedToClipboard(copied);
|
|
325
|
+
setState('success');
|
|
326
|
+
return [
|
|
327
|
+
3,
|
|
328
|
+
3
|
|
329
|
+
];
|
|
330
|
+
case 2:
|
|
331
|
+
err = _state.sent();
|
|
332
|
+
setError(err.message || 'Failed to convert key');
|
|
333
|
+
setState('error');
|
|
334
|
+
return [
|
|
335
|
+
3,
|
|
336
|
+
3
|
|
337
|
+
];
|
|
338
|
+
case 3:
|
|
339
|
+
return [
|
|
340
|
+
2
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
})();
|
|
345
|
+
};
|
|
346
|
+
// Check for available keys when in selecting state
|
|
347
|
+
var pubKeys = discoverSSHPubKeys();
|
|
348
|
+
if (state === 'selecting' && pubKeys.length === 0) {
|
|
349
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
350
|
+
flexDirection: "column",
|
|
351
|
+
paddingTop: 1,
|
|
352
|
+
paddingBottom: 1
|
|
353
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
354
|
+
color: "yellow"
|
|
355
|
+
}, "No SSH public keys found in ~/.ssh/"), /*#__PURE__*/ React.createElement(Box, {
|
|
356
|
+
marginTop: 1,
|
|
357
|
+
flexDirection: "column"
|
|
358
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
359
|
+
dimColor: true
|
|
360
|
+
}, "Generate a new SSH key with:"), /*#__PURE__*/ React.createElement(Box, {
|
|
361
|
+
marginLeft: 2,
|
|
362
|
+
marginTop: 1
|
|
363
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
364
|
+
color: "cyan"
|
|
365
|
+
}, 'ssh-keygen -t ed25519 -C "your-email@example.com"'))), /*#__PURE__*/ React.createElement(Box, {
|
|
366
|
+
marginTop: 1
|
|
367
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
368
|
+
dimColor: true
|
|
369
|
+
}, "Or specify a public key path with: px auth format-jwk-key --pubkey /path/to/key.pub")));
|
|
370
|
+
}
|
|
371
|
+
if (state === 'selecting') {
|
|
372
|
+
var items = pubKeys.map(function(key) {
|
|
373
|
+
return {
|
|
374
|
+
id: key.path,
|
|
375
|
+
label: key.displayPath,
|
|
376
|
+
description: ''
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
var handleSelect = function(item) {
|
|
380
|
+
return _async_to_generator(function() {
|
|
381
|
+
return _ts_generator(this, function(_state) {
|
|
382
|
+
switch(_state.label){
|
|
383
|
+
case 0:
|
|
384
|
+
return [
|
|
385
|
+
4,
|
|
386
|
+
processKey(item.id)
|
|
387
|
+
];
|
|
388
|
+
case 1:
|
|
389
|
+
_state.sent();
|
|
390
|
+
return [
|
|
391
|
+
2
|
|
392
|
+
];
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
})();
|
|
396
|
+
};
|
|
397
|
+
var handleCancel = function() {
|
|
398
|
+
exit();
|
|
399
|
+
};
|
|
400
|
+
return /*#__PURE__*/ React.createElement(SelectList, {
|
|
401
|
+
items: items,
|
|
402
|
+
header: "Select an SSH public key to convert to JWK format",
|
|
403
|
+
onSelect: handleSelect,
|
|
404
|
+
onCancel: handleCancel,
|
|
405
|
+
footer: "Use arrow keys to navigate, Enter to select, q to cancel"
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (state === 'error') {
|
|
409
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
410
|
+
flexDirection: "column",
|
|
411
|
+
paddingTop: 1,
|
|
412
|
+
paddingBottom: 1
|
|
413
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
414
|
+
color: "red"
|
|
415
|
+
}, "Error: ", error));
|
|
416
|
+
}
|
|
417
|
+
if (state === 'success' && jwkOutput) {
|
|
418
|
+
var displayPath = (selectedPath === null || selectedPath === void 0 ? void 0 : selectedPath.startsWith(homedir())) ? selectedPath.replace(homedir(), '~') : selectedPath;
|
|
419
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
420
|
+
flexDirection: "column",
|
|
421
|
+
paddingTop: 1,
|
|
422
|
+
paddingBottom: 1
|
|
423
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
424
|
+
bold: true,
|
|
425
|
+
color: "green"
|
|
426
|
+
}, "JWK Public Key"), /*#__PURE__*/ React.createElement(Box, {
|
|
427
|
+
marginTop: 1
|
|
428
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
429
|
+
dimColor: true
|
|
430
|
+
}, "Source: ", displayPath)), fingerprint && /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, {
|
|
431
|
+
dimColor: true
|
|
432
|
+
}, "Fingerprint: ", fingerprint)), /*#__PURE__*/ React.createElement(Box, {
|
|
433
|
+
marginTop: 1,
|
|
434
|
+
flexDirection: "column"
|
|
435
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
436
|
+
color: "cyan"
|
|
437
|
+
}, jwkOutput)), /*#__PURE__*/ React.createElement(Box, {
|
|
438
|
+
marginTop: 1
|
|
439
|
+
}, copiedToClipboard ? /*#__PURE__*/ React.createElement(Text, {
|
|
440
|
+
color: "green"
|
|
441
|
+
}, "Copied to clipboard.") : /*#__PURE__*/ React.createElement(Text, {
|
|
442
|
+
color: "yellow"
|
|
443
|
+
}, "Could not copy to clipboard - copy the value above manually.")), /*#__PURE__*/ React.createElement(Box, {
|
|
444
|
+
marginTop: 1,
|
|
445
|
+
flexDirection: "column"
|
|
446
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
447
|
+
bold: true
|
|
448
|
+
}, "Next steps:"), /*#__PURE__*/ React.createElement(Box, {
|
|
449
|
+
marginLeft: 2,
|
|
450
|
+
marginTop: 1,
|
|
451
|
+
flexDirection: "column"
|
|
452
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "1. Go to Cloudflare dashboard"), /*#__PURE__*/ React.createElement(Text, null, "2. Navigate to Workers & Pages ", '>', " Your project ", '>', " Settings ", '>', " Variables and Secrets"), /*#__PURE__*/ React.createElement(Text, null, "3. Add a new secret named ", /*#__PURE__*/ React.createElement(Text, {
|
|
453
|
+
color: "cyan"
|
|
454
|
+
}, "ROOT_PUBLIC_KEY")), /*#__PURE__*/ React.createElement(Text, null, "4. Paste the JWK value above"))));
|
|
455
|
+
}
|
|
456
|
+
return null;
|
|
457
|
+
};
|
|
@@ -47,7 +47,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
47
47
|
import React, { useState } from 'react';
|
|
48
48
|
import { Box, Text, useApp } from 'ink';
|
|
49
49
|
import { discoverSSHKeys, expandPath } from '../lib/ssh-key-utils.js';
|
|
50
|
-
import {
|
|
50
|
+
import { resetJwtAuthProvider } from '../lib/jwt-auth.js';
|
|
51
51
|
import { SelectList } from './select-list.js';
|
|
52
52
|
import { existsSync } from 'fs';
|
|
53
53
|
export var AuthLogin = function(param) {
|
|
@@ -103,7 +103,7 @@ export var AuthLogin = function(param) {
|
|
|
103
103
|
configManager.setDefaultPrivateKeyPath(keyPath);
|
|
104
104
|
}
|
|
105
105
|
// Reset request signer to use new key
|
|
106
|
-
|
|
106
|
+
resetJwtAuthProvider();
|
|
107
107
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
108
108
|
flexDirection: "column",
|
|
109
109
|
paddingTop: 1,
|
|
@@ -163,7 +163,7 @@ export var AuthLogin = function(param) {
|
|
|
163
163
|
configManager.setDefaultPrivateKeyPath(displayPath);
|
|
164
164
|
}
|
|
165
165
|
// Reset request signer to use new key
|
|
166
|
-
|
|
166
|
+
resetJwtAuthProvider();
|
|
167
167
|
setSelectedPath(displayPath);
|
|
168
168
|
setState('success');
|
|
169
169
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
|
-
import {
|
|
3
|
+
import { resetJwtAuthProvider } from '../lib/jwt-auth.js';
|
|
4
4
|
export var AuthLogout = function(param) {
|
|
5
5
|
var configManager = param.configManager, forProject = param.forProject;
|
|
6
6
|
var currentProject = configManager.getCurrentProject();
|
|
@@ -33,7 +33,7 @@ export var AuthLogout = function(param) {
|
|
|
33
33
|
}, "Nothing to clear.")));
|
|
34
34
|
}
|
|
35
35
|
configManager.clearProjectPrivateKeyPath(currentProject.name);
|
|
36
|
-
|
|
36
|
+
resetJwtAuthProvider();
|
|
37
37
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
38
38
|
flexDirection: "column",
|
|
39
39
|
paddingTop: 1,
|
|
@@ -60,7 +60,7 @@ export var AuthLogout = function(param) {
|
|
|
60
60
|
}, "Nothing to clear.")));
|
|
61
61
|
}
|
|
62
62
|
configManager.clearDefaultPrivateKeyPath();
|
|
63
|
-
|
|
63
|
+
resetJwtAuthProvider();
|
|
64
64
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
65
65
|
flexDirection: "column",
|
|
66
66
|
paddingTop: 1,
|