public async Task InspectContentAsync_RequestObject()
        {
            // Snippet: InspectContentAsync(InspectContentRequest,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

            // Initialize request argument(s)
            InspectContentRequest request = new InspectContentRequest
            {
                InspectConfig = new InspectConfig
                {
                    InfoTypes =
                    {
                        new InfoType
                        {
                            Name = "EMAIL_ADDRESS",
                        },
                    },
                },
                Items =
                {
                    new ContentItem
                    {
                        Type  = "text/plain",
                        Value = "My email is [email protected].",
                    },
                },
            };
            // Make the request
            InspectContentResponse response = await dlpServiceClient.InspectContentAsync(request);

            // End snippet
        }
        public static int Main(string[] args)
        {
            // Create client
            DlpServiceClient client = DlpServiceClient.Create();

            // Initialize request argument(s)
            InspectConfig inspectConfig = new InspectConfig
            {
                MinLikelihood = Likelihood.Possible,
            };
            IEnumerable <ContentItem> items = new[]
            {
                new ContentItem
                {
                    Type  = "text/plain",
                    Value = "my phone number is 215-512-1212",
                },
            };

            // Call API method
            InspectContentResponse response = client.InspectContent(inspectConfig, items);

            // Show the result
            Console.WriteLine(response);

            // Success
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
 public void InspectContent()
 {
     // Snippet: InspectContent(InspectConfig,IEnumerable<ContentItem>,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     InspectConfig inspectConfig = new InspectConfig
     {
         InfoTypes =
         {
             new InfoType
             {
                 Name = "EMAIL_ADDRESS",
             },
         },
     };
     IEnumerable <ContentItem> items = new[]
     {
         new ContentItem
         {
             Type  = "text/plain",
             Value = "My email is [email protected].",
         },
     };
     // Make the request
     InspectContentResponse response = dlpServiceClient.InspectContent(inspectConfig, items);
     // End snippet
 }
예제 #4
0
        // [START dlp_inspect_string]
        public static object InspectString(
            string projectId,
            string dataValue,
            string minLikelihood,
            int maxFindings,
            bool includeQuote,
            IEnumerable <InfoType> infoTypes,
            IEnumerable <CustomInfoType> customInfoTypes)
        {
            var inspectConfig = new InspectConfig
            {
                MinLikelihood = (Likelihood)System.Enum.Parse(typeof(Likelihood), minLikelihood),
                Limits        = new InspectConfig.Types.FindingLimits
                {
                    MaxFindingsPerRequest = maxFindings
                },
                IncludeQuote    = includeQuote,
                InfoTypes       = { infoTypes },
                CustomInfoTypes = { customInfoTypes }
            };
            var request = new InspectContentRequest
            {
                ParentAsProjectName = new ProjectName(projectId),
                Item = new ContentItem
                {
                    Value = dataValue
                },
                InspectConfig = inspectConfig
            };

            DlpServiceClient       dlp      = DlpServiceClient.Create();
            InspectContentResponse response = dlp.InspectContent(request);

            var findings = response.Result.Findings;

            if (findings.Count > 0)
            {
                Console.WriteLine("Findings:");
                foreach (var finding in findings)
                {
                    if (includeQuote)
                    {
                        Console.WriteLine($"  Quote: {finding.Quote}");
                    }
                    Console.WriteLine($"  InfoType: {finding.InfoType}");
                    Console.WriteLine($"  Likelihood: {finding.Likelihood}");
                }
            }
            else
            {
                Console.WriteLine("No findings.");
            }

            return(0);
        }
예제 #5
0
 public void InspectContent()
 {
     // Snippet: InspectContent(InspectConfig,IEnumerable<ContentItem>,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     InspectConfig             inspectConfig = new InspectConfig();
     IEnumerable <ContentItem> items         = new List <ContentItem>();
     // Make the request
     InspectContentResponse response = dlpServiceClient.InspectContent(inspectConfig, items);
     // End snippet
 }
예제 #6
0
 /// <summary>Snippet for InspectContent</summary>
 public void InspectContent_RequestObject()
 {
     // Snippet: InspectContent(InspectContentRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     InspectContentRequest request = new InspectContentRequest
     {
         ParentAsProjectName = new ProjectName("[PROJECT]"),
     };
     // Make the request
     InspectContentResponse response = dlpServiceClient.InspectContent(request);
     // End snippet
 }
예제 #7
0
 public void InspectContent_RequestObject()
 {
     // Snippet: InspectContent(InspectContentRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     InspectContentRequest request = new InspectContentRequest
     {
         InspectConfig = new InspectConfig(),
         Items         = { },
     };
     // Make the request
     InspectContentResponse response = dlpServiceClient.InspectContent(request);
     // End snippet
 }
예제 #8
0
        public async Task InspectContentAsync()
        {
            // Snippet: InspectContentAsync(InspectConfig,IEnumerable<ContentItem>,CallSettings)
            // Additional: InspectContentAsync(InspectConfig,IEnumerable<ContentItem>,CancellationToken)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

            // Initialize request argument(s)
            InspectConfig             inspectConfig = new InspectConfig();
            IEnumerable <ContentItem> items         = new List <ContentItem>();
            // Make the request
            InspectContentResponse response = await dlpServiceClient.InspectContentAsync(inspectConfig, items);

            // End snippet
        }
예제 #9
0
        public async Task InspectContentAsync_RequestObject()
        {
            // Snippet: InspectContentAsync(InspectContentRequest,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

            // Initialize request argument(s)
            InspectContentRequest request = new InspectContentRequest
            {
                InspectConfig = new InspectConfig(),
                Items         = { },
            };
            // Make the request
            InspectContentResponse response = await dlpServiceClient.InspectContentAsync(request);

            // End snippet
        }
예제 #10
0
        /// <summary>Snippet for InspectContentAsync</summary>
        public async Task InspectContentAsync_RequestObject()
        {
            // Snippet: InspectContentAsync(InspectContentRequest,CallSettings)
            // Additional: InspectContentAsync(InspectContentRequest,CancellationToken)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

            // Initialize request argument(s)
            InspectContentRequest request = new InspectContentRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
            };
            // Make the request
            InspectContentResponse response = await dlpServiceClient.InspectContentAsync(request);

            // End snippet
        }
        public async Task InspectContentAsync()
        {
            Mock <DlpService.DlpServiceClient> mockGrpcClient = new Mock <DlpService.DlpServiceClient>(MockBehavior.Strict);
            InspectContentRequest request = new InspectContentRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
            };
            InspectContentResponse expectedResponse = new InspectContentResponse();

            mockGrpcClient.Setup(x => x.InspectContentAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <InspectContentResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            DlpServiceClient       client   = new DlpServiceClientImpl(mockGrpcClient.Object, null);
            InspectContentResponse response = await client.InspectContentAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void InspectContent()
        {
            Mock <DlpService.DlpServiceClient> mockGrpcClient = new Mock <DlpService.DlpServiceClient>(MockBehavior.Strict);
            InspectContentRequest request = new InspectContentRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
            };
            InspectContentResponse expectedResponse = new InspectContentResponse();

            mockGrpcClient.Setup(x => x.InspectContent(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            DlpServiceClient       client   = new DlpServiceClientImpl(mockGrpcClient.Object, null);
            InspectContentResponse response = client.InspectContent(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #13
0
    private static void PrintResponse(bool includeQuote, InspectContentResponse response)
    {
        var findings = response.Result.Findings;

        if (findings.Any())
        {
            Console.WriteLine("Findings:");
            foreach (var finding in findings)
            {
                if (includeQuote)
                {
                    Console.WriteLine($"  Quote: {finding.Quote}");
                }
                Console.WriteLine($"  InfoType: {finding.InfoType}");
                Console.WriteLine($"  Likelihood: {finding.Likelihood}");
            }
        }
        else
        {
            Console.WriteLine("No findings.");
        }
    }
예제 #14
0
        public static object InspectFile(
            string projectId,
            string file,
            string minLikelihood,
            int maxFindings,
            bool includeQuote,
            IEnumerable <InfoType> infoTypes)
        {
            var fileStream = new FileStream(file, FileMode.Open);

            try
            {
                var inspectConfig = new InspectConfig
                {
                    MinLikelihood = (Likelihood)System.Enum.Parse(typeof(Likelihood), minLikelihood),
                    Limits        = new FindingLimits
                    {
                        MaxFindingsPerRequest = maxFindings
                    },
                    IncludeQuote = includeQuote,
                    InfoTypes    = { infoTypes }
                };
                DlpServiceClient       dlp      = DlpServiceClient.Create();
                InspectContentResponse response = dlp.InspectContent(new InspectContentRequest
                {
                    ParentAsProjectName = new Google.Cloud.Dlp.V2.ProjectName(projectId),
                    Item = new ContentItem
                    {
                        ByteItem = new ByteContentItem
                        {
                            Data = ByteString.FromStream(fileStream),
                            Type = s_fileTypes.GetValueOrDefault(
                                new FileInfo(file).Extension.ToLower(),
                                ByteContentItem.Types.BytesType.Unspecified
                                )
                        }
                    },
                    InspectConfig = inspectConfig
                });

                var findings = response.Result.Findings;
                if (findings.Count > 0)
                {
                    Console.WriteLine("Findings:");
                    foreach (var finding in findings)
                    {
                        if (includeQuote)
                        {
                            Console.WriteLine($"  Quote: {finding.Quote}");
                        }
                        Console.WriteLine($"  InfoType: {finding.InfoType}");
                        Console.WriteLine($"  Likelihood: {finding.Likelihood}");
                    }
                }
                else
                {
                    Console.WriteLine("No findings.");
                }

                return(0);
            }
            finally
            {
                fileStream.Close();
            }
        }
    /// <summary>
    /// Inspects the provided file for sensitive data.
    ///</summary>
    /// <param name="projectId">Your Google Cloud Project ID.</param>
    /// <param name="filePath">The path to the specified file to inspect.</param>
    /// <param name="fileType">The type of the specifed file.</param>
    public IEnumerable <Finding> InspectFile(
        string projectId   = "YOUR-PROJECT-ID",
        string filePath    = "path/to/image.png",
        BytesType fileType = BytesType.ImagePng)
    {
        // Instantiate a client.
        DlpServiceClient dlp = DlpServiceClient.Create();

        // Get the bytes from the file.
        ByteString fileBytes;

        using (Stream f = new FileStream(filePath, FileMode.Open))
        {
            fileBytes = ByteString.FromStream(f);
        }

        // Construct a request.
        var request = new InspectContentRequest
        {
            ParentAsProjectName = new ProjectName(projectId),
            Item = new ContentItem
            {
                ByteItem = new ByteContentItem()
                {
                    Data = fileBytes,
                    Type = fileType
                }
            },
            InspectConfig = new InspectConfig
            {
                // The info types of information to match
                InfoTypes =
                {
                    new InfoType {
                        Name = "PHONE_NUMBER"
                    },
                    new InfoType {
                        Name = "EMAIL_ADDRESS"
                    },
                    new InfoType {
                        Name = "CREDIT_CARD_NUMBER"
                    }
                },
                // The minimum likelihood before returning a match
                MinLikelihood = Likelihood.Unspecified,
                // Whether to include the matching string
                IncludeQuote = true,
                Limits       = new InspectConfig.Types.FindingLimits
                {
                    // The maximum number of findings to report per request
                    // (0 = server maximum)
                    MaxFindingsPerRequest = 0
                }
            }
        };

        // Execute request
        InspectContentResponse response = dlp.InspectContent(request);

        // Inspect response
        var findings = response.Result.Findings;

        if (findings.Count > 0)
        {
            Console.WriteLine("Findings:");
            foreach (var finding in findings)
            {
                Console.WriteLine($"Quote: {finding.Quote}");
                Console.WriteLine($"InfoType: {finding.InfoType}");
                Console.WriteLine($"Likelihood: {finding.Likelihood}");
            }
        }
        else
        {
            Console.WriteLine("No findings.");
        }
        return(findings);
    }