Skip to content

Commit

Permalink
feat: Get top parent name and customize UA
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlaud committed Jul 20, 2020
1 parent a72e834 commit 7c66192
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ interface snykRequest {
requestId?: string
}

const getTopParentModuleName = (parent: NodeModule | null): string => {
if(parent == null){
return ''
}
if(parent?.parent){
return getTopParentModuleName(parent.parent)
} else {
return parent?.paths[0].split('/')[parent.paths[0].split('/').length-2]+'/' as string
}
}

const makeSnykRequest = async (request: snykRequest, snykToken: string = '') => {
const userConfig = getConfig()
const token = snykToken == '' ? userConfig.token : snykToken

let topParentModuleName = getTopParentModuleName(module.parent)

const requestHeaders: Object = {
'Content-Type': 'application/json',
'Authorization': 'token '+ token,
'User-Agent': 'tech-services/snyk-request-manager/1.0'
'User-Agent': `${topParentModuleName}tech-services/snyk-request-manager/1.0`
}

const apiClient = axios.create({
baseURL: userConfig.endpoint,
responseType: 'json',
Expand Down

0 comments on commit 7c66192

Please sign in to comment.