Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/commands/scan/cmd-scan-create.mts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ const generalFlags: MeowFlags = {
shortFlag: 'r',
description: 'Repository name',
},
workspace: {
type: 'string',
default: '',
description:
'The workspace in the Socket Organization that the repository is in to associate with the full scan.',
},
report: {
type: 'boolean',
description:
Expand Down Expand Up @@ -304,11 +310,13 @@ async function run(
branch: branchName,
repo: repoName,
report,
workspace,
} = cli.flags as {
autoManifest?: boolean | undefined
branch: string
repo: string
report?: boolean | undefined
workspace: string
}

let { 0: orgSlug } = await determineOrgSlug(
Expand Down Expand Up @@ -353,6 +361,10 @@ async function run(
repoName = await getRepoName(cwd)
}
}
if (!workspace && sockJson.defaults?.scan?.create?.workspace) {
workspace = sockJson.defaults.scan.create.workspace
logger.info(`Using default --workspace from ${SOCKET_JSON}:`, workspace)
}
if (typeof report !== 'boolean') {
if (sockJson.defaults?.scan?.create?.report !== undefined) {
report = sockJson.defaults.scan.create.report
Expand Down Expand Up @@ -595,5 +607,6 @@ async function run(
reportLevel,
targets,
tmp: Boolean(tmp),
workspace: (workspace && String(workspace)) || '',
})
}
1 change: 1 addition & 0 deletions src/commands/scan/cmd-scan-create.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('socket scan create', async () => {
--report-level Which policy level alerts should be reported (default 'error')
--set-as-alerts-page When true and if this is the "default branch" then this Scan will be the one reflected on your alerts page. See help for details. Defaults to true.
--tmp Set the visibility (true/false) of the scan in your dashboard.
--workspace The workspace in the Socket Organization that the repository is in to associate with the full scan.

Reachability Options (when --reach is used)
--reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB.
Expand Down
3 changes: 3 additions & 0 deletions src/commands/scan/fetch-create-org-full-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type FetchCreateOrgFullScanConfigs = {
pullRequest: number
repoName: string
scanType: string | undefined
workspace?: string | undefined
}

export type FetchCreateOrgFullScanOptions = {
Expand All @@ -43,6 +44,7 @@ export async function fetchCreateOrgFullScan(
pullRequest,
repoName,
scanType,
workspace,
} = { __proto__: null, ...config } as FetchCreateOrgFullScanConfigs

const {
Expand Down Expand Up @@ -82,6 +84,7 @@ export async function fetchCreateOrgFullScan(
...(pullRequest ? { pull_request: String(pullRequest) } : {}),
scan_type: scanType,
repo: repoName,
...(workspace ? { workspace } : {}),
set_as_pending_head: String(pendingHead),
tmp: String(tmp),
}),
Expand Down
9 changes: 8 additions & 1 deletion src/commands/scan/handle-create-new-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type HandleCreateNewScanConfig = {
reportLevel: REPORT_LEVEL
targets: string[]
tmp: boolean
workspace?: string | undefined
}

export async function handleCreateNewScan({
Expand All @@ -106,8 +107,12 @@ export async function handleCreateNewScan({
reportLevel,
targets,
tmp,
workspace,
}: HandleCreateNewScanConfig): Promise<void> {
debugFn('notice', `Creating new scan for ${orgSlug}/${repoName}`)
debugFn(
'notice',
`Creating new scan for ${orgSlug}/${workspace ? `${workspace}/` : ''}${repoName}`,
)
debugDir('inspect', {
autoManifest,
branchName,
Expand All @@ -121,6 +126,7 @@ export async function handleCreateNewScan({
reportLevel,
targets,
tmp,
workspace,
})

if (autoManifest) {
Expand Down Expand Up @@ -257,6 +263,7 @@ export async function handleCreateNewScan({
scanType: reach.runReachabilityAnalysis
? constants.SCAN_TYPE_SOCKET_TIER1
: constants.SCAN_TYPE_SOCKET,
workspace,
},
{
cwd,
Expand Down
17 changes: 17 additions & 0 deletions src/commands/scan/setup-scan-config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import constants, { SOCKET_JSON } from '../../constants.mts'
import {
detectDefaultBranch,
getRepoName,
getRepoOwner,
gitBranch,
} from '../../utils/git.mts'
import {
Expand Down Expand Up @@ -154,6 +155,22 @@ async function configureScan(
delete config.repo
}

const defaultWorkspace = await input({
message:
'(--workspace) The workspace in the Socket Organization that the repository is in to associate with the full scan.',
default: config.workspace || (await getRepoOwner(cwd)) || '',
required: false,
// validate: async string => bool
})
if (defaultWorkspace === undefined) {
return canceledByUser()
}
if (defaultWorkspace) {
config.workspace = defaultWorkspace
} else {
delete config.workspace
}

const defaultBranchName = await input({
message:
'(--branch) What branch name (slug) should be reported to Socket for this dir?',
Expand Down
1 change: 1 addition & 0 deletions src/utils/socket-json.mts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface SocketJson {
repo?: string | undefined
report?: boolean | undefined
branch?: string | undefined
workspace?: string | undefined
}
github?: {
all?: boolean | undefined
Expand Down