@sudoji/cli 0.1.4 → 0.1.6
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/index.js +39 -13
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,12 +15,17 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from "f
|
|
|
15
15
|
import { join, dirname } from "path";
|
|
16
16
|
import { homedir } from "os";
|
|
17
17
|
var SERVICE = "sudoji";
|
|
18
|
+
function noKeychainAvailable() {
|
|
19
|
+
if (process.platform !== "linux") return false;
|
|
20
|
+
return !process.env["DBUS_SESSION_BUS_ADDRESS"] && !process.env["DISPLAY"];
|
|
21
|
+
}
|
|
18
22
|
async function tryKeytar() {
|
|
19
|
-
if (process.env["SUDOJI_NO_KEYCHAIN"]) return null;
|
|
23
|
+
if (process.env["SUDOJI_NO_KEYCHAIN"] || noKeychainAvailable()) return null;
|
|
20
24
|
try {
|
|
21
25
|
const k = await import("./keytar-2QOTTVWZ.js");
|
|
22
26
|
const mod = "default" in k ? k.default : k;
|
|
23
|
-
|
|
27
|
+
if (!mod || typeof mod.setPassword !== "function") return null;
|
|
28
|
+
return mod;
|
|
24
29
|
} catch {
|
|
25
30
|
return null;
|
|
26
31
|
}
|
|
@@ -51,20 +56,22 @@ function writeFile(path, creds) {
|
|
|
51
56
|
async function store(creds, profile = "default") {
|
|
52
57
|
const keytar = await tryKeytar();
|
|
53
58
|
if (keytar) {
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
try {
|
|
60
|
+
await keytar.setPassword(SERVICE, profile, JSON.stringify(creds));
|
|
61
|
+
return;
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
56
64
|
}
|
|
57
65
|
writeFile(filePath(profile), creds);
|
|
58
66
|
}
|
|
59
67
|
async function load(profile = "default") {
|
|
60
68
|
const keytar = await tryKeytar();
|
|
61
69
|
if (keytar) {
|
|
62
|
-
const raw = await keytar.getPassword(SERVICE, profile);
|
|
63
|
-
if (!raw) return null;
|
|
64
70
|
try {
|
|
71
|
+
const raw = await keytar.getPassword(SERVICE, profile);
|
|
72
|
+
if (!raw) return null;
|
|
65
73
|
return JSON.parse(raw);
|
|
66
74
|
} catch {
|
|
67
|
-
return null;
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
return readFile(filePath(profile));
|
|
@@ -72,8 +79,11 @@ async function load(profile = "default") {
|
|
|
72
79
|
async function clear(profile = "default") {
|
|
73
80
|
const keytar = await tryKeytar();
|
|
74
81
|
if (keytar) {
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
try {
|
|
83
|
+
await keytar.deletePassword(SERVICE, profile);
|
|
84
|
+
return;
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
const path = filePath(profile);
|
|
79
89
|
if (existsSync(path)) {
|
|
@@ -82,6 +92,24 @@ async function clear(profile = "default") {
|
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
// src/commands/login.ts
|
|
95
|
+
var _ = "\x1B[0m";
|
|
96
|
+
var C = "\x1B[36m";
|
|
97
|
+
var B = "\x1B[1m";
|
|
98
|
+
var G = "\x1B[32m";
|
|
99
|
+
var D = "\x1B[2m";
|
|
100
|
+
function printBanner(profile, key) {
|
|
101
|
+
const masked = key.slice(0, 14) + "\u2026";
|
|
102
|
+
console.log();
|
|
103
|
+
console.log(` ${C}${B}\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510${_}`);
|
|
104
|
+
console.log(` ${C}${B}\u2502${_} \u{1F99A} ${B}sudoji agent${_} ${G}${B}connected${_} ${C}${B}\u2502${_}`);
|
|
105
|
+
console.log(` ${C}${B}\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518${_}`);
|
|
106
|
+
console.log();
|
|
107
|
+
console.log(` ${D}profile${_} ${profile}`);
|
|
108
|
+
console.log(` ${D}key${_} ${masked}`);
|
|
109
|
+
console.log();
|
|
110
|
+
console.log(` ${D}next \u2192${_} sudoji doctor`);
|
|
111
|
+
console.log();
|
|
112
|
+
}
|
|
85
113
|
function loginCommand() {
|
|
86
114
|
return new Command("login").description("Authenticate the Sudoji CLI with an API key").option("--paste <key>", "Accept a key directly \u2014 useful for CI and scripting").option("--profile <name>", "Credentials profile to store the key under", "default").action(async (opts) => {
|
|
87
115
|
let key;
|
|
@@ -99,10 +127,8 @@ function loginCommand() {
|
|
|
99
127
|
console.error('Invalid key \u2014 keys start with "sudoji_sk_" and are at least 26 characters.');
|
|
100
128
|
process.exit(1);
|
|
101
129
|
}
|
|
102
|
-
await store(key, opts.profile);
|
|
103
|
-
|
|
104
|
-
Logged in. Key stored for profile "${opts.profile}".`);
|
|
105
|
-
console.log("Run: sudoji doctor to verify the connection.");
|
|
130
|
+
await store({ token: key }, opts.profile);
|
|
131
|
+
printBanner(opts.profile, key);
|
|
106
132
|
});
|
|
107
133
|
}
|
|
108
134
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudoji/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Sudoji installable IT agent CLI — diagnose, approve, fix on your Linux server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"sudoji": "
|
|
7
|
+
"sudoji": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|