Skip to content

Commit 4051bba

Browse files
committed
fix: support Socket CLI v2 settings directory layout
The Socket CLI v2 writes credentials to settings/config.json (a directory) instead of a flat settings file. The scanner now checks both locations, trying the legacy flat file first and falling back to the directory layout. Fixes #9
1 parent 1bac8d8 commit 4051bba

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@ if (typeof SOCKET_API_KEY !== 'string') {
2424
))
2525
}
2626

27-
// append `socket/settings`
28-
const defaultSettingsPath = path.join(dataHome, 'socket', 'settings')
29-
const file = Bun.file(defaultSettingsPath)
30-
3127
// attempt to read token from socket settings
32-
if (await file.exists()) {
33-
const rawContent = await file.text()
34-
// rawContent is base64, must decode
35-
36-
try {
37-
SOCKET_API_KEY = JSON.parse(Buffer.from(rawContent, 'base64').toString().trim()).apiToken
38-
} catch {
39-
throw new Error('error reading Socket settings')
28+
// supports both the legacy flat file and the CLI v2 directory layout
29+
const settingsPath = path.join(dataHome, 'socket', 'settings')
30+
const candidates = [
31+
Bun.file(settingsPath),
32+
Bun.file(path.join(settingsPath, 'config.json'))
33+
]
34+
35+
for (const file of candidates) {
36+
if (await file.exists()) {
37+
const rawContent = await file.text()
38+
// rawContent is base64, must decode
39+
40+
try {
41+
SOCKET_API_KEY = JSON.parse(Buffer.from(rawContent, 'base64').toString().trim()).apiToken
42+
} catch {
43+
throw new Error('error reading Socket settings')
44+
}
45+
46+
break
4047
}
4148
}
4249
}

0 commit comments

Comments
 (0)