Skip to content

Commit

Permalink
Merge pull request #5702 from snyk/fix/IAC-3180/fix-iac-v2-link-to-re…
Browse files Browse the repository at this point in the history
…sults

fix (iac): update project page link for iac v2 --report
  • Loading branch information
sandor-trombitas authored Feb 7, 2025
2 parents 06bb8dd + 1c9b3b3 commit c1cf770
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
25 changes: 22 additions & 3 deletions src/cli/commands/test/iac/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import {
shareResultsTip,
formatTestData,
} from '../../../../lib/formatters/iac-output/text';
import { formatShareResultsOutputV2 } from '../../../../lib/formatters/iac-output/text/share-results';
import {
formatShareResultsOutputIacV2,
formatShareResultsOutputIacPlus,
shareResultsError,
} from '../../../../lib/formatters/iac-output/text/share-results';

const SEPARATOR = '\n-------------------------------------------------------\n';

Expand Down Expand Up @@ -270,7 +274,7 @@ export function buildShareResultsSummary({
return response;
}

export function buildShareResultsSummaryV2({
export function buildShareResultsSummaryIacPlus({
orgName,
projectName,
options,
Expand All @@ -286,7 +290,7 @@ export function buildShareResultsSummaryV2({
let response = '';

response +=
SEPARATOR + EOL + formatShareResultsOutputV2(orgName, projectName);
SEPARATOR + EOL + formatShareResultsOutputIacPlus(orgName, projectName);

if (
shouldPrintShareCustomRulesDisclaimer(
Expand All @@ -301,6 +305,21 @@ export function buildShareResultsSummaryV2({
return response;
}

export function buildShareResultsSummaryIacV2({
orgName,
projectPublicId,
}: {
orgName: string;
projectPublicId: string | undefined;
}): string {
let response = SEPARATOR + EOL;
response += projectPublicId
? formatShareResultsOutputIacV2(orgName, projectPublicId)
: shareResultsError;

return response;
}

export function shouldPrintShareResultsTip(options: IaCTestFlags): boolean {
return shouldLogUserMessages(options) && !options.report;
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function test(
scanResult,
testSpinner,
options,
iacNewEngine,
});
} finally {
testSpinner?.stop();
Expand Down
32 changes: 31 additions & 1 deletion src/lib/formatters/iac-output/text/share-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function formatShareResultsOutput(orgName: string, projectName: string) {
);
}

export function formatShareResultsOutputV2(
export function formatShareResultsOutputIacPlus(
orgName: string,
projectName: string,
) {
Expand All @@ -37,6 +37,25 @@ export function formatShareResultsOutputV2(
);
}

export function formatShareResultsOutputIacV2(
orgName: string,
projectPublicId: string | undefined,
) {
let projectLink = ''; // empty link if projectId is undefined, will follow up on this after product decision
if (projectPublicId) {
projectLink = `${config.ROOT}/org/${orgName}/project/${encodeURIComponent(projectPublicId)}`;
}

return (
colors.title('Report Complete') +
EOL +
EOL +
contentPadding +
'Your test results are available at: ' +
colors.title(projectLink)
);
}

export const shareResultsTip =
colors.title('Tip') +
EOL +
Expand All @@ -50,3 +69,14 @@ export const shareCustomRulesDisclaimer =
colors.suggestion(
'Please note that your custom rules will not be sent to the platform, and will not be available on the projects page.',
);

export const shareResultsError =
colors.title('Failed to create and display results in Snyk UI') +
EOL +
EOL +
contentPadding +
'There was a problem creating the project and displaying the test results in Snyk UI.' +
EOL +
contentPadding +
colors.title('Need help?') +
' Check the Snyk CLI for IaC doc https://docs.snyk.io/snyk-cli/scan-and-maintain-projects-using-the-cli/snyk-cli-for-iac';
10 changes: 5 additions & 5 deletions src/lib/iac/test/v2/local-cache/policy-engine/constants/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as os from 'os';

const policyEngineChecksums = `
aeb08fbecd094cdec741237f0f9f187492fa4e446f41e3dc7135426fdd721382 snyk-iac-test_0.57.4_Darwin_x86_64
b9607371e0372b382c6e92fdbe1624364baf3b2d4856312c32567de4ed0bdc72 snyk-iac-test_0.57.4_Darwin_arm64
c4447339c352c646bfa79bf12aef108e8c9f0263ac2440fe7e5edafa46ba433d snyk-iac-test_0.57.4_Linux_arm64
fa327f0909b43b59bb76dfd54f99603859a2606663390aad16abe484f6ef8765 snyk-iac-test_0.57.4_Windows_x86_64.exe
fe0604529047aa5fcd3edffe5f1b9392bfc255f94885d745266aca768f521907 snyk-iac-test_0.57.4_Linux_x86_64
2bece98c6602298aab72fe8be803cd48974b63766c2a53491761d0855dccef0d snyk-iac-test_0.57.5_Darwin_x86_64
3703de51908fb24ea11358c1f97643937b502a43afac5131d45c11a321138687 snyk-iac-test_0.57.5_Windows_x86_64.exe
458e9debc734006ce6bb4ae530111ad0548a3d85ca43f8b4b5f0b17994e75efd snyk-iac-test_0.57.5_Linux_arm64
c624ddaa85851ed8c9fb54895c8834d0f04221066feb7d08afd2413ae2cf97cc snyk-iac-test_0.57.5_Darwin_arm64
d15e89f5933933b13693f5ee42b27799825a1abc16e0bdbd5a2c40c5b5af8f9b snyk-iac-test_0.57.5_Linux_x86_64
`;

export const policyEngineVersion = getPolicyEngineVersion();
Expand Down
43 changes: 31 additions & 12 deletions src/lib/iac/test/v2/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import stripAnsi = require('strip-ansi');
import * as path from 'path';
import { getErrorStringCode } from '../../../../cli/commands/test/iac/local-execution/error-utils';
import {
buildShareResultsSummaryV2,
buildShareResultsSummaryIacV2,
buildShareResultsSummaryIacPlus,
shouldPrintShareResultsTip,
} from '../../../../cli/commands/test/iac/output';
import {
Expand All @@ -40,10 +41,12 @@ export function buildOutput({
scanResult,
testSpinner,
options,
iacNewEngine,
}: {
scanResult: TestOutput;
testSpinner?: Ora;
options: any;
iacNewEngine?: boolean;
}): TestCommandResult {
if (scanResult.results) {
testSpinner?.succeed(spinnerSuccessMessage);
Expand All @@ -54,6 +57,7 @@ export function buildOutput({
const { responseData, jsonData, sarifData } = buildTestCommandResultData({
scanResult,
options,
iacNewEngine,
});

if (options.json || options.sarif) {
Expand All @@ -74,9 +78,11 @@ export function buildOutput({
function buildTestCommandResultData({
scanResult,
options,
iacNewEngine,
}: {
scanResult: TestOutput;
options: any;
iacNewEngine?: boolean;
}) {
const projectName =
scanResult.results?.metadata?.projectName ?? path.basename(process.cwd());
Expand Down Expand Up @@ -108,6 +114,7 @@ function buildTestCommandResultData({
scanResult,
projectName,
options,
iacNewEngine,
});
}

Expand All @@ -129,10 +136,12 @@ function buildTextOutput({
scanResult,
projectName,
options,
iacNewEngine,
}: {
scanResult: TestOutput;
projectName: string;
options: IaCTestFlags;
iacNewEngine?: boolean;
}): string {
let response = '';

Expand Down Expand Up @@ -177,24 +186,34 @@ function buildTextOutput({
response += EOL;

if (options.report) {
response += buildShareResultsSummaryV2({
orgName: scanResult.settings.org,
projectName,
options,
isIacCustomRulesEntitlementEnabled: false, // TODO: update when we add custom rules support
isIacShareCliResultsCustomRulesSupported: false, // TODO: update when we add custom rules support
});
if (iacNewEngine) {
response += buildShareResultsSummaryIacV2({
orgName: scanResult.settings.org,
projectPublicId: scanResult.results?.metadata.projectPublicId,
});
} else {
response += buildShareResultsSummaryIacPlus({
orgName: scanResult.settings.org,
projectName,
options,
isIacCustomRulesEntitlementEnabled: false, // TODO: update when we add custom rules support
isIacShareCliResultsCustomRulesSupported: false, // TODO: update when we add custom rules support
});
}

response += EOL;
}

if (shouldPrintShareResultsTip(options)) {
response += SEPARATOR + EOL + shareResultsTip + EOL;
}

response += EOL;
response += colors.title('Info') + EOL;
response += EOL;
response += wrapWithPadding(infoMessage(scanResult), 80) + EOL;
if (!iacNewEngine) {
response += EOL;
response += colors.title('Info') + EOL;
response += EOL;
response += wrapWithPadding(infoMessage(scanResult), 80) + EOL;
}

return response;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/iac/test/v2/scan/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Results {

export interface Metadata {
projectName: string;
projectPublicId: string;
ignoredCount: number;
}

Expand Down

0 comments on commit c1cf770

Please sign in to comment.