From 763ab39cbcbe33d50e135a6d97b8d5ea0fa0b0c3 Mon Sep 17 00:00:00 2001 From: Chris Wilson <46912004+sushicw@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:08:28 -0700 Subject: [PATCH] fix(samples): include locations/global in parent field (#488) * Include locations/global in parent field for samples * Go back to looking for exact name match on risk jobs * Fix & reenable tests * Put the skips back, they're needed for other reasons --- dlp/deid.js | 10 ++++---- dlp/inspect.js | 10 ++++---- dlp/jobs.js | 2 +- dlp/quickstart.js | 2 +- dlp/redact.js | 4 ++-- dlp/risk.js | 40 ++++++++----------------------- dlp/system-test/jobs.test.js | 14 +++++++---- dlp/system-test/templates.test.js | 2 +- dlp/system-test/triggers.test.js | 2 +- dlp/templates.js | 4 ++-- dlp/triggers.js | 4 ++-- 11 files changed, 40 insertions(+), 54 deletions(-) diff --git a/dlp/deid.js b/dlp/deid.js index 8a55a3ca9e..8f78a18db3 100644 --- a/dlp/deid.js +++ b/dlp/deid.js @@ -43,7 +43,7 @@ async function deidentifyWithMask( // Construct deidentification request const item = {value: string}; const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, deidentifyConfig: { infoTypeTransformations: { transformations: [ @@ -190,7 +190,7 @@ async function deidentifyWithDateShift( // Construct deidentification request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, deidentifyConfig: { recordTransformations: { fieldTransformations: [ @@ -289,7 +289,7 @@ async function deidentifyWithFpe( // Construct deidentification request const item = {value: string}; const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, deidentifyConfig: { infoTypeTransformations: { transformations: [ @@ -354,7 +354,7 @@ async function reidentifyWithFpe( // Construct deidentification request const item = {value: string}; const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, reidentifyConfig: { infoTypeTransformations: { transformations: [ @@ -426,7 +426,7 @@ async function deidentifyWithReplacement( // Construct deidentification request const item = {value: string}; const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, deidentifyConfig: { infoTypeTransformations: { transformations: [ diff --git a/dlp/inspect.js b/dlp/inspect.js index 5c9431b560..89cbbaefc7 100644 --- a/dlp/inspect.js +++ b/dlp/inspect.js @@ -57,7 +57,7 @@ async function inspectString( // Construct request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectConfig: { infoTypes: infoTypes, customInfoTypes: customInfoTypes, @@ -150,7 +150,7 @@ async function inspectFile( // Construct request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectConfig: { infoTypes: infoTypes, customInfoTypes: customInfoTypes, @@ -246,7 +246,7 @@ async function inspectGCSFile( // Construct request for creating an inspect job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectJob: { inspectConfig: { infoTypes: infoTypes, @@ -394,7 +394,7 @@ async function inspectDatastore( // Construct request for creating an inspect job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectJob: { inspectConfig: { infoTypes: infoTypes, @@ -537,7 +537,7 @@ async function inspectBigquery( // Construct request for creating an inspect job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectJob: { inspectConfig: { infoTypes: infoTypes, diff --git a/dlp/jobs.js b/dlp/jobs.js index 4464e7e55f..fadeb1ecca 100644 --- a/dlp/jobs.js +++ b/dlp/jobs.js @@ -36,7 +36,7 @@ async function listJobs(callingProjectId, filter, jobType) { // Construct request for listing DLP scan jobs const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, filter: filter, type: jobType, }; diff --git a/dlp/quickstart.js b/dlp/quickstart.js index 347afa5917..637de7d565 100644 --- a/dlp/quickstart.js +++ b/dlp/quickstart.js @@ -46,7 +46,7 @@ async function quickStart() { // Construct request const request = { - parent: dlp.projectPath(projectId), + parent: `projects/${projectId}/locations/global`, inspectConfig: { infoTypes: infoTypes, minLikelihood: minLikelihood, diff --git a/dlp/redact.js b/dlp/redact.js index f7553b1e46..67afeea301 100644 --- a/dlp/redact.js +++ b/dlp/redact.js @@ -32,7 +32,7 @@ async function redactText(callingProjectId, string, minLikelihood, infoTypes) { // Construct redaction request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, item: { value: string, }, @@ -105,7 +105,7 @@ async function redactImage( // Construct image redaction request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, byteItem: { type: fileTypeConstant, data: fileBytes, diff --git a/dlp/risk.js b/dlp/risk.js index 963b6b0c66..74c66f63d5 100644 --- a/dlp/risk.js +++ b/dlp/risk.js @@ -68,7 +68,7 @@ async function numericalRiskAnalysis( // Construct request for creating a risk analysis job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, riskJob: { privacyMetric: { numericalStatsConfig: { @@ -97,14 +97,10 @@ async function numericalRiskAnalysis( const subscription = await topicResponse.subscription(subscriptionId); const [jobsResponse] = await dlp.createDlpJob(request); const jobName = jobsResponse.name; - const jobNameSuffix = jobName.split('/').pop(); // Watch the Pub/Sub topic until the DLP job finishes await new Promise((resolve, reject) => { const messageHandler = message => { - if ( - message.attributes && - message.attributes.DlpJobName.includes(jobNameSuffix) - ) { + if (message.attributes && message.attributes.DlpJobName === jobName) { message.ack(); subscription.removeListener('message', messageHandler); subscription.removeListener('error', errorHandler); @@ -207,7 +203,7 @@ async function categoricalRiskAnalysis( // Construct request for creating a risk analysis job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, riskJob: { privacyMetric: { categoricalStatsConfig: { @@ -236,14 +232,10 @@ async function categoricalRiskAnalysis( const subscription = await topicResponse.subscription(subscriptionId); const [jobsResponse] = await dlp.createDlpJob(request); const jobName = jobsResponse.name; - const jobNameSuffix = jobName.split('/').pop(); // Watch the Pub/Sub topic until the DLP job finishes await new Promise((resolve, reject) => { const messageHandler = message => { - if ( - message.attributes && - message.attributes.DlpJobName.includes(jobNameSuffix) - ) { + if (message.attributes && message.attributes.DlpJobName === jobName) { message.ack(); subscription.removeListener('message', messageHandler); subscription.removeListener('error', errorHandler); @@ -347,7 +339,7 @@ async function kAnonymityAnalysis( // Construct request for creating a risk analysis job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, riskJob: { privacyMetric: { kAnonymityConfig: { @@ -374,14 +366,10 @@ async function kAnonymityAnalysis( const subscription = await topicResponse.subscription(subscriptionId); const [jobsResponse] = await dlp.createDlpJob(request); const jobName = jobsResponse.name; - const jobNameSuffix = jobName.split('/').pop(); // Watch the Pub/Sub topic until the DLP job finishes await new Promise((resolve, reject) => { const messageHandler = message => { - if ( - message.attributes && - message.attributes.DlpJobName.includes(jobNameSuffix) - ) { + if (message.attributes && message.attributes.DlpJobName === jobName) { message.ack(); subscription.removeListener('message', messageHandler); subscription.removeListener('error', errorHandler); @@ -483,7 +471,7 @@ async function lDiversityAnalysis( // Construct request for creating a risk analysis job const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, riskJob: { privacyMetric: { lDiversityConfig: { @@ -513,14 +501,10 @@ async function lDiversityAnalysis( const subscription = await topicResponse.subscription(subscriptionId); const [jobsResponse] = await dlp.createDlpJob(request); const jobName = jobsResponse.name; - const jobNameSuffix = jobName.split('/').pop(); // Watch the Pub/Sub topic until the DLP job finishes await new Promise((resolve, reject) => { const messageHandler = message => { - if ( - message.attributes && - message.attributes.DlpJobName.includes(jobNameSuffix) - ) { + if (message.attributes && message.attributes.DlpJobName === jobName) { message.ack(); subscription.removeListener('message', messageHandler); subscription.removeListener('error', errorHandler); @@ -631,7 +615,7 @@ async function kMapEstimationAnalysis( // Construct request for creating a risk analysis job const request = { - parent: dlp.projectPath(process.env.GCLOUD_PROJECT), + parent: `projects/${callingProjectId}/locations/global`, riskJob: { privacyMetric: { kMapEstimationConfig: { @@ -659,14 +643,10 @@ async function kMapEstimationAnalysis( const subscription = await topicResponse.subscription(subscriptionId); const [jobsResponse] = await dlp.createDlpJob(request); const jobName = jobsResponse.name; - const jobNameSuffix = jobName.split('/').pop(); // Watch the Pub/Sub topic until the DLP job finishes await new Promise((resolve, reject) => { const messageHandler = message => { - if ( - message.attributes && - message.attributes.DlpJobName.includes(jobNameSuffix) - ) { + if (message.attributes && message.attributes.DlpJobName === jobName) { message.ack(); subscription.removeListener('message', messageHandler); subscription.removeListener('error', errorHandler); diff --git a/dlp/system-test/jobs.test.js b/dlp/system-test/jobs.test.js index 0f16cb7d76..e49989f2c7 100644 --- a/dlp/system-test/jobs.test.js +++ b/dlp/system-test/jobs.test.js @@ -39,7 +39,7 @@ describe('jobs', () => { // Construct job request const request = { - parent: dlp.projectPath(testCallingProjectId), + parent: `projects/${testCallingProjectId}/locations/global`, riskJob: { privacyMetric: { categoricalStatsConfig: { @@ -72,7 +72,7 @@ describe('jobs', () => { async function deleteStaleJobs() { const dlp = new DLP.DlpServiceClient(); const request = { - parent: dlp.projectPath(testCallingProjectId), + parent: `projects/${testCallingProjectId}/locations/global`, filter: 'state=DONE', type: 'RISK_ANALYSIS_JOB', }; @@ -91,12 +91,18 @@ describe('jobs', () => { // dlp_list_jobs it('should list jobs', () => { const output = execSync(`${cmd} list 'state=DONE'`); - assert.match(output, /Job projects\/(\w|-)+\/dlpJobs\/\w-\d+ status: DONE/); + assert.match( + output, + /Job projects\/(\w|-)+\/locations\/global\/dlpJobs\/\w-\d+ status: DONE/ + ); }); it('should list jobs of a given type', () => { const output = execSync(`${cmd} list 'state=DONE' -t RISK_ANALYSIS_JOB`); - assert.match(output, /Job projects\/(\w|-)+\/dlpJobs\/r-\d+ status: DONE/); + assert.match( + output, + /Job projects\/(\w|-)+\/locations\/global\/dlpJobs\/r-\d+ status: DONE/ + ); }); it('should handle job listing errors', () => { diff --git a/dlp/system-test/templates.test.js b/dlp/system-test/templates.test.js index fe2e18c374..0b774d6d3d 100644 --- a/dlp/system-test/templates.test.js +++ b/dlp/system-test/templates.test.js @@ -32,7 +32,7 @@ describe('templates', () => { const DISPLAY_NAME = `My Template ${uuid.v4()}`; const TEMPLATE_NAME = `my-template-${uuid.v4()}`; - const fullTemplateName = `projects/${process.env.GCLOUD_PROJECT}/inspectTemplates/${TEMPLATE_NAME}`; + const fullTemplateName = `projects/${process.env.GCLOUD_PROJECT}/locations/global/inspectTemplates/${TEMPLATE_NAME}`; // create_inspect_template it('should create template', () => { diff --git a/dlp/system-test/triggers.test.js b/dlp/system-test/triggers.test.js index bc8c57b301..7271623a03 100644 --- a/dlp/system-test/triggers.test.js +++ b/dlp/system-test/triggers.test.js @@ -25,7 +25,7 @@ describe('triggers', () => { const projectId = process.env.GCLOUD_PROJECT; const cmd = 'node triggers.js'; const triggerName = `my-trigger-${uuid.v4()}`; - const fullTriggerName = `projects/${projectId}/jobTriggers/${triggerName}`; + const fullTriggerName = `projects/${projectId}/locations/global/jobTriggers/${triggerName}`; const triggerDisplayName = `My Trigger Display Name: ${uuid.v4()}`; const triggerDescription = `My Trigger Description: ${uuid.v4()}`; const infoType = 'PERSON_NAME'; diff --git a/dlp/templates.js b/dlp/templates.js index 91ca83f0e6..31e5ceccdb 100644 --- a/dlp/templates.js +++ b/dlp/templates.js @@ -65,7 +65,7 @@ async function createInspectTemplate( // Construct template-creation request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, inspectTemplate: { inspectConfig: inspectConfig, displayName: displayName, @@ -103,7 +103,7 @@ async function listInspectTemplates(callingProjectId) { // Construct template-listing request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, }; try { diff --git a/dlp/triggers.js b/dlp/triggers.js index b2f06f665e..a1f70d1c9b 100644 --- a/dlp/triggers.js +++ b/dlp/triggers.js @@ -89,7 +89,7 @@ async function createTrigger( // Construct trigger creation request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, jobTrigger: { inspectJob: job, displayName: displayName, @@ -132,7 +132,7 @@ async function listTriggers(callingProjectId) { // Construct trigger listing request const request = { - parent: dlp.projectPath(callingProjectId), + parent: `projects/${callingProjectId}/locations/global`, }; // Helper function to pretty-print dates