From 6ec35ba974934f5eba62739e93a9045fa5915aa7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 14 Jan 2025 03:31:00 +0000 Subject: [PATCH] update readme --- README.md | 35 +++++++--- .../helpers/parseCliSyncOtArguments.ts | 64 +++++++++++++------ .../helpers/syncOneTrustAssessments.ts | 3 +- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index e233e3a0..01cfa962 100644 --- a/README.md +++ b/README.md @@ -598,21 +598,36 @@ To learn how to generate the token, see the [OAuth 2.0 Scopes](https://developer #### Arguments -| Argument | Description | Type | Default | Required | -| ---------- | ------------------------------------------------------------------------------------------------- | ------- | ----------- | -------- | -| auth | The OAuth access token with the scopes necessary to access the OneTrust Public APIs. | string | N/A | true | -| hostname | The domain of the OneTrust environment from which to pull the resource (e.g. trial.onetrust.com). | string | N/A | true | -| file | Path to the file to pull the resource into. Its format must match the fileFormat argument. | string | N/A | true | -| fileFormat | The format of the output file. | string | csv | false | -| resource | The resource to pull from OneTrust. For now, only assessments is supported. | string | assessments | false | -| debug | Whether to print detailed logs in case of error. | boolean | false | false | -| dryRun | Whether to export the resource to a file rather than sync to Transcend. | boolean | false | false | +| Argument | Description | Type | Default | Required | +| ------------- | ------------------------------------------------------------------------------------------------- | ------- | ----------- | -------- | +| hostname | The domain of the OneTrust environment from which to pull the resource (e.g. trial.onetrust.com). | string | N/A | true | +| oneTrustAuth | The OAuth access token with the scopes necessary to access the OneTrust Public APIs. | string | N/A | true | +| transcendAuth | The Transcend API Key to with the scopes necessary to access Transcend's Public APIs. | string | N/A | false | +| file | Path to the file to pull the resource into. Its format must match the fileFormat argument. | string | N/A | false | +| fileFormat | The format of the output file. | string | csv | false | +| resource | The resource to pull from OneTrust. For now, only assessments is supported. | string | assessments | false | +| dryRun | Whether to export the resource to a file rather than sync to Transcend. | boolean | false | false | +| debug | Whether to print detailed logs in case of error. | boolean | false | false | #### Usage +```sh +# Syncs all assessments from the OneTrust instance to Transcend +tr-sync-ot --hostname=trial.onetrust.com --oneTrustAuth=$ONE_TRUST_OAUTH_TOKEN --transcendAuth=$TRANSCEND_API_KEY +``` + +Alternatively, you can set dryRun to true and sync the resource to disk: + +```sh +# Writes out file to ./oneTrustAssessments.csv +tr-sync-ot --hostname=trial.onetrust.com --oneTrustAuth=$ONE_TRUST_OAUTH_TOKEN --dryRun=true --file=./oneTrustAssessments.csv +``` + +You can also sync to disk in json format: + ```sh # Writes out file to ./oneTrustAssessments.json -tr-sync-ot --auth=$ONE_TRUST_OAUTH_TOKEN --hostname=trial.onetrust.com --file=./oneTrustAssessments.json +tr-sync-ot --hostname=trial.onetrust.com --oneTrustAuth=$ONE_TRUST_OAUTH_TOKEN --dryRun=true --fileFormat=json --file=./oneTrustAssessments.json ``` ### tr-push diff --git a/src/oneTrust/helpers/parseCliSyncOtArguments.ts b/src/oneTrust/helpers/parseCliSyncOtArguments.ts index d8ae3581..6d726cf1 100644 --- a/src/oneTrust/helpers/parseCliSyncOtArguments.ts +++ b/src/oneTrust/helpers/parseCliSyncOtArguments.ts @@ -11,8 +11,10 @@ interface OneTrustCliArguments { file: string; /** The OneTrust hostname to send the requests to */ hostname: string; - /** The OAuth Bearer token used to authenticate the requests */ - auth: string; + /** The OAuth Bearer token used to authenticate the requests to OneTrust */ + oneTrustAuth: string; + /** The Transcend API key to authenticate the requests to Transcend */ + transcendAuth: string; /** The resource to pull from OneTrust */ resource: OneTrustPullResource; /** Whether to enable debugging while reporting errors */ @@ -29,25 +31,50 @@ interface OneTrustCliArguments { * @returns the parsed arguments */ export const parseCliSyncOtArguments = (): OneTrustCliArguments => { - const { file, hostname, auth, resource, debug, fileFormat, dryRun } = yargs( - process.argv.slice(2), - { - string: ['file', 'hostname', 'auth', 'resource', 'fileFormat', 'dryRun'], - boolean: ['debug', 'dryRun'], - default: { - resource: OneTrustPullResource.Assessments, - fileFormat: OneTrustFileFormat.Csv, - debug: false, - dryRun: false, - }, + const { + file, + hostname, + oneTrustAuth, + resource, + debug, + fileFormat, + dryRun, + transcendAuth, + } = yargs(process.argv.slice(2), { + string: [ + 'file', + 'hostname', + 'oneTrustAuth', + 'resource', + 'fileFormat', + 'dryRun', + 'transcendAuth', + ], + boolean: ['debug', 'dryRun'], + default: { + resource: OneTrustPullResource.Assessments, + fileFormat: OneTrustFileFormat.Csv, + debug: false, + dryRun: false, }, - ); + }); + + // Can only sync to Transcend via a CSV file format! + if (!dryRun && !transcendAuth) { + logger.error( + colors.red( + // eslint-disable-next-line no-template-curly-in-string + 'Must specify a "transcendAuth" parameter to sync resources to Transcend. e.g. --transcendAuth=${TRANSCEND_API_KEY}', + ), + ); + return process.exit(1); + } // Can only sync to Transcend via a CSV file format! if (!dryRun && fileFormat !== OneTrustFileFormat.Csv) { logger.error( colors.red( - `The "fileFormat" parameter must equal ${OneTrustFileFormat.Csv} when "dryRun" is "false".`, + `The "fileFormat" parameter must equal ${OneTrustFileFormat.Csv} to sync resources to Transcend.`, ), ); return process.exit(1); @@ -102,10 +129,10 @@ export const parseCliSyncOtArguments = (): OneTrustCliArguments => { return process.exit(1); } - if (!auth) { + if (!oneTrustAuth) { logger.error( colors.red( - 'Missing required parameter "auth". e.g. --auth=$ONE_TRUST_AUTH_TOKEN', + 'Missing required parameter "oneTrustAuth". e.g. --oneTrustAuth=$ONE_TRUST_AUTH_TOKEN', ), ); return process.exit(1); @@ -134,10 +161,11 @@ export const parseCliSyncOtArguments = (): OneTrustCliArguments => { return { file, hostname, - auth, + oneTrustAuth, resource, debug, fileFormat, dryRun, + transcendAuth, }; }; diff --git a/src/oneTrust/helpers/syncOneTrustAssessments.ts b/src/oneTrust/helpers/syncOneTrustAssessments.ts index 0790d958..2ebb4fc9 100644 --- a/src/oneTrust/helpers/syncOneTrustAssessments.ts +++ b/src/oneTrust/helpers/syncOneTrustAssessments.ts @@ -15,6 +15,7 @@ import uniq from 'lodash/uniq'; import { enrichOneTrustAssessment } from './enrichOneTrustAssessment'; import { writeOneTrustAssessment } from './writeOneTrustAssessment'; import { OneTrustFileFormat } from '../../enums'; +import { oneTrustAssessmentToCsvRecord } from './oneTrustAssessmentToCsvRecord'; export const syncOneTrustAssessments = async ({ oneTrust, @@ -92,7 +93,7 @@ export const syncOneTrustAssessments = async ({ }); } else if (fileFormat === OneTrustFileFormat.Csv) { // sync to transcend - // const csvEntry = oneTrustAssessmentToCsv({ assessment, index }); + // const csvEntry = oneTrustAssessmentToCsvRecord(enrichedAssessment); } }); };