Skip to content

Commit

Permalink
update enrichOneTrustAssessment to enrich creator
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 21, 2025
1 parent 8ab3780 commit 6a1d610
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ Note: This command will overwrite the existing transcend.yml file that you have

### tr-sync-ot

Pulls resources from a OneTrust and syncs them to a Transcend instance. For now, it only supports retrieving OneTrust Assessments. It sends a request to the [Get List of Assessments](https://developer.onetrust.com/onetrust/reference/getallassessmentbasicdetailsusingget) endpoint to fetch a list of all Assessments in your account. Then, it queries the [Get Assessment](https://developer.onetrust.com/onetrust/reference/exportassessmentusingget) and [Get Risk](https://developer.onetrust.com/onetrust/reference/getriskusingget) endpoints to enrich these assessments with more details such as respondents, approvers, assessment questions and responses, and assessment risks. Finally, it syncs the enriched resources to disk in the specified file and format.
Pulls resources from a OneTrust and syncs them to a Transcend instance. For now, it only supports retrieving OneTrust Assessments. It sends a request to the [Get List of Assessments](https://developer.onetrust.com/onetrust/reference/getallassessmentbasicdetailsusingget) endpoint to fetch a list of all Assessments in your account. Then, it queries the [Get Assessment](https://developer.onetrust.com/onetrust/reference/exportassessmentusingget), [Get Risk](https://developer.onetrust.com/onetrust/reference/getriskusingget), and [Get User](https://developer.onetrust.com/onetrust/reference/getuserbyid) endpoints to enrich these assessments with more details such as respondents, approvers, assessment questions and responses, and assessment risks. Finally, it syncs the enriched resources to disk in the specified file and format.

This command can be helpful if you are looking to:

Expand All @@ -594,6 +594,7 @@ In order to use this command, you will need to generate a OneTrust OAuth Token w
- [GET /v2/assessments](https://developer.onetrust.com/onetrust/reference/getallassessmentbasicdetailsusingget)
- [GET /v2/assessments/{assessmentId}/export](https://developer.onetrust.com/onetrust/reference/exportassessmentusingget)
- [GET /risks/{riskId}](https://developer.onetrust.com/onetrust/reference/getriskusingget)
- [GET /v2/Users/{userId}](https://developer.onetrust.com/onetrust/reference/getuserusingget)

To learn how to generate the token, see the [OAuth 2.0 Scopes](https://developer.onetrust.com/onetrust/reference/oauth-20-scopes) and [Generate Access Token](https://developer.onetrust.com/onetrust/reference/getoauthtoken) pages.

Expand Down
27 changes: 27 additions & 0 deletions src/oneTrust/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
OneTrustGetRiskResponse,
} from '@transcend-io/privacy-types';
import * as t from 'io-ts';
import { OneTrustGetUserResponse } from './endpoints';

// FIXME: some some of these to privacy-types (the ones shared with main)

/** OneTrustAssessmentNestedQuestion without nested options */
export const OneTrustAssessmentNestedQuestionFlat = t.type({
Expand Down Expand Up @@ -148,8 +151,32 @@ export type OneTrustEnrichedAssessmentSection = t.TypeOf<
typeof OneTrustEnrichedAssessmentSection
>;

// FIXME: add to OneTrustGetAssessmentResponse
const OneTrustAssessmentCreatedBy = t.type({
/** The ID of the creator */
id: t.string,
/** The name of the creator */
name: t.string,
/** The name key of the template */
nameKey: t.union([t.string, t.null]),
});

/** Type override */
export type OneTrustAssessmentCreatedBy = t.TypeOf<
typeof OneTrustAssessmentCreatedBy
>;

export const OneTrustEnrichedUser = t.type({
...OneTrustAssessmentCreatedBy.props,
...OneTrustGetUserResponse.props,
});

/** Type override */
export type OneTrustEnrichedUser = t.TypeOf<typeof OneTrustEnrichedUser>;

export const OneTrustEnrichedAssessmentResponse = t.type({
...OneTrustGetAssessmentResponse.props,
createdBy: OneTrustEnrichedUser,
sections: t.array(OneTrustEnrichedAssessmentSection),
});
/** Type override */
Expand Down
1 change: 1 addition & 0 deletions src/oneTrust/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './getListOfOneTrustAssessments';
export * from './getOneTrustAssessment';
export * from './getOneTrustRisk';
export * from './getOneTrustUser';
12 changes: 11 additions & 1 deletion src/oneTrust/helpers/enrichOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@transcend-io/privacy-types';
import keyBy from 'lodash/keyBy';
import { OneTrustEnrichedAssessment } from '../codecs';
import { OneTrustGetUserResponse } from '../endpoints';

/**
* Merge the assessment, assessmentDetails, and riskDetails into one object.
Expand All @@ -16,16 +17,19 @@ export const enrichOneTrustAssessment = ({
assessment,
assessmentDetails,
riskDetails,
creatorDetails,
}: {
/** The OneTrust risk details */
riskDetails: OneTrustGetRiskResponse[];
/** The OneTrust assessment as returned from Get List of Assessments endpoint */
assessment: OneTrustAssessment;
/** The OneTrust assessment details */
assessmentDetails: OneTrustGetAssessmentResponse;
/** The OneTrust assessment creator details */
creatorDetails: OneTrustGetUserResponse;
}): OneTrustEnrichedAssessment => {
const riskDetailsById = keyBy(riskDetails, 'id');
const { sections, ...restAssessmentDetails } = assessmentDetails;
const { sections, createdBy, ...restAssessmentDetails } = assessmentDetails;
const sectionsWithEnrichedRisk = sections.map((section) => {
const { questions, ...restSection } = section;
const enrichedQuestions = questions.map((question) => {
Expand Down Expand Up @@ -57,11 +61,17 @@ export const enrichOneTrustAssessment = ({
};
});

const enrichedCreatedBy = {
...createdBy,
...creatorDetails,
};

// combine the two assessments into a single enriched result

return {
...assessment,
...restAssessmentDetails,
createdBy: enrichedCreatedBy,
sections: sectionsWithEnrichedRisk,
};
};
14 changes: 14 additions & 0 deletions src/oneTrust/helpers/syncOneTrustAssessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getListOfOneTrustAssessments,
getOneTrustAssessment,
getOneTrustRisk,
getOneTrustUser,
} from '../endpoints';
import { map, mapSeries } from 'bluebird';
import { logger } from '../../logger';
Expand Down Expand Up @@ -62,6 +63,18 @@ export const syncOneTrustAssessments = async ({
assessmentId: assessment.assessmentId,
});

// enrich assessments with user information
const creator = await getOneTrustUser({
oneTrust,
creatorId: assessmentDetails.createdBy.id,
});

/**
* FIXME: enrich rootRequestInformationIds
*/

// console.log({ creator });

// enrich assessments with risk information
let riskDetails: OneTrustGetRiskResponse[] = [];
const riskIds = uniq(
Expand Down Expand Up @@ -91,6 +104,7 @@ export const syncOneTrustAssessments = async ({
assessment,
assessmentDetails,
riskDetails,
creatorDetails: creator,
});

if (dryRun && file && fileFormat) {
Expand Down

0 comments on commit 6a1d610

Please sign in to comment.