Skip to content

Commit 90088f9

Browse files
committed
Support the SOCKET_CLI_ORG_SLUG env var
1 parent 53937e1 commit 90088f9

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/commands/ci/fetch-default-org-slug.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { debugFn } from '@socketsecurity/registry/lib/debug'
22

3+
import constants from '../../constants.mts'
34
import { getConfigValueOrUndef } from '../../utils/config.mts'
45
import { fetchOrganization } from '../organization/fetch-organization-list.mts'
56

@@ -13,6 +14,13 @@ export async function getDefaultOrgSlug(): Promise<CResult<string>> {
1314
return { ok: true, data: defaultOrgResult }
1415
}
1516

17+
// Lazily access constants.ENV.SOCKET_CLI_ORG_SLUG.
18+
const envOrgSlug = constants.ENV.SOCKET_CLI_ORG_SLUG
19+
if (envOrgSlug) {
20+
debugFn('notice', 'use: org from environment variable', envOrgSlug)
21+
return { ok: true, data: envOrgSlug }
22+
}
23+
1624
const orgsCResult = await fetchOrganization()
1725
if (!orgsCResult.ok) {
1826
return orgsCResult

src/commands/fix/cmd-fix.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ async function run(
188188
const orgSlugCResult = await getDefaultOrgSlug()
189189
if (!orgSlugCResult.ok) {
190190
process.exitCode = orgSlugCResult.code ?? 1
191-
// Always assume json mode.
192-
// logger.log(serializeResultJson(orgSlugCResult))
191+
logger.fail(
192+
'Unable to resolve a Socket account organization.\nEnsure a Socket API token is specified for the organization using the SOCKET_CLI_API_TOKEN environment variable.',
193+
)
193194
return
194195
}
195196

src/constants.mts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type ENV = Remap<
7979
SOCKET_CLI_GIT_USER_NAME: string
8080
SOCKET_CLI_GITHUB_TOKEN: string
8181
SOCKET_CLI_NO_API_TOKEN: boolean
82+
SOCKET_CLI_ORG_SLUG: string
8283
SOCKET_CLI_VIEW_ALL_RISKS: boolean
8384
TERM: string
8485
XDG_DATA_HOME: string
@@ -248,7 +249,7 @@ const LAZY_ENV = () => {
248249
__proto__: null,
249250
// Lazily access registryConstants.ENV.
250251
...registryConstants.ENV,
251-
// Flag to disable using GitHub's workflow actions/cache.
252+
// Variable to disable using GitHub's workflow actions/cache.
252253
// https://github.com/actions/cache
253254
DISABLE_GITHUB_CACHE: envAsBoolean(env['DISABLE_GITHUB_CACHE']),
254255
// The API URL. For example, https://api.github.com.
@@ -329,7 +330,7 @@ const LAZY_ENV = () => {
329330
// non-roaming application data, like temporary files, cached data, and program
330331
// settings, that are specific to the current machine and user.
331332
LOCALAPPDATA: envAsString(env[LOCALAPPDATA]),
332-
// Flag to enable the module compile cache for the Node.js instance.
333+
// Variable to enable the module compile cache for the Node.js instance.
333334
// https://nodejs.org/api/cli.html#node_compile_cachedir
334335
NODE_COMPILE_CACHE:
335336
// Lazily access constants.SUPPORTS_NODE_COMPILE_CACHE_ENV_VAR.
@@ -350,16 +351,16 @@ const LAZY_ENV = () => {
350351
// programs are located. When a command is run, the system searches these
351352
// directories to find the executable.
352353
PATH: envAsString(env['PATH']),
353-
// Flag to accepts risks of safe-npm and safe-npx run.
354+
// Variable to accepts risks of safe-npm and safe-npx run.
354355
SOCKET_CLI_ACCEPT_RISKS: envAsBoolean(env[SOCKET_CLI_ACCEPT_RISKS]),
355-
// Flag to change the base URL for all API-calls.
356+
// Variable to change the base URL for all API-calls.
356357
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables-for-development
357358
SOCKET_CLI_API_BASE_URL:
358359
envAsString(env['SOCKET_CLI_API_BASE_URL']) ||
359360
envAsString(env['SOCKET_SECURITY_API_BASE_URL']) ||
360361
getConfigValueOrUndef('apiBaseUrl') ||
361362
'https://api.socket.dev/v0/',
362-
// Flag to set the proxy all requests are routed through.
363+
// Variable to set the proxy all requests are routed through.
363364
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables-for-development
364365
SOCKET_CLI_API_PROXY:
365366
envAsString(env['SOCKET_CLI_API_PROXY']) ||
@@ -370,16 +371,16 @@ const LAZY_ENV = () => {
370371
envAsString(env['https_proxy']) ||
371372
envAsString(env['HTTP_PROXY']) ||
372373
envAsString(env['http_proxy']),
373-
// Flag to set the API token.
374+
// Variable to set the Socket API token.
374375
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables
375376
SOCKET_CLI_API_TOKEN:
376377
envAsString(env['SOCKET_CLI_API_TOKEN']) ||
377378
envAsString(env['SOCKET_CLI_API_KEY']) ||
378379
envAsString(env['SOCKET_SECURITY_API_TOKEN']) ||
379380
envAsString(env['SOCKET_SECURITY_API_KEY']),
380-
// Flag containing a JSON stringified Socket configuration object.
381+
// Variable containing a JSON stringified Socket configuration object.
381382
SOCKET_CLI_CONFIG: envAsString(env['SOCKET_CLI_CONFIG']),
382-
// Flag to help debug Socket CLI.
383+
// Variable to help debug Socket CLI.
383384
SOCKET_CLI_DEBUG: envAsBoolean(env['SOCKET_CLI_DEBUG']),
384385
// The git config user.email used by Socket CLI.
385386
SOCKET_CLI_GIT_USER_EMAIL:
@@ -398,9 +399,14 @@ const LAZY_ENV = () => {
398399
envAsString(env['SOCKET_CLI_GITHUB_TOKEN']) ||
399400
envAsString(env['SOCKET_SECURITY_GITHUB_PAT']) ||
400401
GITHUB_TOKEN,
401-
// Flag to make the default API token `undefined`.
402+
// Variable to make the default API token `undefined`.
402403
SOCKET_CLI_NO_API_TOKEN: envAsBoolean(env['SOCKET_CLI_NO_API_TOKEN']),
403-
// Flag to view all risks of safe-npm and safe-npx run.
404+
// Variable to specify the Socket organization slug.
405+
SOCKET_CLI_ORG_SLUG:
406+
envAsString(env['SOCKET_CLI_ORG_SLUG']) ||
407+
// Coana CLI accepts the SOCKET_ORG_SLUG environment variable.
408+
envAsString(env['SOCKET_ORG_SLUG']),
409+
// Variable to view all risks of safe-npm and safe-npx run.
404410
SOCKET_CLI_VIEW_ALL_RISKS: envAsBoolean(env[SOCKET_CLI_VIEW_ALL_RISKS]),
405411
// Specifies the type of terminal or terminal emulator being used by the process.
406412
TERM: envAsString(env['TERM']),

0 commit comments

Comments
 (0)