Skip to content

Commit 4e9bb13

Browse files
committed
chore: provide Red Hat catalog link as image analysis recommendation
Signed-off-by: Ilona Shishov <[email protected]>
1 parent 48bb794 commit 4e9bb13

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

dist/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138036,6 +138036,8 @@ const UTM_SOURCE = 'github-actions';
138036138036
const SARIF_SCHEMA_URL = 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json';
138037138037
// Version of the SARIF schema.
138038138038
const SARIF_SCHEMA_VERSION = '2.1.0';
138039+
// Red Hat certified container image catalog
138040+
const REDHAT_CATALOG = 'https://catalog.redhat.com/software/containers/search';
138039138041
// Supported manifests and files
138040138042
const GO_MOD = 'go.mod';
138041138043
const POM_XML = 'pom.xml';
@@ -141243,6 +141245,7 @@ function fetchRecomendationRules(recommendation) {
141243141245

141244141246

141245141247

141248+
141246141249
/**
141247141250
* Converts RHDA dependency data into SARIF results and rules.
141248141251
* @param rhdaDependency - The RHDA dependency data to convert.
@@ -141287,7 +141290,9 @@ function rhdaToResult(rhdaDependency, manifestFilePath, startLine, refHasIssues)
141287141290
}
141288141291
}
141289141292
else if (!refHasIssues && rhdaDependency.recommendationRef) {
141290-
const textMessage = `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;
141293+
const textMessage = rhdaDependency.imageRef
141294+
? `Switch to [Red Hat UBI](${REDHAT_CATALOG}) for enhanced security and enterprise-grade stability`
141295+
: `Recommended Red Hat verified version: ${rhdaDependency.recommendationRef}.`;
141291141296
const result = fetchResult(rhdaDependency.recommendationRef, textMessage, manifestFilePath, startLine);
141292141297
const rule = fetchRecomendationRules(rhdaDependency.recommendationRef);
141293141298
rules.push(rule);

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export const SARIF_SCHEMA_URL =
88
// Version of the SARIF schema.
99
export const SARIF_SCHEMA_VERSION = '2.1.0';
1010

11+
// Red Hat certified container image catalog
12+
export const REDHAT_CATALOG =
13+
'https://catalog.redhat.com/software/containers/search';
14+
1115
// Supported manifests and files
1216
const GO_MOD = 'go.mod';
1317
const POM_XML = 'pom.xml';

src/sarif/results.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
resolveDependencyFromReference,
88
resolveVersionFromReference,
99
} from './convert.js';
10+
import { REDHAT_CATALOG } from '../constants.js';
1011

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

8083
const result = fetchResult(
8184
rhdaDependency.recommendationRef,

test/sarif/results.test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
22

33
import { rhdaToResult } from '../../src/sarif/results';
44
import * as types from '../../src/sarif/types';
5-
import { resolveVersionFromReference } from '../../src/sarif/convert.js';
5+
import { resolveVersionFromReference } from '../../src/sarif/convert';
6+
import { REDHAT_CATALOG } from '../../src/constants';
67

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

275276
expect(results).toStrictEqual(expectedResult);
276277
});
278+
279+
it('should return correct SARIF result for a image without issues and with recommendation', () => {
280+
const refHasIssues = false;
281+
282+
const dependencyData: types.IDependencyData = {
283+
imageRef: 'image:tag',
284+
depRef: 'pkg:ecosystem/groupId/artifact@version',
285+
depGroup: 'groupId',
286+
depName: 'groupId/artifact',
287+
depVersion: 'version',
288+
ecosystem: 'ecosystem',
289+
providerId: 'providerId',
290+
sourceId: 'sourceId',
291+
issues: null,
292+
transitives: null,
293+
recommendationRef:
294+
'pkg:ecosystem/groupId/artifact@recommendedversion',
295+
};
296+
297+
const expectedResult = [
298+
[
299+
{
300+
ruleId: dependencyData.recommendationRef,
301+
message: {
302+
text: `Switch to [Red Hat UBI](${REDHAT_CATALOG}) for enhanced security and enterprise-grade stability`,
303+
},
304+
locations: [
305+
{
306+
physicalLocation: {
307+
artifactLocation: {
308+
uri: manifestFilePath,
309+
},
310+
region: {
311+
startLine: startLine,
312+
},
313+
},
314+
},
315+
],
316+
},
317+
],
318+
['example rule'],
319+
];
320+
321+
const results = rhdaToResult(
322+
dependencyData,
323+
manifestFilePath,
324+
startLine,
325+
refHasIssues,
326+
);
327+
328+
expect(results).toStrictEqual(expectedResult);
329+
});
277330
});

test/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fs from 'fs';
55
import * as zlib from 'zlib';
66

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

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

0 commit comments

Comments
 (0)