Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 14, 2025
1 parent 4256788 commit 6ec35ba
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 46 additions & 18 deletions src/oneTrust/helpers/parseCliSyncOtArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -134,10 +161,11 @@ export const parseCliSyncOtArguments = (): OneTrustCliArguments => {
return {
file,
hostname,
auth,
oneTrustAuth,
resource,
debug,
fileFormat,
dryRun,
transcendAuth,
};
};
3 changes: 2 additions & 1 deletion src/oneTrust/helpers/syncOneTrustAssessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
});
};

0 comments on commit 6ec35ba

Please sign in to comment.