-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
099a7e3
commit 70de777
Showing
6 changed files
with
107 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import got, { Got } from 'got'; | ||
|
||
/** | ||
* Instantiate an instance of got that is capable of making requests to OneTrust | ||
* | ||
* @param param - information about the OneTrust URL | ||
* @returns The instance of got that is capable of making requests to the customer ingress | ||
*/ | ||
export const createOneTrustGotInstance = ({ | ||
hostname, | ||
auth, | ||
}: { | ||
/** Hostname of the OneTrust API */ | ||
hostname: string; | ||
/** The OAuth access token */ | ||
auth: string; | ||
}): Got => | ||
got.extend({ | ||
prefixUrl: `https://${hostname}`, | ||
headers: { | ||
accept: 'application/json', | ||
'content-type': 'application/json', | ||
authorization: `Bearer ${auth}`, | ||
}, | ||
}); |
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,49 @@ | ||
import { Got } from 'got'; | ||
import { logger } from '../logger'; | ||
import { | ||
OneTrustAssessment, | ||
OneTrustGetListOfAssessmentsResponse, | ||
} from './types'; | ||
|
||
/** | ||
* Fetch a list of all assessments from the OneTrust client. | ||
* | ||
* @param param - the information about the OneTrust client | ||
* @returns a list of OneTrustAssessment | ||
*/ | ||
export const getListOfAssessments = async ({ | ||
oneTrust, | ||
}: { | ||
/** The OneTrust client instance */ | ||
oneTrust: Got; | ||
}): Promise<OneTrustAssessment[]> => { | ||
let currentPage = 0; | ||
let totalPages = 1; | ||
let totalElements = 0; | ||
|
||
const allAssessments: OneTrustAssessment[] = []; | ||
|
||
logger.info('Getting list of OneTrust assessments...'); | ||
while (currentPage < totalPages) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const { body } = await oneTrust.get( | ||
`api/assessment/v2/assessments?page=${currentPage}&size=2000`, | ||
); | ||
const parsedBody = JSON.parse(body) as OneTrustGetListOfAssessmentsResponse; | ||
const assessments = parsedBody.content ?? []; | ||
allAssessments.push(...assessments); | ||
const page = parsedBody.page ?? { totalPages: 0, totalElements: 0 }; | ||
if (currentPage === 0) { | ||
totalPages = page.totalPages; | ||
totalElements = page.totalElements; | ||
} | ||
currentPage += 1; | ||
|
||
// log progress | ||
logger.info( | ||
`Fetched ${allAssessments.length} of ${totalElements} assessments.`, | ||
); | ||
} | ||
|
||
return allAssessments; | ||
}; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './pullOneTrustConfiguration'; | ||
export * from './getListOfAssessments'; | ||
export * from './createOneTrustGotInstance'; |
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