예제 #1
0
        // [END dlp_list_inspect_templates]

        // An example of ListInspectTemplates, but using paging
        // Not intended for inclusion in the documentation
        public static object ListInspectTemplatesPaging(string projectId)
        {
            DlpServiceClient client = DlpServiceClient.Create();

            // Read the templates in batches of 10 using paging.
            const int batchSize     = 10;
            string    nextPageToken = string.Empty;
            Page <InspectTemplate> currentTemplatesPage = null;

            do
            {
                var request = new ListInspectTemplatesRequest
                {
                    Parent    = $"projects/{projectId}",
                    PageToken = nextPageToken,
                };

                // This is the actual API call to DLP
                var response = client.ListInspectTemplates(request);

                currentTemplatesPage = response.ReadPage(batchSize);;
                foreach (var template in currentTemplatesPage)
                {
                    Console.WriteLine("Inspect Template Info:");
                    Console.WriteLine($"\tname: {template.Name}");
                    Console.WriteLine($"\tdisplayName: {template.DisplayName}");
                    Console.WriteLine($"\tdescription: {template.Description}");
                    Console.WriteLine($"\tcreateTime: {template.CreateTime}");
                    Console.WriteLine("Configuration:");
                    if (template.InspectConfig.InfoTypes.Any())
                    {
                        Console.WriteLine(
                            $"\tInfo types: {string.Join(',', template.InspectConfig.InfoTypes.Select(t => t.Name))}");
                    }
                    Console.WriteLine($"Min Likelihood: {template.InspectConfig.MinLikelihood}");
                    if (template.InspectConfig.ContentOptions.Any())
                    {
                        Console.WriteLine($"\tContent Options: {string.Join(',', template.InspectConfig.ContentOptions.Select(o => o.ToString()))}");
                    }
                    Console.WriteLine();
                }

                nextPageToken = currentTemplatesPage.NextPageToken;
            }while (!string.IsNullOrEmpty(nextPageToken));

            return(null);
        }
예제 #2
0
        /// <summary>Snippet for ListInspectTemplatesAsync</summary>
        public async Task ListInspectTemplatesAsync_RequestObject()
        {
            // Snippet: ListInspectTemplatesAsync(ListInspectTemplatesRequest,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListInspectTemplatesRequest request = new ListInspectTemplatesRequest
            {
                ParentAsOrganizationName = new OrganizationName("[ORGANIZATION]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListInspectTemplatesResponse, InspectTemplate> response =
                dlpServiceClient.ListInspectTemplatesAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((InspectTemplate item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListInspectTemplatesResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (InspectTemplate item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <InspectTemplate> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (InspectTemplate item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }