diff --git a/packages/dlp/README.md b/packages/dlp/README.md new file mode 100644 index 00000000000..e6de4d11497 --- /dev/null +++ b/packages/dlp/README.md @@ -0,0 +1,25 @@ +# Node.js Client for DLP API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning)) + +[DLP API][Product Documentation]: The Google Data Loss Prevention API provides methods for detection of privacy-sensitive fragments in text, images, and Google Cloud Platform storage repositories. +- [Client Library Documentation][] +- [Product Documentation][] + +## Quick Start +In order to use this library, you first need to go through the following steps: + +1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) +2. [Enable the DLP API.](https://console.cloud.google.com/apis/api/dlp) +3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication) + +### Installation +``` +$ npm install --save @google-cloud/dlp +``` + +### Next Steps +- Read the [Client Library Documentation][] for DLP API to see other available methods on the client. +- Read the [DLP API Product documentation][Product Documentation] to learn more about the product and see How-to Guides. +- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover. + +[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/dlp +[Product Documentation]: https://cloud.google.com/dlp \ No newline at end of file diff --git a/packages/dlp/package.json b/packages/dlp/package.json new file mode 100644 index 00000000000..ce503ca9581 --- /dev/null +++ b/packages/dlp/package.json @@ -0,0 +1,44 @@ +{ + "repository": "GoogleCloudPlatform/google-cloud-node", + "name": "@google-cloud/dlp", + "version": "0.0.0", + "author": "Google Inc", + "description": "DLP API client for Node.js", + "main": "src/index.js", + "files": [ + "src", + "AUTHORS", + "CONTRIBUTING", + "COPYING" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google dlp", + "dlp", + "DLP API" + ], + "dependencies": { + "google-proto-files": "^0.12.0", + "google-gax": "^0.13.2", + "extend": "^3.0.0" + }, + "devDependencies": { + "mocha": "^3.2.0", + "through2": "^2.0.3" + }, + "scripts": { + "test": "mocha", + "publish-module": "node ../../scripts/publish.js dlp" + }, + "license": "Apache-2.0", + "engines": { + "node": ">=4.0.0" + } +} diff --git a/packages/dlp/src/index.js b/packages/dlp/src/index.js new file mode 100644 index 00000000000..922d1d7e10b --- /dev/null +++ b/packages/dlp/src/index.js @@ -0,0 +1,55 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * 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'; + +var extend = require('extend'); +var gapic = { + v2beta1: require('./v2beta1') +}; + +const VERSION = require('../package.json').version; + +/** + * Create an dlpServiceClient with additional helpers for common + * tasks. + * + * The DLP API is a service that allows clients + * to detect the presence of Personally Identifiable Information (PII) and other + * privacy-sensitive data in user-supplied, unstructured data streams, like text + * blocks or images. + * The service also includes methods for sensitive data redaction and + * scheduling of data scans on Google Cloud Platform based data sets. + * + * @param {object=} options - [Configuration object](#/docs). + * @param {number=} options.port - The port on which to connect to + * the remote host. + * @param {string=} options.servicePath - The domain name of the + * API remote host. + */ +function dlpV2beta1(options) { + // Define the header options. + options = extend({}, options, { + libName: 'gccl', + libVersion: VERSION + }); + + // Create the image annotator client with the provided options. + var client = gapic.v2beta1(options).dlpServiceClient(options); + return client; +} + +module.exports = dlpV2beta1; +module.exports.v2beta1 = dlpV2beta1; \ No newline at end of file diff --git a/packages/dlp/src/v2beta1/dlp_service_client.js b/packages/dlp/src/v2beta1/dlp_service_client.js new file mode 100644 index 00000000000..d9225aaf614 --- /dev/null +++ b/packages/dlp/src/v2beta1/dlp_service_client.js @@ -0,0 +1,567 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * 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. + * + * EDITING INSTRUCTIONS + * This file was generated from the file + * https://github.com/googleapis/googleapis/blob/master/google/privacy/dlp/v2beta1/dlp.proto, + * and updates to that file get reflected here through a refresh process. + * For the short term, the refresh process will only be runnable by Google + * engineers. + * + * The only allowed edits are to method and file documentation. A 3-way + * merge preserves those additions if the generated source changes. + */ +/* TODO: introduce line-wrapping so that it never exceeds the limit. */ +/* jscs: disable maximumLineLength */ +'use strict'; + +var configData = require('./dlp_service_client_config'); +var extend = require('extend'); +var gax = require('google-gax'); + +var SERVICE_ADDRESS = 'dlp.googleapis.com'; + +var DEFAULT_SERVICE_PORT = 443; + +var CODE_GEN_NAME_VERSION = 'gapic/0.0.0'; + +/** + * The scopes needed to make gRPC calls to all of the methods defined in + * this service. + */ +var ALL_SCOPES = [ + 'https://www.googleapis.com/auth/cloud-platform' +]; + +/** + * The DLP API is a service that allows clients + * to detect the presence of Personally Identifiable Information (PII) and other + * privacy-sensitive data in user-supplied, unstructured data streams, like text + * blocks or images. + * The service also includes methods for sensitive data redaction and + * scheduling of data scans on Google Cloud Platform based data sets. + * + * This will be created through a builder function which can be obtained by the module. + * See the following example of how to initialize the module and how to access to the builder. + * @see {@link dlpServiceClient} + * + * @example + * var dlpV2beta1 = require('@google-cloud/dlp').v2beta1({ + * // optional auth parameters. + * }); + * var client = dlpV2beta1.dlpServiceClient(); + * + * @class + */ +function DlpServiceClient(gaxGrpc, grpcClients, opts) { + opts = extend({ + servicePath: SERVICE_ADDRESS, + port: DEFAULT_SERVICE_PORT, + clientConfig: {} + }, opts); + + var googleApiClient = [ + 'gl-node/' + process.versions.node + ]; + if (opts.libName && opts.libVersion) { + googleApiClient.push(opts.libName + '/' + opts.libVersion); + } + googleApiClient.push( + CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, + 'grpc/' + gaxGrpc.grpcVersion + ); + + this.operationsClient = new gax.lro({ + auth: gaxGrpc.auth, + grpc: gaxGrpc.grpc + }).operationsClient(opts); + + this.longrunningDescriptors = { + createInspectOperation: new gax.LongrunningDescriptor( + this.operationsClient, + grpcClients.google.privacy.dlp.v2beta1.InspectOperationResult.decode, + grpcClients.google.privacy.dlp.v2beta1.InspectOperationMetadata.decode) + }; + + var defaults = gaxGrpc.constructSettings( + 'google.privacy.dlp.v2beta1.DlpService', + configData, + opts.clientConfig, + {'x-goog-api-client': googleApiClient.join(' ')}); + + var self = this; + + this.auth = gaxGrpc.auth; + var dlpServiceStub = gaxGrpc.createStub( + grpcClients.google.privacy.dlp.v2beta1.DlpService, + opts); + var dlpServiceStubMethods = [ + 'inspectContent', + 'redactContent', + 'createInspectOperation', + 'listInspectFindings', + 'listInfoTypes', + 'listRootCategories' + ]; + dlpServiceStubMethods.forEach(function(methodName) { + self['_' + methodName] = gax.createApiCall( + dlpServiceStub.then(function(dlpServiceStub) { + return function() { + var args = Array.prototype.slice.call(arguments, 0); + return dlpServiceStub[methodName].apply(dlpServiceStub, args); + }; + }), + defaults[methodName], + self.longrunningDescriptors[methodName]); + }); +} + +// Path templates + +var RESULT_PATH_TEMPLATE = new gax.PathTemplate( + 'inspect/results/{result}'); + +/** + * Returns a fully-qualified result resource name string. + * @param {String} result + * @returns {String} + */ +DlpServiceClient.prototype.resultPath = function(result) { + return RESULT_PATH_TEMPLATE.render({ + result: result + }); +}; + +/** + * Parses the resultName from a result resource. + * @param {String} resultName + * A fully-qualified path representing a result resources. + * @returns {String} - A string representing the result. + */ +DlpServiceClient.prototype.matchResultFromResultName = function(resultName) { + return RESULT_PATH_TEMPLATE.match(resultName).result; +}; + +/** + * Get the project ID used by this class. + * @param {function(Error, string)} callback - the callback to be called with + * the current project Id. + */ +DlpServiceClient.prototype.getProjectId = function(callback) { + return this.auth.getProjectId(callback); +}; + +// Service calls + +/** + * Find potentially sensitive info in a list of strings. + * This method has limits on input size, processing time, and output size. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.inspectConfig + * Configuration for the inspector. + * + * This object should have the same structure as [InspectConfig]{@link InspectConfig} + * @param {Object[]} request.items + * The list of items to inspect. Items in a single request are + * considered "related" unless inspect_config.independent_inputs is true. + * Up to 100 are allowed per request. + * + * This object should have the same structure as [ContentItem]{@link ContentItem} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [InspectContentResponse]{@link InspectContentResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [InspectContentResponse]{@link InspectContentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var inspectConfig = {}; + * var items = []; + * var request = { + * inspectConfig: inspectConfig, + * items: items + * }; + * client.inspectContent(request).then(function(responses) { + * var response = responses[0]; + * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.inspectContent = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._inspectContent(request, options, callback); +}; + +/** + * Redact potentially sensitive info from a list of strings. + * This method has limits on input size, processing time, and output size. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.inspectConfig + * Configuration for the inspector. + * + * This object should have the same structure as [InspectConfig]{@link InspectConfig} + * @param {Object[]} request.items + * The list of items to inspect. Up to 100 are allowed per request. + * + * This object should have the same structure as [ContentItem]{@link ContentItem} + * @param {Object[]} request.replaceConfigs + * The strings to replace findings with. Must specify at least one. + * + * This object should have the same structure as [ReplaceConfig]{@link ReplaceConfig} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [RedactContentResponse]{@link RedactContentResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [RedactContentResponse]{@link RedactContentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var inspectConfig = {}; + * var items = []; + * var replaceConfigs = []; + * var request = { + * inspectConfig: inspectConfig, + * items: items, + * replaceConfigs: replaceConfigs + * }; + * client.redactContent(request).then(function(responses) { + * var response = responses[0]; + * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.redactContent = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._redactContent(request, options, callback); +}; + +/** + * Schedule a job scanning content in a Google Cloud Platform data repository. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.inspectConfig + * Configuration for the inspector. + * + * This object should have the same structure as [InspectConfig]{@link InspectConfig} + * @param {Object} request.storageConfig + * Specification of the data set to process. + * + * This object should have the same structure as [StorageConfig]{@link StorageConfig} + * @param {Object} request.outputConfig + * Optional location to store findings. The bucket must already exist and + * the Google APIs service account for DLP must have write permission to + * write to the given bucket. + * Results will be split over multiple csv files with each file name matching + * the pattern "[operation_id] + [count].csv". + * The operation_id will match the identifier for the Operation, + * and the [count] is a counter used for tracking the number of files written. + * The CSV file(s) contain the following columns regardless of storage type + * scanned: id, info_type, likelihood, byte size of finding, quote, time_stamp + * For cloud storage the next two columns are: file_path, start_offset + * For datastore the next two columns are: project_id, namespace_id, path, + * column_name, offset. + * + * This object should have the same structure as [OutputStorageConfig]{@link OutputStorageConfig} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var inspectConfig = {}; + * var storageConfig = {}; + * var outputConfig = {}; + * var request = { + * inspectConfig: inspectConfig, + * storageConfig: storageConfig, + * outputConfig: outputConfig + * }; + * + * // Handle the operation using the promise pattern. + * client.createInspectOperation(request).then(function(responses) { + * var operation = responses[0]; + * var initialApiResponse = responses[1]; + * + * // Operation#promise starts polling for the completion of the LRO. + * return operation.promise(); + * }).then(function(responses) { + * // The final result of the operation. + * var result = responses[0]; + * + * // The metadata value of the completed operation. + * var metadata = responses[1]; + * + * // The response of the api call returning the complete operation. + * var finalApiResponse = responses[2]; + * }).catch(function(err) { + * console.error(err); + * }); + * + * // Handle the operation using the event emitter pattern. + * client.createInspectOperation(request).then(function(responses) { + * var operation = responses[0]; + * var initialApiResponse = responses[1]; + * + * // Adding a listener for the "complete" event starts polling for the + * // completion of the operation. + * operation.on('complete', function(result, metadata, finalApiResponse) { + * // doSomethingWith(result); + * }); + * + * // Adding a listener for the "progress" event causes the callback to be + * // called on any change in metadata when the operation is polled. + * operation.on('progress', function(metadata, apiResponse) { + * // doSomethingWith(metadata) + * }) + * + * // Adding a listener for the "error" event handles any errors found during polling. + * operation.on('error', function(err) { + * // throw(err); + * }) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.createInspectOperation = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._createInspectOperation(request, options, callback); +}; + +/** + * Returns list of results for given inspect operation result set id. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Identifier of the results set returned as metadata of + * the longrunning operation created by a call to CreateInspectOperation. + * Should be in the format of `inspect/results/{id}. + * @param {number=} request.pageSize + * Maximum number of results to return. + * If 0, the implementation will select a reasonable value. + * @param {string=} request.pageToken + * The value returned by the last `ListInspectFindingsResponse`; indicates + * that this is a continuation of a prior `ListInspectFindings` call, and that + * the system should return the next page of data. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [ListInspectFindingsResponse]{@link ListInspectFindingsResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [ListInspectFindingsResponse]{@link ListInspectFindingsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var formattedName = client.resultPath("[RESULT]"); + * client.listInspectFindings({name: formattedName}).then(function(responses) { + * var response = responses[0]; + * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.listInspectFindings = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._listInspectFindings(request, options, callback); +}; + +/** + * Returns sensitive information types for given category. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.category + * Category name as returned by ListRootCategories. + * @param {string} request.languageCode + * Optional BCP-47 language code for localized info type friendly + * names. If omitted, or if localized strings are not available, + * en-US strings will be returned. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [ListInfoTypesResponse]{@link ListInfoTypesResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [ListInfoTypesResponse]{@link ListInfoTypesResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var category = ''; + * var languageCode = ''; + * var request = { + * category: category, + * languageCode: languageCode + * }; + * client.listInfoTypes(request).then(function(responses) { + * var response = responses[0]; + * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.listInfoTypes = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._listInfoTypes(request, options, callback); +}; + +/** + * Returns the list of root categories of sensitive information. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.languageCode + * Optional language code for localized friendly category names. + * If omitted or if localized strings are not available, + * en-US strings will be returned. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [ListRootCategoriesResponse]{@link ListRootCategoriesResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [ListRootCategoriesResponse]{@link ListRootCategoriesResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * var client = dlpV2beta1.dlpServiceClient(); + * var languageCode = ''; + * client.listRootCategories({languageCode: languageCode}).then(function(responses) { + * var response = responses[0]; + * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); + * }); + */ +DlpServiceClient.prototype.listRootCategories = function(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + + return this._listRootCategories(request, options, callback); +}; + +function DlpServiceClientBuilder(gaxGrpc) { + if (!(this instanceof DlpServiceClientBuilder)) { + return new DlpServiceClientBuilder(gaxGrpc); + } + + var dlpServiceClient = gaxGrpc.load([{ + root: require('google-proto-files')('..'), + file: 'google/privacy/dlp/v2beta1/dlp.proto' + }]); + extend(this, dlpServiceClient.google.privacy.dlp.v2beta1); + + + /** + * Build a new instance of {@link DlpServiceClient}. + * + * @param {Object=} opts - The optional parameters. + * @param {String=} opts.servicePath + * The domain name of the API remote host. + * @param {number=} opts.port + * The port on which to connect to the remote host. + * @param {grpc.ClientCredentials=} opts.sslCreds + * A ClientCredentials for use with an SSL-enabled channel. + * @param {Object=} opts.clientConfig + * The customized config to build the call settings. See + * {@link gax.constructSettings} for the format. + */ + this.dlpServiceClient = function(opts) { + return new DlpServiceClient(gaxGrpc, dlpServiceClient, opts); + }; + extend(this.dlpServiceClient, DlpServiceClient); +} +module.exports = DlpServiceClientBuilder; +module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; +module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file diff --git a/packages/dlp/src/v2beta1/dlp_service_client_config.json b/packages/dlp/src/v2beta1/dlp_service_client_config.json new file mode 100644 index 00000000000..0e7d58accfe --- /dev/null +++ b/packages/dlp/src/v2beta1/dlp_service_client_config.json @@ -0,0 +1,58 @@ +{ + "interfaces": { + "google.privacy.dlp.v2beta1.DlpService": { + "retry_codes": { + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "non_idempotent": [ + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "InspectContent": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "RedactContent": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "CreateInspectOperation": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListInspectFindings": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListInfoTypes": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListRootCategories": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/packages/dlp/src/v2beta1/index.js b/packages/dlp/src/v2beta1/index.js new file mode 100644 index 00000000000..f81ac094648 --- /dev/null +++ b/packages/dlp/src/v2beta1/index.js @@ -0,0 +1,34 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * 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'; + +var dlpServiceClient = require('./dlp_service_client'); +var gax = require('google-gax'); +var extend = require('extend'); + +function v2beta1(options) { + options = extend({ + scopes: v2beta1.ALL_SCOPES + }, options); + var gaxGrpc = gax.grpc(options); + return dlpServiceClient(gaxGrpc); +} + +v2beta1.GAPIC_VERSION = '0.0.0'; +v2beta1.SERVICE_ADDRESS = dlpServiceClient.SERVICE_ADDRESS; +v2beta1.ALL_SCOPES = dlpServiceClient.ALL_SCOPES; + +module.exports = v2beta1; \ No newline at end of file diff --git a/packages/dlp/test/gapic-v2beta1.js b/packages/dlp/test/gapic-v2beta1.js new file mode 100644 index 00000000000..af2b9a0e078 --- /dev/null +++ b/packages/dlp/test/gapic-v2beta1.js @@ -0,0 +1,341 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * 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'; + +var assert = require('assert'); +var dlpV2beta1 = require('../src/v2beta1')(); + +var FAKE_STATUS_CODE = 1; +var error = new Error(); +error.code = FAKE_STATUS_CODE; +describe('DlpServiceClient', function() { + describe('inspectContent', function() { + it('invokes inspectContent without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var items = []; + var request = { + inspectConfig : inspectConfig, + items : items + }; + + // Mock response + var expectedResponse = {}; + + // Mock Grpc layer + client._inspectContent = mockSimpleGrpcMethod(request, expectedResponse); + + client.inspectContent(request, function(err, response) { + assert.ifError(err); + assert.deepStrictEqual(response, expectedResponse); + done(); + }); + }); + + it('invokes inspectContent with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var items = []; + var request = { + inspectConfig : inspectConfig, + items : items + }; + + // Mock Grpc layer + client._inspectContent = mockSimpleGrpcMethod(request, null, error); + + client.inspectContent(request, function(err, response) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + + describe('redactContent', function() { + it('invokes redactContent without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var items = []; + var replaceConfigs = []; + var request = { + inspectConfig : inspectConfig, + items : items, + replaceConfigs : replaceConfigs + }; + + // Mock response + var expectedResponse = {}; + + // Mock Grpc layer + client._redactContent = mockSimpleGrpcMethod(request, expectedResponse); + + client.redactContent(request, function(err, response) { + assert.ifError(err); + assert.deepStrictEqual(response, expectedResponse); + done(); + }); + }); + + it('invokes redactContent with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var items = []; + var replaceConfigs = []; + var request = { + inspectConfig : inspectConfig, + items : items, + replaceConfigs : replaceConfigs + }; + + // Mock Grpc layer + client._redactContent = mockSimpleGrpcMethod(request, null, error); + + client.redactContent(request, function(err, response) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + + describe('createInspectOperation', function() { + it('invokes createInspectOperation without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var storageConfig = {}; + var outputConfig = {}; + var request = { + inspectConfig : inspectConfig, + storageConfig : storageConfig, + outputConfig : outputConfig + }; + + // Mock response + var name = 'name3373707'; + var expectedResponse = { + name : name + }; + + // Mock Grpc layer + client._createInspectOperation = mockLongRunningGrpcMethod(request, expectedResponse); + + client.createInspectOperation(request).then(function(responses) { + var operation = responses[0]; + return operation.promise(); + }).then(function(responses) { + assert.deepStrictEqual(responses[0], expectedResponse); + done(); + }).catch(function(err) { + done(err); + }); + }); + + it('invokes createInspectOperation with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var inspectConfig = {}; + var storageConfig = {}; + var outputConfig = {}; + var request = { + inspectConfig : inspectConfig, + storageConfig : storageConfig, + outputConfig : outputConfig + }; + + // Mock Grpc layer + client._createInspectOperation = mockLongRunningGrpcMethod(request, null, error); + + client.createInspectOperation(request).then(function(responses) { + var operation = responses[0]; + return operation.promise(); + }).then(function(responses) { + assert.fail(); + }).catch(function(err) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + + describe('listInspectFindings', function() { + it('invokes listInspectFindings without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var formattedName = client.resultPath("[RESULT]"); + var request = { + name : formattedName + }; + + // Mock response + var nextPageToken = 'nextPageToken-1530815211'; + var expectedResponse = { + nextPageToken : nextPageToken + }; + + // Mock Grpc layer + client._listInspectFindings = mockSimpleGrpcMethod(request, expectedResponse); + + client.listInspectFindings(request, function(err, response) { + assert.ifError(err); + assert.deepStrictEqual(response, expectedResponse); + done(); + }); + }); + + it('invokes listInspectFindings with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var formattedName = client.resultPath("[RESULT]"); + var request = { + name : formattedName + }; + + // Mock Grpc layer + client._listInspectFindings = mockSimpleGrpcMethod(request, null, error); + + client.listInspectFindings(request, function(err, response) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + + describe('listInfoTypes', function() { + it('invokes listInfoTypes without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var category = 'category50511102'; + var languageCode = 'languageCode-412800396'; + var request = { + category : category, + languageCode : languageCode + }; + + // Mock response + var expectedResponse = {}; + + // Mock Grpc layer + client._listInfoTypes = mockSimpleGrpcMethod(request, expectedResponse); + + client.listInfoTypes(request, function(err, response) { + assert.ifError(err); + assert.deepStrictEqual(response, expectedResponse); + done(); + }); + }); + + it('invokes listInfoTypes with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var category = 'category50511102'; + var languageCode = 'languageCode-412800396'; + var request = { + category : category, + languageCode : languageCode + }; + + // Mock Grpc layer + client._listInfoTypes = mockSimpleGrpcMethod(request, null, error); + + client.listInfoTypes(request, function(err, response) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + + describe('listRootCategories', function() { + it('invokes listRootCategories without error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var languageCode = 'languageCode-412800396'; + var request = { + languageCode : languageCode + }; + + // Mock response + var expectedResponse = {}; + + // Mock Grpc layer + client._listRootCategories = mockSimpleGrpcMethod(request, expectedResponse); + + client.listRootCategories(request, function(err, response) { + assert.ifError(err); + assert.deepStrictEqual(response, expectedResponse); + done(); + }); + }); + + it('invokes listRootCategories with error', function(done) { + var client = dlpV2beta1.dlpServiceClient(); + // Mock request + var languageCode = 'languageCode-412800396'; + var request = { + languageCode : languageCode + }; + + // Mock Grpc layer + client._listRootCategories = mockSimpleGrpcMethod(request, null, error); + + client.listRootCategories(request, function(err, response) { + assert(err instanceof Error); + assert.equal(err.code, FAKE_STATUS_CODE); + done(); + }); + }); + }); + +}); + +function mockSimpleGrpcMethod(expectedRequest, response, error) { + return function(actualRequest, options, callback) { + assert.deepStrictEqual(actualRequest, expectedRequest); + if (error) { + callback(error); + } else if (response) { + callback(null, response); + } else { + callback(null); + } + }; +} + +function mockLongRunningGrpcMethod(expectedRequest, response, error) { + return function(request) { + assert.deepStrictEqual(request, expectedRequest); + var mockOperation = { + promise: function() { + return new Promise(function(resolve, reject) { + if (error) { + reject(error); + } else { + resolve([response]); + } + }); + } + }; + return Promise.resolve([mockOperation]); + }; +} diff --git a/scripts/docs/config.js b/scripts/docs/config.js index 674daf0a350..0f70f676fe7 100644 --- a/scripts/docs/config.js +++ b/scripts/docs/config.js @@ -63,6 +63,9 @@ module.exports = { datastore: { title: 'Cloud Datastore' }, + dlp: { + title: 'DLP API' + }, dns: { title: 'Cloud DNS' }, diff --git a/scripts/helpers.js b/scripts/helpers.js index c1ac5c90c3a..ba1cb63a9c2 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -239,6 +239,7 @@ Module.prototype.runSystemTests = function() { var modulesExcludedFromSystemTests = [ 'common', 'common-grpc', + 'dlp', 'error-reporting', 'google-cloud', 'monitoring',