( projectId, inputCsvFile, outputCsvFile, dateFields, lowerBoundDays, upperBoundDays, contextFieldId, wrappedKey, keyName )
| 20 | // usage: node deidentifyWithDateShift.js my-project dates.csv dates-shifted.csv 30 30 birth_date register_date [<YOUR_ENCRYPTED_AES_256_KEY> projects/my-project/locations/global/keyrings/my-keyring] |
| 21 | |
| 22 | function main( |
| 23 | projectId, |
| 24 | inputCsvFile, |
| 25 | outputCsvFile, |
| 26 | dateFields, |
| 27 | lowerBoundDays, |
| 28 | upperBoundDays, |
| 29 | contextFieldId, |
| 30 | wrappedKey, |
| 31 | keyName |
| 32 | ) { |
| 33 | dateFields = transformCLI(dateFields); |
| 34 | // [START dlp_deidentify_date_shift] |
| 35 | // Imports the Google Cloud Data Loss Prevention library |
| 36 | const DLP = require('@google-cloud/dlp'); |
| 37 | |
| 38 | // Instantiates a client |
| 39 | const dlp = new DLP.DlpServiceClient(); |
| 40 | |
| 41 | // Import other required libraries |
| 42 | const fs = require('fs'); |
| 43 | |
| 44 | // The project ID to run the API call under |
| 45 | // const projectId = 'my-project'; |
| 46 | |
| 47 | // The path to the CSV file to deidentify |
| 48 | // The first row of the file must specify column names, and all other rows |
| 49 | // must contain valid values |
| 50 | // const inputCsvFile = '/path/to/input/file.csv'; |
| 51 | |
| 52 | // The path to save the date-shifted CSV file to |
| 53 | // const outputCsvFile = '/path/to/output/file.csv'; |
| 54 | |
| 55 | // The list of (date) fields in the CSV file to date shift |
| 56 | // const dateFields = [{ name: 'birth_date'}, { name: 'register_date' }]; |
| 57 | |
| 58 | // The maximum number of days to shift a date backward |
| 59 | // const lowerBoundDays = 1; |
| 60 | |
| 61 | // The maximum number of days to shift a date forward |
| 62 | // const upperBoundDays = 1; |
| 63 | |
| 64 | // (Optional) The column to determine date shift amount based on |
| 65 | // If this is not specified, a random shift amount will be used for every row |
| 66 | // If this is specified, then 'wrappedKey' and 'keyName' must also be set |
| 67 | // const contextFieldId = [{ name: 'user_id' }]; |
| 68 | |
| 69 | // (Optional) The name of the Cloud KMS key used to encrypt ('wrap') the AES-256 key |
| 70 | // If this is specified, then 'wrappedKey' and 'contextFieldId' must also be set |
| 71 | // const keyName = 'projects/YOUR_GCLOUD_PROJECT/locations/YOUR_LOCATION/keyRings/YOUR_KEYRING_NAME/cryptoKeys/YOUR_KEY_NAME'; |
| 72 | |
| 73 | // (Optional) The encrypted ('wrapped') AES-256 key to use when shifting dates |
| 74 | // This key should be encrypted using the Cloud KMS key specified above |
| 75 | // If this is specified, then 'keyName' and 'contextFieldId' must also be set |
| 76 | // const wrappedKey = 'YOUR_ENCRYPTED_AES_256_KEY' |
| 77 | |
| 78 | // Helper function for converting CSV rows to Protobuf types |
| 79 | const rowToProto = row => { |
no test coverage detected