Skip to content
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

fix: pip show parsing is incorrect #63

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const rhdaOperationTypeHeader = "rhda-operation-type"
async function requestStack(provider, manifest, url, html = false, opts = {}) {
let provided = provider.provideStack(manifest, opts) // throws error if content providing failed
opts[rhdaOperationTypeHeader.toUpperCase().replaceAll("-","_")] = "stack-analysis"
let startTime = new Date()
let EndTime
if (process.env["EXHORT_DEBUG"] === "true") {
console.log("Starting time of sending stack analysis request to exhort server= " + startTime)
}
let resp = await fetch(`${url}/api/v3/analysis`, {
method: 'POST',
headers: {
Expand All @@ -28,6 +33,12 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
},
body: provided.content
})
if (process.env["EXHORT_DEBUG"] === "true") {
EndTime = new Date()
console.log("Ending time of sending stack analysis request to exhort server= " + EndTime)
let time = (EndTime - startTime) / 1000
console.log("Total Time in seconds: " + time)
}
return html ? resp.text() : resp.json()
}

Expand All @@ -42,6 +53,9 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
async function requestComponent(provider, data, url, opts = {}) {
let provided = provider.provideComponent(data, opts) // throws error if content providing failed
opts[rhdaOperationTypeHeader.toUpperCase().replaceAll("-","_")] = "component-analysis"
if (process.env["EXHORT_DEBUG"] === "true") {
console.log("Starting time of sending component analysis request to exhort server= " + new Date())
}
let resp = await fetch(`${url}/api/v3/analysis`, {
method: 'POST',
headers: {
Expand All @@ -51,6 +65,9 @@ async function requestComponent(provider, data, url, opts = {}) {
},
body: provided.content
})
if (process.env["EXHORT_DEBUG"] === "true") {
console.log("Ending time of sending component analysis request to exhort server= " + new Date())
}
return resp.json()
}

Expand Down
14 changes: 13 additions & 1 deletion src/providers/python_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export default class Python_controller {
*/
getDependencies(includeTransitive)
{
let startingTime
let endingTime
if (process.env["EXHORT_DEBUG"] === "true") {
startingTime = new Date()
console.log("Starting time to get requirements.txt dependency tree = " + startingTime)
}
if(!this.realEnvironment) {
execSync(`${this.pathToPipBin} install -r ${this.pathToRequirements}`, err =>{
if (err) {
Expand All @@ -83,6 +89,12 @@ export default class Python_controller {
}
let dependencies = this.#getDependenciesImpl(includeTransitive)
this.#cleanEnvironment()
if (process.env["EXHORT_DEBUG"] === "true") {
endingTime = new Date()
console.log("Ending time to get requirements.txt dependency tree = " + endingTime)
let time = ( endingTime - startingTime ) / 1000
console.log("total time to get requirements.txt dependency tree = " + time)
}
return dependencies
}
/**
Expand Down Expand Up @@ -113,7 +125,7 @@ export default class Python_controller {
throw new Error('fail invoking pip show to fetch all installed dependencies metadata --> ' + err.message)
}
}).toString();
let allPipShowDeps = pipShowOutput.split("---");
let allPipShowDeps = pipShowOutput.split( EOL +"---" + EOL);
let linesOfRequirements = fs.readFileSync(this.pathToRequirements).toString().split(EOL).filter( (line) => !line.startsWith("#")).map(line => line.trim())
let CachedEnvironmentDeps = {}
allPipShowDeps.forEach( (record) => {
Expand Down
12 changes: 12 additions & 0 deletions src/sbom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import CycloneDxSbom from "./cyclone_dx_sbom.js";

export default class Sbom {
sbomModel
#startTime
#endTime
constructor() {
if (process.env["EXHORT_DEBUG"] === "true") {
this.#startTime = new Date()
console.log("Starting time to create sbom = " + this.#startTime)
}
this.sbomModel = new CycloneDxSbom()
}

Expand Down Expand Up @@ -51,6 +57,12 @@ export default class Sbom {
* @return String sbom json in a string format
*/
getAsJsonString(){
if (process.env["EXHORT_DEBUG"] === "true") {
this.#endTime = new Date()
console.log("Ending time to create sbom = " + this.#endTime)
let time = (this.#endTime - this.#startTime) / 1000
console.log("Total time in seconds to create sbom = " + time)
}
return this.sbomModel.getAsJsonString()
}

Expand Down
27 changes: 27 additions & 0 deletions test/it/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,30 @@ suite('Integration Tests', () => {

});
});

// suite('Developer Test End to End', () => {
// // let opts = {
// // EXHORT_DEV_MODE: "true",
// // EXHORT_SNYK_TOKEN: "ee64316c-a4ba-4ca0-a785-18cb05ed3f25"
// //
// // }
//
// test(`Stack Analysis json`, async () => {
// // process.env["EXHORT_DEBUG"]= "true"
// // process.env["EXHORT_DEV_MODE"]= "false"
// // process.env["EXHORT_GO_PATH"]= "/home/zgrinber/test-go/go/bin/go"
// // process.env["RHDA_TOKEN"] = "34JKLDS-4234809-66666666666"
// // process.env["RHDA_SOURCE"] = "Zvika Client"
// // let result = await index.stackAnalysis("/tmp/rajan-0410/go.mod", false, opts);
//
//
// let pomPath = `/tmp/231023/requirements.txt`
// let providedDataForStack = await index.stackAnalysis(pomPath)
// console.log(JSON.stringify(providedDataForStack.summary,null , 4))
// expect(providedDataForStack.summary.dependencies.scanned).greaterThan(0)
// }).timeout(15000);
//
//
//
//
// });
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@
"type": "library",
"bom-ref": "pkg:npm/[email protected]"
},
{
"name": "jsdom",
"version": "19.0.0",
"purl": "pkg:npm/[email protected]",
"type": "library",
"bom-ref": "pkg:npm/[email protected]"
},
{
"name": "jsdom",
"version": "19.0.0",
"purl": "pkg:npm/[email protected]",
"type": "library",
"bom-ref": "pkg:npm/[email protected]"
},
{
"name": "mongoose",
"version": "5.13.20",
"purl": "pkg:npm/[email protected].20",
"version": "5.13.21",
"purl": "pkg:npm/[email protected].21",
"type": "library",
"bom-ref": "pkg:npm/[email protected].20"
"bom-ref": "pkg:npm/[email protected].21"
},
{
"name": "nodemon",
Expand All @@ -96,7 +96,7 @@
"pkg:npm/[email protected]",
"pkg:npm/[email protected]",
"pkg:npm/[email protected]",
"pkg:npm/[email protected].20",
"pkg:npm/[email protected].21",
"pkg:npm/[email protected]"
]
},
Expand Down Expand Up @@ -129,7 +129,7 @@
"dependsOn": []
},
{
"ref": "pkg:npm/[email protected].20",
"ref": "pkg:npm/[email protected].21",
"dependsOn": []
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
},
{
"name": "mongoose",
"version": "5.13.20",
"purl": "pkg:npm/[email protected].20",
"version": "5.13.21",
"purl": "pkg:npm/[email protected].21",
"type": "library",
"bom-ref": "pkg:npm/[email protected].20"
"bom-ref": "pkg:npm/[email protected].21"
},
{
"name": "nodemon",
Expand All @@ -96,7 +96,7 @@
"pkg:npm/[email protected]",
"pkg:npm/[email protected]",
"pkg:npm/[email protected]",
"pkg:npm/[email protected].20",
"pkg:npm/[email protected].21",
"pkg:npm/[email protected]"
]
},
Expand Down Expand Up @@ -129,7 +129,7 @@
"dependsOn": []
},
{
"ref": "pkg:npm/[email protected].20",
"ref": "pkg:npm/[email protected].21",
"dependsOn": []
},
{
Expand Down