def create_inspect_template(project, info_types, template_id=None, display_name=None, min_likelihood=None, max_findings=None, include_quote=None): """Creates a Data Loss Prevention API inspect template. Args: project: The Google Cloud project id to use as a parent resource. info_types: A list of strings representing info types to look for. A full list of info type categories can be fetched from the API. template_id: The id of the template. If omitted, an id will be randomly generated. display_name: The optional display name of the template. min_likelihood: A string representing the minimum likelihood threshold that constitutes a match. One of: 'LIKELIHOOD_UNSPECIFIED', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY'. max_findings: The maximum number of findings to report; 0 = no maximum. include_quote: Boolean for whether to display a quote of the detected information in the results. Returns: None; the response from the API is printed to the terminal. """ # Import the client library import google.cloud.dlp # Instantiate a client. dlp = google.cloud.dlp.DlpServiceClient() # Prepare info_types by converting the list of strings into a list of # dictionaries (protos are also accepted). info_types = [{'name': info_type} for info_type in info_types] # Construct the configuration dictionary. Keys which are None may # optionally be omitted entirely. inspect_config = { 'info_types': info_types, 'min_likelihood': min_likelihood, 'include_quote': include_quote, 'limits': { 'max_findings_per_request': max_findings }, } inspect_template = { 'inspect_config': inspect_config, 'display_name': display_name, } # Convert the project id into a full resource id. parent = dlp.project_path(project) # Call the API. response = dlp.create_inspect_template(parent, inspect_template=inspect_template, template_id=template_id) print('Successfully created template {}'.format(response.name))
def create_inspect_template(project, info_types, template_id=None, display_name=None, min_likelihood=None, max_findings=None, include_quote=None): """Creates a Data Loss Prevention API inspect template. Args: project: The Google Cloud project id to use as a parent resource. info_types: A list of strings representing info types to look for. A full list of info type categories can be fetched from the API. template_id: The id of the template. If omitted, an id will be randomly generated. display_name: The optional display name of the template. min_likelihood: A string representing the minimum likelihood threshold that constitutes a match. One of: 'LIKELIHOOD_UNSPECIFIED', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY'. max_findings: The maximum number of findings to report; 0 = no maximum. include_quote: Boolean for whether to display a quote of the detected information in the results. Returns: None; the response from the API is printed to the terminal. """ # Import the client library import google.cloud.dlp # Instantiate a client. dlp = google.cloud.dlp.DlpServiceClient() # Prepare info_types by converting the list of strings into a list of # dictionaries (protos are also accepted). info_types = [{'name': info_type} for info_type in info_types] # Construct the configuration dictionary. Keys which are None may # optionally be omitted entirely. inspect_config = { 'info_types': info_types, 'min_likelihood': min_likelihood, 'include_quote': include_quote, 'limits': {'max_findings_per_request': max_findings}, } inspect_template = { 'inspect_config': inspect_config, 'display_name': display_name, } # Convert the project id into a full resource id. parent = dlp.project_path(project) # Call the API. response = dlp.create_inspect_template( parent, inspect_template=inspect_template, template_id=template_id) print('Successfully created template {}'.format(response.name))