Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: migrate code from googleapis/nodejs-dlp #3035

Merged
merged 176 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
1900ae8
DLP samples (#322)
Mar 9, 2017
7caf7de
Travis: fix failing tests + update dependencies (#335)
Apr 5, 2017
242ead6
Cleanup App Engine samples and re-work tests. (#354)
jmdobry Apr 24, 2017
52b9694
Upgrade to repo tools v1.4.7 (#370)
jmdobry May 2, 2017
2cb97b4
Upgrade repo tools and regenerate READMEs. (#384)
jmdobry May 10, 2017
f00874b
Upgrade repo tools and regenerate READMEs.
jmdobry May 16, 2017
13babeb
Add + run dependency updating (bash) script (#401)
Jun 19, 2017
92b4b4f
Move DLP from REST to gRPC + client libraries (#413)
Jun 30, 2017
d3970d5
Update + autogen README (#414)
Jun 30, 2017
dc56d22
Add DLP image redaction sample (Take 2) (#441)
Aug 2, 2017
86902b2
Add DLP quickstart + fix incorrect comments (#442)
Aug 4, 2017
5e575f4
Update dependencies + fix a few tests (#448)
Aug 5, 2017
87645e6
Build updates. (#462)
jmdobry Aug 23, 2017
091d519
Update dependencies (#468)
Aug 31, 2017
030e0cf
Add DLP samples (BigQuery, DeID, RiskAnalysis) (#474)
Oct 18, 2017
fa8ecdc
Repository Migration (#2)
lukesneeringer Oct 27, 2017
d92954f
Fix three-hour typo (#4)
Oct 28, 2017
520281b
Update sample dependencies (#5)
Oct 28, 2017
06f4904
Fix docs and regenerate scaffolding. (#7)
jmdobry Oct 30, 2017
9ee9326
Test on Node 9. (#8)
stephenplusplus Nov 15, 2017
ae2b575
Update dependencies to enable Greenkeeper 🌴 (#13)
greenkeeper[bot] Dec 6, 2017
23a238e
Clean up DLP region tags. (#26)
jmdobry Mar 7, 2018
76f2778
GAPIC v2 code, release 0.3.0 (#23)
alexander-fenster Mar 15, 2018
6b5e881
Fix sample tests and system tests (#29)
alexander-fenster Mar 16, 2018
2401004
Upgrade repo-tools and regenerate scaffolding. (#30)
jmdobry Mar 16, 2018
af00bc0
Fix invalid region code (#32)
Mar 20, 2018
ac44772
tests: fix risk samples tests (#33)
alexander-fenster Mar 20, 2018
0833cd7
chore: make samples depend on the current version (#34)
alexander-fenster Mar 20, 2018
392c146
Fix region tags (#36)
Mar 28, 2018
4525c4b
chore: bump version to 0.4.0 (#39)
alexander-fenster Mar 30, 2018
41d7472
bump version to 0.5.0 (#42)
crwilcox Apr 16, 2018
a56f5c9
Update redact test images (#43)
crwilcox Apr 17, 2018
9974d90
bump version to 0.6.0 (#46)
crwilcox Apr 26, 2018
0b3c3d7
chore: lock files maintenance (#47)
alexander-fenster May 2, 2018
7aca960
chore: lock files maintenance (#50)
alexander-fenster May 8, 2018
999bca0
test: skipping failing tests (#53)
alexander-fenster May 18, 2018
92a18c0
chore: lock files maintenance (#55)
alexander-fenster May 22, 2018
fe827e3
test: updated images for redact sample tests (#57)
alexander-fenster May 30, 2018
afd2c5a
fix: update linking for samples (#66)
JustinBeckwith Jun 25, 2018
34ffb7e
chore: update sample lockfiles (#68)
JustinBeckwith Jun 25, 2018
494fa69
refactor: drop repo-tool as an exec wrapper (#69)
JustinBeckwith Jun 26, 2018
cf1d975
fix(deps): update dependency yargs to v12 (#72)
renovate[bot] Jul 1, 2018
2fa40c5
chore(deps): lock file maintenance (#73)
renovate[bot] Jul 3, 2018
70f6429
Fix dlp code sample end/start tags for embedding (#76)
realjordanna Jul 3, 2018
32bedc6
chore: bump dlp to 0.7.0 (#75)
jkwlui Jul 3, 2018
4dc6cef
fix: update expected images for redact samples test (#78)
jkwlui Jul 3, 2018
9144dcd
chore(deps): lock file maintenance (#82)
renovate[bot] Jul 10, 2018
9196e61
chore(deps): lock file maintenance (#84)
renovate[bot] Jul 10, 2018
634fbee
chore(deps): lock file maintenance (#85)
renovate[bot] Jul 10, 2018
980e965
release: nodejs-dlp v0.8.0 (#89)
jkwlui Jul 12, 2018
69e49cf
chore(deps): lock file maintenance (#90)
renovate[bot] Jul 17, 2018
367bf26
chore(deps): lock file maintenance (#94)
renovate[bot] Jul 24, 2018
7f58375
fix: requiring samples/ node engine >7.6 because async/await was used…
jkwlui Jul 25, 2018
dd8fffa
chore(deps): lock file maintenance (#99)
renovate[bot] Jul 31, 2018
aea226e
feat: Add code samples for DLP text redaction (#61)
jmorrise Aug 6, 2018
4c738ae
chore(deps): lock file maintenance (#103)
renovate[bot] Aug 7, 2018
9bab80f
chore: ignore package-lock.json (#105)
JustinBeckwith Aug 7, 2018
bcebc72
DLP sample: Add autoPopulateTimespan option for creating job triggers…
micheldavid Aug 16, 2018
7716502
Release nodejs-dlp v0.9.0 (#113)
jkwlui Aug 21, 2018
fd4aa18
fix(deps): update dependency @google-cloud/pubsub to ^0.20.0 (#137)
renovate[bot] Sep 18, 2018
0bcf07b
Enable prefer-const in the eslint config (#141)
JustinBeckwith Sep 20, 2018
140cc83
tests: construct pubsub properly (#143)
alexander-fenster Sep 21, 2018
8f529ca
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v3 …
renovate[bot] Nov 10, 2018
5222ba9
fix(deps): update dependency @google-cloud/pubsub to ^0.21.0 (#183)
renovate[bot] Nov 16, 2018
57b2b7e
build: fix the lint rules (#187)
JustinBeckwith Nov 20, 2018
b2672a9
docs(samples): samples to use async/await (#190)
muraliQlogic Nov 21, 2018
413fb50
refactor(samples): convert sample tests from ava to mocha (#186)
nareshqlogic Nov 23, 2018
1f8b9d3
fix(deps): update dependency @google-cloud/pubsub to ^0.22.0 (#192)
renovate[bot] Dec 2, 2018
9c95491
samples: Added custom dictionary and regex code samples (#204)
mwdaub Dec 20, 2018
5e9bd21
Release v0.10.0 (#215)
jkwlui Jan 4, 2019
263a400
fix(samples-test): increase likelihood threshold (#222)
jkwlui Jan 25, 2019
3a4f668
fix(deps): update dependency @google-cloud/pubsub to ^0.23.0 (#219)
renovate[bot] Jan 25, 2019
59e0870
fix(deps): update dependency @google-cloud/pubsub to ^0.24.0 (#225)
renovate[bot] Jan 29, 2019
7b9c68f
refactor: modernize the sample tests (#237)
JustinBeckwith Feb 12, 2019
3d72c31
fix(deps): update dependency yargs to v13 (#235)
renovate[bot] Feb 14, 2019
24d91ae
fix(deps): update dependency @google-cloud/pubsub to ^0.25.0 (#244)
renovate[bot] Feb 26, 2019
7001cc6
chore(deps): update dependency mocha to v6
renovate[bot] Feb 26, 2019
4af4590
fix(test): increase minLikelihood option threshold to VERY_LIKELY (#248)
jkwlui Mar 5, 2019
608413f
fix(deps): update dependency @google-cloud/pubsub to ^0.27.0 (#246)
renovate[bot] Mar 5, 2019
7a324d4
fix(deps): update dependency @google-cloud/pubsub to ^0.28.0 (#253)
renovate[bot] Mar 12, 2019
8f4928d
Release v0.11.0 (#255)
JustinBeckwith Mar 12, 2019
2d50910
refactor: use execSync for tests (#262)
JustinBeckwith Apr 12, 2019
8b1dd40
Release v0.12.0 (#268)
bcoe Apr 26, 2019
51cb02a
fix(deps): update dependency @google-cloud/pubsub to ^0.29.0 (#283)
renovate[bot] May 17, 2019
70a36e7
chore: release 1.0.0 (#288)
yoshi-automation May 20, 2019
ffa3135
feat: auto-generate READMEs, add .repo-metdata.json (#293)
bcoe May 28, 2019
02cb3d4
chore: release 1.1.0 (#294)
yoshi-automation May 28, 2019
8e0641d
chore: release 1.2.0 (#300)
yoshi-automation Jun 6, 2019
f48d291
refactor: changes formatting of several statements
yoshi-automation Jun 7, 2019
bfbafa5
docs(samples): fix misleading comment (#304)
daniel-sanche Jun 12, 2019
4f4660a
chore(deps): update dependency pixelmatch to v5 (#303)
renovate[bot] Jun 14, 2019
752727e
chore: release 1.2.1 (#309)
yoshi-automation Jun 16, 2019
641a1f0
chore: release 1.3.0 (#312)
yoshi-automation Jun 19, 2019
b26f00e
chore: release 1.3.1 (#314)
yoshi-automation Jun 26, 2019
5b673ce
chore: release 1.4.0 (#318)
yoshi-automation Jul 9, 2019
78f32cb
tests: sample integration tests relied on deleted dataset (#334)
bcoe Sep 11, 2019
9c93dd5
fix(deps): update dependency yargs to v14 (#328)
renovate-bot Sep 11, 2019
deeddd8
chore(deps): update dependency @google-cloud/pubsub to ^0.32.0 (#327)
renovate-bot Sep 11, 2019
6c61cd0
chore: release 1.5.0 (#335)
yoshi-automation Sep 12, 2019
b1fce09
fix(deps): update dependency @google-cloud/pubsub to v1 (#339)
renovate-bot Sep 18, 2019
55c392e
chore: release 1.6.1 (#352)
release-please[bot] Oct 22, 2019
c867289
chore: release 1.7.0 (#359)
release-please[bot] Nov 15, 2019
9c28cd8
fix(deps): update dependency yargs to v15 (#361)
renovate-bot Nov 18, 2019
197af09
chore: release 1.7.1 (#362)
release-please[bot] Nov 18, 2019
99f4d7d
chore: update license headers
JustinBeckwith Nov 25, 2019
d64fefd
chore: release 1.8.0 (#366)
release-please[bot] Dec 5, 2019
f0ebfb7
refactor: use explicit mocha imports (#378)
JustinBeckwith Dec 30, 2019
d1e68b9
chore: release 1.9.0 (#379)
release-please[bot] Dec 31, 2019
0acf619
chore(deps): update dependency mocha to v7 (#384)
renovate-bot Jan 6, 2020
447199d
chore: release 2.0.0 (#394)
release-please[bot] Jan 28, 2020
ffc9131
chore: release 2.0.1 (#404)
release-please[bot] Feb 12, 2020
ade7a3a
chore(deps): update dependency uuid to v7
renovate-bot Feb 26, 2020
988d1b7
chore: release 2.1.0 (#411)
release-please[bot] Mar 2, 2020
655fddf
chore: release 2.2.0 (#421)
release-please[bot] Mar 11, 2020
a249f95
feat!: drop node8 support, support for async iterators (#440)
alexander-fenster Mar 31, 2020
13dae9d
fix: sample inspect customInfoTypes infoType name (#439)
beniceberg Mar 31, 2020
e7cd4d3
fix: remove eslint, update gax, fix generated protos, run the generat…
alexander-fenster Apr 12, 2020
51c0a61
chore(deps): update dependency pngjs to v4 (#447)
renovate-bot Apr 12, 2020
cfeddcc
chore: linting
yoshi-automation Apr 16, 2020
63d6ab5
chore(deps): update dependency pngjs to v5 (#459)
renovate-bot Apr 22, 2020
85adb16
chore(deps): update dependency uuid to v8 (#466)
renovate-bot May 1, 2020
48d55f3
fix(deps): update dependency @google-cloud/pubsub to v2 (#475)
renovate-bot May 26, 2020
e61feeb
chore: release 3.0.0 (#441)
release-please[bot] Jun 2, 2020
11b04e6
test: upstream breaking change broke tests (#484)
bcoe Jun 12, 2020
21f266f
chore(deps): update dependency mocha to v8 (#482)
renovate-bot Jun 12, 2020
9aac2c2
docs(samples): Added sample for deid with string replacement (#483)
ivanmed Jun 12, 2020
1519df5
chore: release 3.0.1 (#487)
release-please[bot] Jun 16, 2020
763ab39
fix(samples): include locations/global in parent field (#488)
sushicw Jun 23, 2020
c4a38e7
test: make redact image comparison less strict (#500)
alexander-fenster Jul 7, 2020
afd122e
chore: release 3.0.2 (#490)
release-please[bot] Jul 15, 2020
883a71b
chore: refactor all DLP samples and tests (#520)
sofisl Aug 12, 2020
124e5f2
test: address nightly flake (#535)
bcoe Sep 8, 2020
78f0420
fix(deps): update dependency yargs to v16 (#536)
renovate-bot Sep 9, 2020
64c7afb
chore: release 3.0.3 (#537)
release-please[bot] Sep 14, 2020
4e3f562
chore: release 3.0.4 (#549)
release-please[bot] Oct 16, 2020
dcd45bc
docs: add pattern reognition for running samples (#552)
sofisl Oct 20, 2020
424c42a
chore(deps): update dependency pngjs to v6 (#556)
renovate-bot Oct 26, 2020
e47645d
chore: release 3.0.5 (#561)
release-please[bot] Nov 16, 2020
8d17a03
chore: release 3.0.6 (#564)
release-please[bot] Dec 2, 2020
79ec9c9
chore: release 3.1.0 (#570)
release-please[bot] Jan 12, 2021
fe9776e
chore: release 3.1.1 (#607)
release-please[bot] May 13, 2021
85e7372
chore: release 3.1.2 (#616)
release-please[bot] May 25, 2021
d538c06
chore: release 3.1.3 (#624)
release-please[bot] Jun 22, 2021
19a8015
chore: release 3.1.4 (#630)
release-please[bot] Jun 29, 2021
91b1dcd
chore: release 3.1.5 (#633)
release-please[bot] Jul 12, 2021
d38937b
chore: release 3.1.6 (#635)
release-please[bot] Jul 16, 2021
b1ed064
chore: release 3.1.7 (#643)
release-please[bot] Aug 13, 2021
fe248a2
chore: release 3.1.8 (#645)
release-please[bot] Aug 17, 2021
da50af4
chore: release 3.2.0 (#647)
release-please[bot] Aug 23, 2021
1de7176
docs(samples): add auto-generated Node samples (#656)
gcf-owl-bot[bot] Sep 24, 2021
8dccbd1
fix(deps): update dependency mime to v3 (#663)
renovate-bot Nov 3, 2021
b9e6ba0
chore: release 3.2.1 (#664)
release-please[bot] Nov 3, 2021
34e83db
docs(samples): removed test console logs (#662)
Sita04 Nov 3, 2021
8281bf3
chore: release 3.3.0 (#668)
release-please[bot] Dec 3, 2021
5df2217
docs(samples): modified region tag to align with other snippets (#687)
Sita04 Feb 19, 2022
22fe8d9
chore(main): release 3.4.0 (#694)
release-please[bot] Mar 25, 2022
5ebdf1e
chore(main): release 3.5.0 (#696)
release-please[bot] Apr 1, 2022
676edb1
build!: update library to use Node 12 (#713)
sofisl May 20, 2022
de93e7b
chore(main): release 4.0.0 (#714)
release-please[bot] Jun 6, 2022
15c877f
fix(deps): update dependency @google-cloud/pubsub to v3 (#715)
renovate-bot Jun 7, 2022
5d4129b
chore(main): release 4.0.1 (#717)
release-please[bot] Jun 7, 2022
e3b94b7
build: fix sample test (#721)
sofisl Jun 16, 2022
7e0365d
build: increase retries for dlp test (#723)
sofisl Jun 29, 2022
a849bd9
chore(main): release 4.0.2 (#725)
release-please[bot] Jul 4, 2022
9ed7e38
chore(main): release 4.1.0 (#729)
release-please[bot] Jul 12, 2022
5854387
test: fix sample test for listJobs (#734)
alexander-fenster Aug 19, 2022
bedcd1a
chore(main): release 4.1.1 (#737)
release-please[bot] Sep 8, 2022
0174bc1
chore(deps): update dependency uuid to v9 (#744)
renovate-bot Sep 9, 2022
7d1bfdc
chore(main): release 4.2.0 (#745)
release-please[bot] Sep 26, 2022
1793f7c
chore(main): release 4.3.0 (#778)
release-please[bot] Jan 6, 2023
a6fd652
Merge remote-tracking branch 'migration/main' into nodejs-dlp-migration
Shabirmean Feb 16, 2023
0424092
test: add github actions for migrated samples
Shabirmean Feb 16, 2023
d564b79
chore: add dee-infra as codeowners
Shabirmean Feb 16, 2023
ad775a1
cleanup: remove assessed sample
Shabirmean Feb 16, 2023
889f0c9
cleanup: fix region-tag mismatch
Shabirmean Feb 16, 2023
2fb1355
cleanup: remove unused test files
Shabirmean Feb 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/dlp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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.

name: dlp
on:
push:
branches:
- main
paths:
- 'dlp/**'
- '.github/workflows/dlp.yaml'
pull_request:
paths:
- 'dlp/**'
- '.github/workflows/dlp.yaml'
pull_request_target:
types: [labeled]
paths:
- 'dlp/**'
- '.github/workflows/dlp.yaml'
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/checkout@v3.1.0
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: 'google-github-actions/auth@v1.0.0'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/setup-node@v3.5.1
with:
node-version: 16
- run: npm install
working-directory: dlp
- run: npm test
working-directory: dlp
env:
MOCHA_REPORTER_SUITENAME: dlp
MOCHA_REPORTER_OUTPUT: dlp_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule' && always() }}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"datastore/functions",
"dialogflow",
"dialogflow-cx",
"dlp",
"document-ai",
"endpoints/getting-started",
"endpoints/getting-started-grpc",
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ secret-manager @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-sample
security-center @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers
service-directory @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers
webrisk @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers
dlp @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers

# DEE Platform Ops (DEEPO)
container @GoogleCloudPlatform/dee-platform-ops @GoogleCloudPlatform/nodejs-samples-reviewers
Expand Down
5 changes: 5 additions & 0 deletions dlp/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
no-console: off
no-warning-comments: off
node/no-missing-require: off
3 changes: 3 additions & 0 deletions dlp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test outputs
*.actual.png
*.actual.csv
160 changes: 160 additions & 0 deletions dlp/categoricalRiskAnalysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright 2020 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: Categorical Risk Analysis
// description: Computes risk metrics of a column of data in a Google BigQuery table.
// usage: node categoricalRiskAnalysis.js my-project nhtsa_traffic_fatalities accident_2015 state_name my-topic my-subscription bigquery-public-data

function main(
projectId,
tableProjectId,
datasetId,
tableId,
columnName,
topicId,
subscriptionId
) {
// [START dlp_categorical_stats]
// Import the Google Cloud client libraries
const DLP = require('@google-cloud/dlp');
const {PubSub} = require('@google-cloud/pubsub');

// Instantiates clients
const dlp = new DLP.DlpServiceClient();
const pubsub = new PubSub();

// The project ID to run the API call under
// const projectId = 'my-project';

// The project ID the table is stored under
// This may or (for public datasets) may not equal the calling project ID
// const tableProjectId = 'my-project';

// The ID of the dataset to inspect, e.g. 'my_dataset'
// const datasetId = 'my_dataset';

// The ID of the table to inspect, e.g. 'my_table'
// const tableId = 'my_table';

// The name of the Pub/Sub topic to notify once the job completes
// TODO(developer): create a Pub/Sub topic to use for this
// const topicId = 'MY-PUBSUB-TOPIC'

// The name of the Pub/Sub subscription to use when listening for job
// completion notifications
// TODO(developer): create a Pub/Sub subscription to use for this
// const subscriptionId = 'MY-PUBSUB-SUBSCRIPTION'

// The name of the column to compute risk metrics for, e.g. 'firstName'
// const columnName = 'firstName';
async function categoricalRiskAnalysis() {
const sourceTable = {
projectId: tableProjectId,
datasetId: datasetId,
tableId: tableId,
};

// Construct request for creating a risk analysis job
const request = {
parent: `projects/${projectId}/locations/global`,
riskJob: {
privacyMetric: {
categoricalStatsConfig: {
field: {
name: columnName,
},
},
},
sourceTable: sourceTable,
actions: [
{
pubSub: {
topic: `projects/${projectId}/topics/${topicId}`,
},
},
],
},
};

// Create helper function for unpacking values
const getValue = obj => obj[Object.keys(obj)[0]];

// Run risk analysis job
const [topicResponse] = await pubsub.topic(topicId).get();
const subscription = await topicResponse.subscription(subscriptionId);
const [jobsResponse] = await dlp.createDlpJob(request);
const jobName = jobsResponse.name;
// Watch the Pub/Sub topic until the DLP job finishes
await new Promise((resolve, reject) => {
const messageHandler = message => {
if (message.attributes && message.attributes.DlpJobName === jobName) {
message.ack();
subscription.removeListener('message', messageHandler);
subscription.removeListener('error', errorHandler);
resolve(jobName);
} else {
message.nack();
}
};

const errorHandler = err => {
subscription.removeListener('message', messageHandler);
subscription.removeListener('error', errorHandler);
reject(err);
};

subscription.on('message', messageHandler);
subscription.on('error', errorHandler);
});
setTimeout(() => {
console.log(' Waiting for DLP job to fully complete');
}, 500);
const [job] = await dlp.getDlpJob({name: jobName});
const histogramBuckets =
job.riskDetails.categoricalStatsResult.valueFrequencyHistogramBuckets;
histogramBuckets.forEach((histogramBucket, histogramBucketIdx) => {
console.log(`Bucket ${histogramBucketIdx}:`);

// Print bucket stats
console.log(
` Most common value occurs ${histogramBucket.valueFrequencyUpperBound} time(s)`
);
console.log(
` Least common value occurs ${histogramBucket.valueFrequencyLowerBound} time(s)`
);

// Print bucket values
console.log(`${histogramBucket.bucketSize} unique values total.`);
histogramBucket.bucketValues.forEach(valueBucket => {
console.log(
` Value ${getValue(valueBucket.value)} occurs ${
valueBucket.count
} time(s).`
);
});
});
}

categoricalRiskAnalysis();
// [END dlp_categorical_stats]
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
102 changes: 102 additions & 0 deletions dlp/createInspectTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020 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: Inspect Templates
// description: Create a new DLP inspection configuration template.
// usage: node createInspectTemplate.js my-project VERY_LIKELY PERSON_NAME 5 false my-template-id

function main(
projectId,
templateId,
displayName,
infoTypes,
includeQuote,
minLikelihood,
maxFindings
) {
infoTypes = transformCLI(infoTypes);
// [START dlp_create_inspect_template]
// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

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

// The project ID to run the API call under
// const projectId = 'my-project';

// The minimum likelihood required before returning a match
// const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';

// The maximum number of findings to report per request (0 = server maximum)
// const maxFindings = 0;

// The infoTypes of information to match
// const infoTypes = [{ name: 'PHONE_NUMBER' }, { name: 'EMAIL_ADDRESS' }, { name: 'CREDIT_CARD_NUMBER' }];

// Whether to include the matching string
// const includeQuote = true;

// (Optional) The name of the template to be created.
// const templateId = 'my-template';

// (Optional) The human-readable name to give the template
// const displayName = 'My template';

async function createInspectTemplate() {
// Construct the inspection configuration for the template
const inspectConfig = {
infoTypes: infoTypes,
minLikelihood: minLikelihood,
includeQuote: includeQuote,
limits: {
maxFindingsPerRequest: maxFindings,
},
};

// Construct template-creation request
const request = {
parent: `projects/${projectId}/locations/global`,
inspectTemplate: {
inspectConfig: inspectConfig,
displayName: displayName,
},
templateId: templateId,
};

const [response] = await dlp.createInspectTemplate(request);
const templateName = response.name;
console.log(`Successfully created template ${templateName}.`);
}
createInspectTemplate();
// [END dlp_create_inspect_template]
}

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

function transformCLI(infoTypes) {
infoTypes = infoTypes
? infoTypes.split(',').map(type => {
return {name: type};
})
: undefined;
return infoTypes;
}
Loading