-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from snyk/feat/MYC-41-return-content-sets-fro…
…m-plugin feat: Return rpm repositories with the scanResult
- Loading branch information
Showing
17 changed files
with
2,005 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,28 @@ | ||
import { ExtractAction, ExtractedLayers } from "../../extractor/types"; | ||
import { streamToJson } from "../../stream-utils"; | ||
|
||
export const getRedHatRepositoriesContentAction: ExtractAction = { | ||
actionName: "redhat-content-manifests", | ||
filePathMatches: isRedHatContentManifest, | ||
callback: streamToJson, | ||
}; | ||
|
||
export function getRedHatRepositoriesFromExtractedLayers( | ||
extractedLayers: ExtractedLayers, | ||
): string[] { | ||
const repositories: string[] = []; | ||
for (const filePath in extractedLayers) { | ||
if (isRedHatContentManifest(filePath)) { | ||
const contentManifest = extractedLayers[filePath][ | ||
"redhat-content-manifests" | ||
] as any; | ||
repositories.push(...contentManifest?.content_sets); | ||
} | ||
} | ||
|
||
return [...new Set(repositories)]; | ||
} | ||
|
||
function isRedHatContentManifest(filePath: string): boolean { | ||
return filePath.startsWith("/root/buildinfo/content_manifests/"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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
17 changes: 17 additions & 0 deletions
17
test/fixtures/extracted-layers/rhel7-with-content-manifests.json
This file contains 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,17 @@ | ||
{ | ||
"/root/buildinfo/content_manifests/jenkins-agent-maven-35-rhel7-container-v3.11.346-2.json": { | ||
"redhat-content-manifests": { | ||
"metadata": { | ||
"icm_version": 1, | ||
"icm_spec": "https://raw.githubusercontent.com/containerbuildsystem/atomic-reactor/master/atomic_reactor/schemas/content_manifest.json", | ||
"image_layer_index": 6 | ||
}, | ||
"content_sets": [ | ||
"rhel-7-server-ose-3.11-rpms", | ||
"rhel-server-rhscl-7-rpms", | ||
"rhel-7-server-rpms" | ||
], | ||
"image_contents": [] | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
test/fixtures/extracted-layers/ubi8-with-content-manifests.json
This file contains 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,37 @@ | ||
{ | ||
"/root/buildinfo/content_manifests/s2i-core-container-1-155.json": { | ||
"redhat-content-manifests": { | ||
"content_sets": [ | ||
"rhel-8-for-x86_64-baseos-rpms", | ||
"rhel-8-for-x86_64-appstream-rpms" | ||
], | ||
"metadata": { | ||
"image_layer_index": 2 | ||
} | ||
} | ||
}, | ||
"/root/buildinfo/content_manifests/ubi8-container-8.2-337": { | ||
"redhat-content-manifests": { | ||
"content_sets": [ | ||
"rhel-8-for-x86_64-baseos-beta-rpms", | ||
"rhel-8-for-x86_64-appstream-beta-rpms", | ||
"rhel-8-for-x86_64-baseos-htb-rpms", | ||
"rhel-8-for-x86_64-appstream-htb-rpms" | ||
], | ||
"metadata": { | ||
"image_layer_index": 1 | ||
} | ||
} | ||
}, | ||
"/root/buildinfo/content_manifests/nodejs-10-container-1-99": { | ||
"redhat-content-manifests": { | ||
"content_sets": [ | ||
"rhel-8-for-x86_64-baseos-rpms", | ||
"rhel-8-for-x86_64-appstream-rpms" | ||
], | ||
"metadata": { | ||
"image_layer_index": 4 | ||
} | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
test/fixtures/extracted-layers/with-content-manifests.json
This file was deleted.
Oops, something went wrong.
This file contains 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 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,37 @@ | ||
import { getRedHatRepositoriesFromExtractedLayers } from "../../../../lib/inputs/redHat/static"; | ||
import { getObjFromFixture } from "../../../util"; | ||
|
||
describe("getRedHatRepositoriesFromExtractedLayers", () => { | ||
it("returns unique set of repositories from rhel7 image", () => { | ||
const extractedLayers = getObjFromFixture( | ||
"extracted-layers/rhel7-with-content-manifests.json", | ||
); | ||
|
||
const repositories = | ||
getRedHatRepositoriesFromExtractedLayers(extractedLayers); | ||
|
||
expect(repositories).toMatchObject([ | ||
"rhel-7-server-ose-3.11-rpms", | ||
"rhel-server-rhscl-7-rpms", | ||
"rhel-7-server-rpms", | ||
]); | ||
}); | ||
|
||
it("returns unique set of repositories from ubi8 image", () => { | ||
const extractedLayers = getObjFromFixture( | ||
"extracted-layers/ubi8-with-content-manifests.json", | ||
); | ||
|
||
const repositories = | ||
getRedHatRepositoriesFromExtractedLayers(extractedLayers); | ||
|
||
expect(repositories).toMatchObject([ | ||
"rhel-8-for-x86_64-baseos-rpms", | ||
"rhel-8-for-x86_64-appstream-rpms", | ||
"rhel-8-for-x86_64-baseos-beta-rpms", | ||
"rhel-8-for-x86_64-appstream-beta-rpms", | ||
"rhel-8-for-x86_64-baseos-htb-rpms", | ||
"rhel-8-for-x86_64-appstream-htb-rpms", | ||
]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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.