Skip to content

Commit

Permalink
remove enrich helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 14, 2025
1 parent ad32c0a commit 2b05b5d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 177 deletions.
118 changes: 59 additions & 59 deletions src/cli-pull-ot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,75 +28,75 @@ import {
* yarn cli-pull-ot --hostname=customer.my.onetrust.com --auth=$ONE_TRUST_OAUTH_TOKEN --file=./oneTrustAssessment.json
*/
async function main(): Promise<void> {
const { file, fileFormat, hostname, auth, resource, debug } =
const { file, fileFormat, hostname, auth, resource } =
parseCliPullOtArguments();

try {
// TODO: move to helper function
if (resource === OneTrustPullResource.Assessments) {
// use the hostname and auth token to instantiate a client to talk to OneTrust
const oneTrust = createOneTrustGotInstance({ hostname, auth });
// try {
// TODO: move to helper function
if (resource === OneTrustPullResource.Assessments) {
// use the hostname and auth token to instantiate a client to talk to OneTrust
const oneTrust = createOneTrustGotInstance({ hostname, auth });

// fetch the list of all assessments in the OneTrust organization
const assessments = await getListOfOneTrustAssessments({ oneTrust });
// fetch the list of all assessments in the OneTrust organization
const assessments = await getListOfOneTrustAssessments({ oneTrust });

// fetch details about one assessment at a time and sync to disk right away to avoid running out of memory
await mapSeries(assessments, async (assessment, index) => {
logger.info(
`Fetching details about assessment ${index + 1} of ${
assessments.length
}...`,
);
const assessmentDetails = await getOneTrustAssessment({
oneTrust,
assessmentId: assessment.assessmentId,
});
// fetch details about one assessment at a time and sync to disk right away to avoid running out of memory
await mapSeries(assessments, async (assessment, index) => {
logger.info(
`Fetching details about assessment ${index + 1} of ${
assessments.length
}...`,
);
const assessmentDetails = await getOneTrustAssessment({
oneTrust,
assessmentId: assessment.assessmentId,
});

// enrich assessments with risk information
let riskDetails: OneTrustGetRiskResponse[] = [];
const riskIds = uniq(
assessmentDetails.sections.flatMap((s: OneTrustAssessmentSection) =>
s.questions.flatMap((q: OneTrustAssessmentQuestion) =>
(q.risks ?? []).flatMap((r) => r.riskId),
),
// enrich assessments with risk information
let riskDetails: OneTrustGetRiskResponse[] = [];
const riskIds = uniq(
assessmentDetails.sections.flatMap((s: OneTrustAssessmentSection) =>
s.questions.flatMap((q: OneTrustAssessmentQuestion) =>
(q.risks ?? []).flatMap((r) => r.riskId),
),
),
);
if (riskIds.length > 0) {
logger.info(
`Fetching details about ${riskIds.length} risks for assessment ${
index + 1
} of ${assessments.length}...`,
);
riskDetails = await map(
riskIds,
(riskId) => getOneTrustRisk({ oneTrust, riskId: riskId as string }),
{
concurrency: 5,
},
);
if (riskIds.length > 0) {
logger.info(
`Fetching details about ${riskIds.length} risks for assessment ${
index + 1
} of ${assessments.length}...`,
);
riskDetails = await map(
riskIds,
(riskId) => getOneTrustRisk({ oneTrust, riskId: riskId as string }),
{
concurrency: 5,
},
);
}
}

writeOneTrustAssessment({
assessment,
assessmentDetails,
riskDetails,
index,
total: assessments.length,
file,
fileFormat,
});
writeOneTrustAssessment({
assessment,
assessmentDetails,
riskDetails,
index,
total: assessments.length,
file,
fileFormat,
});
}
} catch (err) {
logger.error(
colors.red(
`An error occurred pulling the resource ${resource} from OneTrust: ${
debug ? err.stack : err.message
}`,
),
);
process.exit(1);
});
}
// } catch (err) {
// logger.error(
// colors.red(
// `An error occurred pulling the resource ${resource} from OneTrust: ${
// debug ? err.stack : err.message
// }`,
// ),
// );
// process.exit(1);
// }

// Indicate success
logger.info(
Expand Down
101 changes: 0 additions & 101 deletions src/helpers/enrichWithDefault.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './inquirer';
export * from './parseVariablesFromString';
export * from './extractProperties';
export * from './createDefaultCodec';
export * from './enrichWithDefault';
19 changes: 6 additions & 13 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
OneTrustAssessmentSectionHeader,
OneTrustRiskCategories,
} from '@transcend-io/privacy-types';
import {
enrichCombinedAssessmentWithDefaults,
extractProperties,
} from '../helpers';
import { extractProperties } from '../helpers';
import {
OneTrustCombinedAssessment,
OneTrustEnrichedAssessmentQuestion,
Expand All @@ -23,7 +20,7 @@ import {

// TODO: test what happens when a value is null -> it should convert to ''
const flattenObject = (obj: any, prefix = ''): any =>
Object.keys(obj).reduce((acc, key) => {
Object.keys(obj ?? []).reduce((acc, key) => {
const newKey = prefix ? `${prefix}_${key}` : key;

const entry = obj[key];
Expand Down Expand Up @@ -132,7 +129,7 @@ const flattenOneTrustRiskCategories = (
allCategories: OneTrustRiskCategories[],
prefix: string,
): any => {
const allCategoriesFlat = allCategories.map((categories) => {
const allCategoriesFlat = (allCategories ?? []).map((categories) => {
const flatCategories = categories.map((c) => flattenObject(c, prefix));
return aggregateObjects({ objs: flatCategories });
});
Expand All @@ -144,12 +141,12 @@ const flattenOneTrustRisks = (
prefix: string,
): any => {
// TODO: extract categories and other nested properties
const allRisksFlat = allRisks.map((risks) => {
const allRisksFlat = (allRisks ?? []).map((risks) => {
const { categories, rest: restRisks } = extractProperties(risks ?? [], [
'categories',
]);

const flatRisks = restRisks.map((r) => flattenObject(r, prefix));
const flatRisks = (restRisks ?? []).map((r) => flattenObject(r, prefix));
return {
...aggregateObjects({ objs: flatRisks }),
...flattenOneTrustRiskCategories(categories, `${prefix}_categories`),
Expand Down Expand Up @@ -243,10 +240,6 @@ const flattenOneTrustSections = (
export const flattenOneTrustAssessment = (
combinedAssessment: OneTrustCombinedAssessment,
): Record<string, string> => {
// add default values to assessments
const combinedAssessmentWithDefaults =
enrichCombinedAssessmentWithDefaults(combinedAssessment);

const {
approvers,
primaryEntityDetails,
Expand All @@ -255,7 +248,7 @@ export const flattenOneTrustAssessment = (
respondent,
sections,
...rest
} = combinedAssessmentWithDefaults;
} = combinedAssessment;

// TODO: extract approver from approvers, otherwise it won't agree with the codec
const flatApprovers = approvers.map((approver) =>
Expand Down
3 changes: 0 additions & 3 deletions src/oneTrust/writeOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const writeOneTrustAssessment = ({
}),
);

// TODO: import from privacy-types
// ensure the record has the expected type!
decodeCodec(OneTrustAssessmentCsvRecord, flatAssessmentFull);

Expand All @@ -147,7 +146,5 @@ export const writeOneTrustAssessment = ({
// append the rows to the file
csvRows.push(`${assessmentRow.join(',')}\n`);
fs.appendFileSync('./oneTrust.csv', csvRows.join('\n'));

// TODO: consider not to convert it to CSV at all! The importOneTrustAssessments does not actually accept CSV.
}
};

0 comments on commit 2b05b5d

Please sign in to comment.