Skip to content

Commit

Permalink
chore: provide Red Hat catalog link as image analysis recommendation
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Jul 24, 2024
1 parent 48bb794 commit 4e9bb13
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
7 changes: 6 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138036,6 +138036,8 @@ const UTM_SOURCE = 'github-actions';
const SARIF_SCHEMA_URL = 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json';
// Version of the SARIF schema.
const SARIF_SCHEMA_VERSION = '2.1.0';
// Red Hat certified container image catalog
const REDHAT_CATALOG = 'https://catalog.redhat.com/software/containers/search';
// Supported manifests and files
const GO_MOD = 'go.mod';
const POM_XML = 'pom.xml';
Expand Down Expand Up @@ -141243,6 +141245,7 @@ function fetchRecomendationRules(recommendation) {




/**
* Converts RHDA dependency data into SARIF results and rules.
* @param rhdaDependency - The RHDA dependency data to convert.
Expand Down Expand Up @@ -141287,7 +141290,9 @@ function rhdaToResult(rhdaDependency, manifestFilePath, startLine, refHasIssues)
}
}
else if (!refHasIssues && rhdaDependency.recommendationRef) {
const textMessage = `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;
const textMessage = rhdaDependency.imageRef
? `Switch to [Red Hat UBI](${REDHAT_CATALOG}) for enhanced security and enterprise-grade stability`
: `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;
const result = fetchResult(rhdaDependency.recommendationRef, textMessage, manifestFilePath, startLine);
const rule = fetchRecomendationRules(rhdaDependency.recommendationRef);
rules.push(rule);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const SARIF_SCHEMA_URL =
// Version of the SARIF schema.
export const SARIF_SCHEMA_VERSION = '2.1.0';

// Red Hat certified container image catalog
export const REDHAT_CATALOG =
'https://catalog.redhat.com/software/containers/search';

// Supported manifests and files
const GO_MOD = 'go.mod';
const POM_XML = 'pom.xml';
Expand Down
5 changes: 4 additions & 1 deletion src/sarif/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
resolveDependencyFromReference,
resolveVersionFromReference,
} from './convert.js';
import { REDHAT_CATALOG } from '../constants.js';

/**
* Converts RHDA dependency data into SARIF results and rules.
Expand Down Expand Up @@ -75,7 +76,9 @@ export function rhdaToResult(
});
}
} else if (!refHasIssues && rhdaDependency.recommendationRef) {
const textMessage = `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;
const textMessage = rhdaDependency.imageRef
? `Switch to [Red Hat UBI](${REDHAT_CATALOG}) for enhanced security and enterprise-grade stability`
: `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;

const result = fetchResult(
rhdaDependency.recommendationRef,
Expand Down
55 changes: 54 additions & 1 deletion test/sarif/results.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';

import { rhdaToResult } from '../../src/sarif/results';
import * as types from '../../src/sarif/types';
import { resolveVersionFromReference } from '../../src/sarif/convert.js';
import { resolveVersionFromReference } from '../../src/sarif/convert';
import { REDHAT_CATALOG } from '../../src/constants';

vi.mock('../../src/sarif/rules', () => ({
fetchIssueRules: vi.fn().mockImplementation(() => 'example rule'),
Expand Down Expand Up @@ -274,4 +275,56 @@ describe('rhdaToResult', () => {

expect(results).toStrictEqual(expectedResult);
});

it('should return correct SARIF result for a image without issues and with recommendation', () => {
const refHasIssues = false;

const dependencyData: types.IDependencyData = {
imageRef: 'image:tag',
depRef: 'pkg:ecosystem/groupId/artifact@version',
depGroup: 'groupId',
depName: 'groupId/artifact',
depVersion: 'version',
ecosystem: 'ecosystem',
providerId: 'providerId',
sourceId: 'sourceId',
issues: null,
transitives: null,
recommendationRef:
'pkg:ecosystem/groupId/artifact@recommendedversion',
};

const expectedResult = [
[
{
ruleId: dependencyData.recommendationRef,
message: {
text: `Switch to [Red Hat UBI](${REDHAT_CATALOG}) for enhanced security and enterprise-grade stability`,
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: manifestFilePath,
},
region: {
startLine: startLine,
},
},
},
],
},
],
['example rule'],
];

const results = rhdaToResult(
dependencyData,
manifestFilePath,
startLine,
refHasIssues,
);

expect(results).toStrictEqual(expectedResult);
});
});
2 changes: 1 addition & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from 'fs';
import * as zlib from 'zlib';

import * as utils from '../src/utils';
import { Inputs } from '../src/generated/inputs-outputs.js';
import { Inputs } from '../src/generated/inputs-outputs';

vi.mock('@actions/core', () => ({
warning: vi.fn(),
Expand Down

0 comments on commit 4e9bb13

Please sign in to comment.