Monday, November 20, 2023

VSCode

 Notes on VSCode

JSON jump to opening closing bracket: ctrl - shift - \


JSONPath plugin

Note, shoudl be added to general json plugin

Can run jsonpath expressions in vscode. Alternative is to use https://jsonpath.com/ 

Once plugin is added ctrl-shift-p to get command pallette

Run Jsonpath: Extract json data with their paths

Some samples: (From nexus response)

$.components.length   = 33

$.components[0].displayName

$.components[0].licenseData

$.components[*].displayName

$.components[*].licenseData.effectiveLicenseThreats

$.components[*].licenseData.effectiveLicenseThreats.length

$.components[*].securityData.securityIssues

$.components[*].dependencyData

RESTClient

1/ Add variables for hosts / usernames passwords per env


Create folder .vscode/settings.json

e.g.  

Then chose and env from the bottem right

{
    "rest-client.environmentVariables": {
"dev" : {
            "url" : "htttp://urlDev",
            "user": "blah",
            "password":"myPass"
}
         "uat" : {
            "url" : "htttp://urlUat",
            "user": "blah2",
            "password":"myPass2"
}
}
}

2/ Capture results and reuse

e.g. These examples are of queries reports from NexusIQ

see getAppIdResp contains the request and response, and we use this to take the applciationId and use it in the next answer (Using jsonPath). Note be careful to spot arrays.

### Get application Id by name
@name getAppIdResp
GET {{url}}/api/v2/applications?publicId=My Project
Authorization: Basic {{user}} {{token}}

### Get individual reports
@name getReports
GET {{url}}/api/v2/reports/applications/{{getAppIdResp.response.body.$.applications[0].id}}
Authorization: Basic {{user}} {{token}}

### Using reportDataUrl from previous result we get the link to the raw data
@name getReport
GET {{url}}/{{getReports.response.body.$[0].reportDataUrl}}
Authorization: Basic {{user}} {{token}}


### Using reportDataUrl from previous result we get the link to the raw data
@name report
GET {{url}}/api/v2/applications/CAASBUILD-nexus-pipeline/reports/b38675be326741678d907d3d35dac573/raw
Authorization: Basic {{user}} {{token}}


### Using reportDataUrl from change context to policy to get policy violations
GET {{url}}/api/v2/applications/CAASBUILD-nexus-pipeline/reports/b38675be326741678d907d3d35dac573/policy
Authorization: Basic {{user}} {{token}}


Nice!

No comments: