Skip to content

Commit

Permalink
Merge branch 'main' into renovate/google-cloud-aiplatform-3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
pattishin authored Aug 8, 2023
2 parents bab7e46 + a07d704 commit 3da20f0
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 3 deletions.
82 changes: 82 additions & 0 deletions dlp/createJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// sample-metadata:
// title: Create an inspection job
// description: Create an inspection job
// usage: node createJob.js my-project bucket-url
function main(projectId, cloudFileUrl) {
// [START dlp_create_job]
// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

// Initialize google DLP Client
const dlp = new DLP.DlpServiceClient();

async function jobsCreate() {
// Construct cloud storage configuration
const cloudStorageConfig = {
cloudStorageOptions: {
fileSet: {
url: cloudFileUrl,
},
},
timespanConfig: {
enableAutoPopulationOfTimespanConfig: true,
},
};

// Construct inspect job configuration
const inspectJob = {
storageConfig: cloudStorageConfig,
};

// Construct inspect configuration
const inspectConfig = {
infoTypes: [
{name: 'EMAIL_ADDRESS'},
{name: 'PERSON_NAME'},
{name: 'LOCATION'},
{name: 'PHONE_NUMBER'},
],
includeQuote: true,
minLikelihood: DLP.protos.google.privacy.dlp.v2.Likelihood.LIKELY,
excludeInfoTypes: false,
};

// Combine configurations into a request for the service.
const request = {
parent: `projects/${projectId}/locations/global`,
inspectJob: inspectJob,
inspectConfig: inspectConfig,
};

// Send the request and receive response from the service
const [response] = await dlp.createDlpJob(request);
// Print the results
console.log(`Job created successfully: ${response.name}`);
}

jobsCreate();
// [END dlp_create_job]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
54 changes: 54 additions & 0 deletions dlp/getJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// sample-metadata:
// title: Get an inspection job
// description: Get DLP inspection job using job name.
// usage: node getJob.js jobName
function main(jobName) {
// [START dlp_get_job]
// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

// Instantiates a client
const dlp = new DLP.DlpServiceClient();

// Job name to look for
// const jobName = 'your-job-name';

async function getJob() {
// Construct request for finding job using job name.
const request = {
name: jobName,
};

// Send the request and receive response from the service
const [job] = await dlp.getDlpJob(request);

// Print results.
console.log(`Job ${job.name} status: ${job.state}`);
}

getJob();
// [END dlp_get_job]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
39 changes: 39 additions & 0 deletions dlp/system-test/jobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const testTableProjectId = 'bigquery-public-data';
const testDatasetId = 'san_francisco';
const testTableId = 'bikeshare_trips';
const testColumnName = 'zip_code';
const bucketName = 'nodejs-dlp-test-bucket';

const client = new DLP.DlpServiceClient();

Expand Down Expand Up @@ -156,4 +157,42 @@ describe('test', () => {
console.log(output);
assert.match(output, /Error in deleteJob/);
});

// dlp_create_job
it('should create job', () => {
const output = execSync(
`node createJob.js ${projectId} gs://${bucketName}/test.txt`
);
assert.match(output, /Job created successfully:/);
});

it('should handle job creation errors', () => {
let output;
try {
output = execSync(
`node createJob.js BAD_PROJECT_IDgs://${bucketName}/test.txt `
);
} catch (err) {
output = err.message;
}
assert.include(output, 'INVALID_ARGUMENT');
});

// dlp_get_job
it('should get job details using job name', async () => {
const jobName = await createTestJob();
const output = execSync(`node getJob.js ${jobName}`);
assert.match(output, /Job .+ status: \w/);
await client.deleteDlpJob({name: jobName});
});

it('should handle error while fetching job details', () => {
let output;
try {
output = execSync('node getJob.js INVALID_JOB');
} catch (err) {
output = err.message;
}
assert.include(output, 'INVALID_ARGUMENT');
});
});
2 changes: 1 addition & 1 deletion functions/billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Ace Nassri <anassri@google.com>",
"license": "Apache-2.0",
"dependencies": {
"@google-cloud/billing": "^3.0.0",
"@google-cloud/billing": "^4.0.0",
"@google-cloud/compute": "^3.1.0",
"google-auth-library": "^9.0.0",
"googleapis": "^123.0.0",
Expand Down
2 changes: 2 additions & 0 deletions functions/v2/helloGCS/test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// [START functions_cloudevent_storage_unit_test]
const {getFunction} = require('@google-cloud/functions-framework/testing');

describe('functions_cloudevent_storage', () => {
Expand Down Expand Up @@ -52,3 +53,4 @@ describe('functions_cloudevent_storage', () => {
assert(console.log.calledWith('File: my-file.txt'));
});
});
// [END functions_cloudevent_storage_unit_test]
62 changes: 62 additions & 0 deletions media/livestream/createAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright 2023 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, assetId, assetUri) {
// [START livestream_create_asset]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// assetId = 'my-asset';
// assetUri = 'gs://my-bucket/my-video.mp4';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function createAsset() {
// Construct request
const request = {
parent: livestreamServiceClient.locationPath(projectId, location),
assetId: assetId,
asset: {
video: {
uri: assetUri,
},
},
};

// Run request
const [operation] = await livestreamServiceClient.createAsset(request);
const response = await operation.promise();
const [asset] = response;
console.log(`Asset: ${asset.name}`);
}

createAsset();
// [END livestream_create_asset]
}

// node createAsset.js <projectId> <location> <assetId> <assetUri>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
54 changes: 54 additions & 0 deletions media/livestream/deleteAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright 2023 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, assetId) {
// [START livestream_delete_asset]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// assetId = 'my-asset';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function deleteAsset() {
// Construct request
const request = {
name: livestreamServiceClient.assetPath(projectId, location, assetId),
};

// Run request
const [operation] = await livestreamServiceClient.deleteAsset(request);
await operation.promise();
console.log('Deleted asset');
}

deleteAsset();
// [END livestream_delete_asset]
}

// node deleteAsset.js <projectId> <location> <assetId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/livestream/getAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2023 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, assetId) {
// [START livestream_get_asset]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// assetId = 'my-asset';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function getAsset() {
// Construct request
const request = {
name: livestreamServiceClient.assetPath(projectId, location, assetId),
};
const [asset] = await livestreamServiceClient.getAsset(request);
console.log(`Asset: ${asset.name}`);
}

getAsset();
// [END livestream_get_asset]
}

// node getAsset.js <projectId> <location> <assetId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Loading

0 comments on commit 3da20f0

Please sign in to comment.