Skip to content

Commit

Permalink
Add explicit accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Killough committed Mar 3, 2022
1 parent c6058f2 commit 0cba6cc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ class BlackduckApiService {
}
getComponentVulnerabilties(bearerToken, componentVersion) {
return __awaiter(this, void 0, void 0, function* () {
// Accept: application/vnd.blackducksoftware.vulnerability-4+json
return this.get(bearerToken, `${componentVersion._meta.href}/vulnerabilities`);
return this.get(bearerToken, `${componentVersion._meta.href}/vulnerabilities`, 'application/vnd.blackducksoftware.vulnerability-4+json');
});
}
getPolicies(bearerToken, limit = 10, enabled) {
Expand All @@ -123,11 +122,11 @@ class BlackduckApiService {
return this.get(bearerToken, `${this.blackduckUrl}${requestPath}&offset=${offset}&limit=${limit}`);
});
}
get(bearerToken, requestUrl) {
get(bearerToken, requestUrl, acceptHeader) {
return __awaiter(this, void 0, void 0, function* () {
const bearerTokenHandler = new Handlers_1.BearerCredentialHandler(bearerToken, true);
const blackduckRestClient = new RestClient_1.RestClient(application_constants_1.APPLICATION_NAME, this.blackduckUrl, [bearerTokenHandler]);
return blackduckRestClient.get(requestUrl);
return blackduckRestClient.get(requestUrl, { acceptHeader });
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/blackduck-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ export class BlackduckApiService {
}

async getComponentVulnerabilties(bearerToken: string, componentVersion: IComponentVersion): Promise<IRestResponse<IBlackduckItemArray<IComponentVulnerability>>> {
// Accept: application/vnd.blackducksoftware.vulnerability-4+json
return this.get(bearerToken, `${componentVersion._meta.href}/vulnerabilities`)
return this.get(bearerToken, `${componentVersion._meta.href}/vulnerabilities`, 'application/vnd.blackducksoftware.vulnerability-4+json')
}

async getPolicies(bearerToken: string, limit: number = 10, enabled?: boolean) {
Expand All @@ -166,11 +165,11 @@ export class BlackduckApiService {
return this.get(bearerToken, `${this.blackduckUrl}${requestPath}&offset=${offset}&limit=${limit}`)
}

async get<Type>(bearerToken: string, requestUrl: string): Promise<IRestResponse<Type>> {
async get<Type>(bearerToken: string, requestUrl: string, acceptHeader?: string): Promise<IRestResponse<Type>> {
const bearerTokenHandler = new BearerCredentialHandler(bearerToken, true)
const blackduckRestClient = new RestClient(APPLICATION_NAME, this.blackduckUrl, [bearerTokenHandler])

return blackduckRestClient.get(requestUrl)
return blackduckRestClient.get(requestUrl, { acceptHeader })
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/detect/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function createComponentVulnerabilityReports(policyViolatingVulnerabiliti
} else {
const violatingPolicyVulnerabilityNames = policyViolatingVulnerabilities.map(vulnerability => vulnerability.name)
vulnerabilityReport = componentVulnerabilities.map(vulnerability => {
const compVulnBaseScore = vulnerability.useCvss3 ? vulnerability.cvss3.baseScore : vulnerability.cvss2.baseScore;
const compVulnBaseScore = vulnerability.useCvss3 ? vulnerability.cvss3.baseScore : vulnerability.cvss2.baseScore
return createVulnerabilityReport(vulnerability.name, violatingPolicyVulnerabilityNames.includes(vulnerability.name), vulnerability._meta.href, compVulnBaseScore, vulnerability.severity)
})
}
Expand Down

0 comments on commit 0cba6cc

Please sign in to comment.