-
Notifications
You must be signed in to change notification settings - Fork 9
add new flag for security scanning #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Shaharshaki2
merged 11 commits into
master
from
feat/shaharsh/monday-code-security-scanning
Dec 7, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
779832f
add new flag for security scanning
Shaharshaki2 6f5f4de
Merge branch 'master' into feat/shaharsh/monday-code-security-scanning
Shaharshaki2 b056461
remove comment
Shaharshaki2 b5a9d4f
fix comments
Shaharshaki2 f140260
[beta]
Shaharshaki2 0be44fd
add new command for code:report to return the security scanning for s…
Shaharshaki2 e40be30
bump version for beta [beta]
Shaharshaki2 f83ebd4
fix comemnts
Shaharshaki2 330d26e
fix code:status when appRelease has null region, its happen when for …
Shaharshaki2 950b97b
[beta]
Shaharshaki2 fa4aebf
bump version
Shaharshaki2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { Flags } from '@oclif/core'; | ||
| import chalk from 'chalk'; | ||
| import { StatusCodes } from 'http-status-codes'; | ||
|
|
||
| import { AuthenticatedCommand } from 'commands-base/authenticated-command'; | ||
| import { APP_VERSION_ID_TO_ENTER, VAR_UNKNOWN } from 'consts/messages'; | ||
| import { DynamicChoicesService } from 'services/dynamic-choices-service'; | ||
| import { getDeploymentSecurityScan } from 'services/push-service'; | ||
| import { HttpError } from 'types/errors'; | ||
| import { SecurityScanResponse, SecurityScanResultType } from 'types/services/push-service'; | ||
| import logger from 'utils/logger'; | ||
| import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region'; | ||
|
|
||
| const DEBUG_TAG = 'code_report'; | ||
|
|
||
| const printSecurityScanSummary = (securityScanResults: SecurityScanResultType) => { | ||
| const { summary, timestamp, version } = securityScanResults; | ||
|
|
||
| logger.log(`\nSecurity Scan Report (v${version})`); | ||
| logger.log(`Scan timestamp: ${timestamp}\n`); | ||
|
|
||
| const errors = chalk.red(`✖ ${summary.error} errors`); | ||
| const warnings = chalk.yellow(`▲ ${summary.warning} warnings`); | ||
| const notes = chalk.cyan(`ℹ ${summary.note} info`); | ||
|
|
||
| logger.log(`Total findings: ${summary.total}`); | ||
| logger.log(`${errors}\t${warnings}\t${notes}\n`); | ||
| }; | ||
|
|
||
| const writeResultsToFile = (securityScanResults: SecurityScanResultType, appVersionId: number): string => { | ||
| const timestamp = new Date().toISOString().split('.')[0].replaceAll(':', '-'); | ||
| const fileName = `security-scan-${appVersionId}-${timestamp}.json`; | ||
| const filePath = path.join(process.cwd(), fileName); | ||
|
|
||
| fs.writeFileSync(filePath, JSON.stringify(securityScanResults, null, 2), 'utf8'); | ||
|
|
||
| return filePath; | ||
| }; | ||
|
|
||
| export default class Report extends AuthenticatedCommand { | ||
| static description = 'Get security scan report for a monday-code deployment.'; | ||
|
|
||
| static examples = [ | ||
| '<%= config.bin %> <%= command.id %> -i APP_VERSION_ID', | ||
| '<%= config.bin %> <%= command.id %> -i APP_VERSION_ID -o', | ||
| ]; | ||
|
|
||
| static flags = Report.serializeFlags( | ||
| addRegionToFlags({ | ||
| appVersionId: Flags.integer({ | ||
| char: 'i', | ||
| aliases: ['v'], | ||
| description: APP_VERSION_ID_TO_ENTER, | ||
| }), | ||
| output: Flags.boolean({ | ||
| char: 'o', | ||
| description: 'Save the full report to a JSON file', | ||
| default: false, | ||
| }), | ||
| }), | ||
| ); | ||
|
|
||
| public async run(): Promise<void> { | ||
| const { flags } = await this.parse(Report); | ||
| const { region: strRegion, output } = flags; | ||
| const region = getRegionFromString(strRegion); | ||
| let appVersionId = flags.appVersionId; | ||
|
|
||
| try { | ||
| if (!appVersionId) { | ||
| const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(true, true); | ||
| appVersionId = appAndAppVersion.appVersionId; | ||
| } | ||
|
|
||
| const selectedRegion = await chooseRegionIfNeeded(region, { appVersionId }); | ||
|
|
||
| this.preparePrintCommand(this, { appVersionId }); | ||
|
|
||
| logger.debug(`Fetching security scan results for appVersionId: ${appVersionId}`, DEBUG_TAG); | ||
|
|
||
| const response: SecurityScanResponse = await getDeploymentSecurityScan(appVersionId, selectedRegion); | ||
|
|
||
| if (!response.securityScanResults) { | ||
| logger.log('\nNo security scan results available for this deployment.'); | ||
| logger.log('Security scans are performed when deploying with the --security-scan (-s) flag.'); | ||
| return; | ||
| } | ||
|
|
||
| printSecurityScanSummary(response.securityScanResults); | ||
|
|
||
| if (output) { | ||
| const filePath = writeResultsToFile(response.securityScanResults, appVersionId); | ||
| logger.log(`Full report saved to: ${filePath}`); | ||
| } else { | ||
| logger.log('Use the -o flag to save the full report to a JSON file.'); | ||
| } | ||
| } catch (error: unknown) { | ||
| logger.debug({ res: error }, DEBUG_TAG); | ||
| if (error instanceof HttpError) { | ||
| if (error.code === StatusCodes.NOT_FOUND) { | ||
| logger.error(`No deployment found for provided app version id - "${appVersionId || VAR_UNKNOWN}"`); | ||
| } else if (error.code === 400) { | ||
| logger.error(error.message); | ||
| } else { | ||
| logger.error(`Failed to fetch security scan report: ${error.message}`); | ||
| } | ||
| } else { | ||
| logger.error( | ||
| `An unknown error happened while fetching security scan report for app version id - "${ | ||
| appVersionId || VAR_UNKNOWN | ||
| }"`, | ||
| ); | ||
| } | ||
|
|
||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.