|
| 1 | +/* |
| 2 | + * Copyright 2020 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package dlp.snippets; |
| 18 | + |
| 19 | +// [START dlp_list_info_types] |
| 20 | +import com.google.cloud.dlp.v2.DlpServiceClient; |
| 21 | +import com.google.privacy.dlp.v2.InfoTypeDescription; |
| 22 | +import com.google.privacy.dlp.v2.ListInfoTypesRequest; |
| 23 | +import com.google.privacy.dlp.v2.ListInfoTypesResponse; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | +public class InfoTypesList { |
| 29 | + |
| 30 | + // Lists the types of sensitive information the DLP API supports. |
| 31 | + public static void listInfoTypes() throws IOException { |
| 32 | + // Initialize client that will be used to send requests. This client only needs to be created |
| 33 | + // once, and can be reused for multiple requests. After completing all of your requests, call |
| 34 | + // the "close" method on the client to safely clean up any remaining background resources. |
| 35 | + try (DlpServiceClient dlpClient = DlpServiceClient.create()) { |
| 36 | + |
| 37 | + // Construct the request to be sent by the client |
| 38 | + ListInfoTypesRequest listInfoTypesRequest = ListInfoTypesRequest.newBuilder() |
| 39 | + // Only return infoTypes supported by certain parts of the API. |
| 40 | + // Supported filters are "supported_by=INSPECT" and "supported_by=RISK_ANALYSIS" |
| 41 | + // Defaults to "supported_by=INSPECT" |
| 42 | + .setFilter("supported_by=INSPECT") |
| 43 | + // BCP-47 language code for localized infoType friendly names. |
| 44 | + // Defaults to "en_US" |
| 45 | + .setLanguageCode("en-US").build(); |
| 46 | + |
| 47 | + // Use the client to send the API request. |
| 48 | + ListInfoTypesResponse response = dlpClient.listInfoTypes(listInfoTypesRequest); |
| 49 | + |
| 50 | + // Parse the response and process the results |
| 51 | + System.out.println("Infotypes found:"); |
| 52 | + for (InfoTypeDescription infoTypeDescription : response.getInfoTypesList()) { |
| 53 | + System.out.println("Name : " + infoTypeDescription.getName()); |
| 54 | + System.out.println("Display name : " + infoTypeDescription.getDisplayName()); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | +// [END dlp_list_info_types] |
0 commit comments