Skip to content

Commit

Permalink
fix(samples): include locations/global in parent field (#488)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sushicw authored Jun 23, 2020
1 parent 1519df5 commit 763ab39
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 54 deletions.
10 changes: 5 additions & 5 deletions dlp/deid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -190,7 +190,7 @@ async function deidentifyWithDateShift(

// Construct deidentification request
const request = {
parent: dlp.projectPath(callingProjectId),
parent: `projects/${callingProjectId}/locations/global`,
deidentifyConfig: {
recordTransformations: {
fieldTransformations: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
10 changes: 5 additions & 5 deletions dlp/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dlp/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion dlp/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dlp/redact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 10 additions & 30 deletions dlp/risk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand All @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions dlp/system-test/jobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('jobs', () => {

// Construct job request
const request = {
parent: dlp.projectPath(testCallingProjectId),
parent: `projects/${testCallingProjectId}/locations/global`,
riskJob: {
privacyMetric: {
categoricalStatsConfig: {
Expand Down Expand Up @@ -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',
};
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion dlp/system-test/templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion dlp/system-test/triggers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions dlp/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -103,7 +103,7 @@ async function listInspectTemplates(callingProjectId) {

// Construct template-listing request
const request = {
parent: dlp.projectPath(callingProjectId),
parent: `projects/${callingProjectId}/locations/global`,
};

try {
Expand Down
4 changes: 2 additions & 2 deletions dlp/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 763ab39

Please sign in to comment.