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 }
// [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); }
/// <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 }
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 }
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(); }
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 }
/// <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 static InspectContentResponse Inspect( string projectId, string dataValue, string minLikelihood, int maxFindings, bool includeQuote, IEnumerable <InfoType> infoTypes, IEnumerable <CustomInfoType> customInfoTypes) { var inspectConfig = new InspectConfig { MinLikelihood = (Likelihood)Enum.Parse(typeof(Likelihood), minLikelihood, true), Limits = new FindingLimits { MaxFindingsPerRequest = maxFindings }, IncludeQuote = includeQuote, InfoTypes = { infoTypes }, CustomInfoTypes = { customInfoTypes } }; var request = new InspectContentRequest { ParentAsProjectName = new ProjectName(projectId), Item = new ContentItem { Value = dataValue }, InspectConfig = inspectConfig }; var dlp = DlpServiceClient.Create(); var response = dlp.InspectContent(request); PrintResponse(includeQuote, response); return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect, List <String> excludedMatchList) { var dlp = DlpServiceClient.Create(); var byteContentItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteContentItem }; var infoTypes = new string[] { "PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD_NUMBER" }.Select(it => new InfoType { Name = it }); var exclusionRule = new ExclusionRule { MatchingType = MatchingType.FullMatch, Dictionary = new CustomInfoType.Types.Dictionary { WordList = new CustomInfoType.Types.Dictionary.Types.WordList { Words = { excludedMatchList } } } }; var ruleSet = new InspectionRuleSet { InfoTypes = { new InfoType { Name = "EMAIL_ADDRESS" } }, Rules = { new InspectionRule { ExclusionRule = exclusionRule } } }; var config = new InspectConfig { InfoTypes = { infoTypes }, IncludeQuote = true, RuleSet = { ruleSet } }; var request = new InspectContentRequest { Parent = new LocationName(projectId, "global").ToString(), Item = contentItem, InspectConfig = config }; var response = dlp.InspectContent(request); Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect) { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. var dlp = DlpServiceClient.Create(); // Specify the type and content to be inspected. var byteContentItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteContentItem }; // Specify the type of info the inspection will look for. // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types. var infoTypes = new string[] { "DOMAIN_NAME", "EMAIL_ADDRESS" }.Select(it => new InfoType { Name = it }); // Define a custom info type to exclude email addresses var customInfoType = new CustomInfoType { InfoType = new InfoType { Name = "EMAIL_ADDRESS" }, ExclusionType = ExclusionType.Exclude }; // Exclude EMAIL_ADDRESS matches var exclusionRule = new ExclusionRule { ExcludeInfoTypes = new ExcludeInfoTypes { InfoTypes = { new InfoType { Name = "EMAIL_ADDRESS" } } }, MatchingType = MatchingType.PartialMatch }; // Construct a ruleset that applies the exclusion rule to the DOMAIN_NAME infotype. // If a DOMAIN_NAME match is part of an EMAIL_ADDRESS match, the DOMAIN_NAME match will // be excluded. var ruleSet = new InspectionRuleSet { InfoTypes = { new InfoType { Name = "DOMAIN_NAME" } }, Rules = { new InspectionRule { ExclusionRule = exclusionRule } } }; // Construct the configuration for the Inspect request, including the ruleset. var config = new InspectConfig { InfoTypes = { infoTypes }, CustomInfoTypes = { customInfoType }, IncludeQuote = true, RuleSet = { ruleSet } }; // Construct the Inspect request to be sent by the client. var request = new InspectContentRequest { Parent = new LocationName(projectId, "global").ToString(), Item = contentItem, InspectConfig = config }; // Use the client to send the API request. var response = dlp.InspectContent(request); return(response); }
public static IEnumerable <Finding> InspectFile(string projectId, string filePath, BytesType fileType) { // Instantiate a client. var 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 { Parent = new LocationName(projectId, "global").ToString(), 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 var response = dlp.InspectContent(request); // Inspect response var findings = response.Result.Findings; if (findings.Any()) { 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); }
public static InspectContentResponse Inspect(string projectId, string textToInspect) { var dlp = DlpServiceClient.Create(); var byteContentItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteContentItem }; var patientRule = new DetectionRule.Types.HotwordRule { HotwordRegex = new CustomInfoType.Types.Regex { Pattern = "patient" }, Proximity = new DetectionRule.Types.Proximity { WindowBefore = 10 }, LikelihoodAdjustment = new DetectionRule.Types.LikelihoodAdjustment { FixedLikelihood = Likelihood.VeryLikely } }; var doctorRule = new DetectionRule.Types.HotwordRule { HotwordRegex = new CustomInfoType.Types.Regex { Pattern = "doctor" }, Proximity = new DetectionRule.Types.Proximity { WindowBefore = 10 }, LikelihoodAdjustment = new DetectionRule.Types.LikelihoodAdjustment { FixedLikelihood = Likelihood.Unlikely } }; // Construct exclusion rules var quasimodoRule = new ExclusionRule { Dictionary = new Dictionary { WordList = new Dictionary.Types.WordList { Words = { "Quasimodo" } } }, MatchingType = MatchingType.PartialMatch }; var redactedRule = new ExclusionRule { Regex = new CustomInfoType.Types.Regex { Pattern = "REDACTED" }, MatchingType = MatchingType.PartialMatch }; var infoType = new InfoType { Name = "PERSON_NAME" }; var inspectionRuleSet = new InspectionRuleSet { InfoTypes = { infoType }, Rules = { new InspectionRule { HotwordRule = patientRule }, new InspectionRule { HotwordRule = doctorRule }, new InspectionRule { ExclusionRule = quasimodoRule }, new InspectionRule { ExclusionRule = redactedRule } } }; var inspectConfig = new InspectConfig { InfoTypes = { infoType }, IncludeQuote = true, RuleSet = { inspectionRuleSet } }; var request = new InspectContentRequest { ParentAsProjectName = new ProjectName(projectId), Item = contentItem, InspectConfig = inspectConfig }; var response = dlp.InspectContent(request); Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect) { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. var dlp = DlpServiceClient.Create(); // Specify the type and content to be inspected. var byteItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteItem }; // Specify the type of info the inspection will look for. // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types. var infoTypes = new string[] { "PERSON_NAME", "EMAIL_ADDRESS" }.Select(it => new InfoType { Name = it }); // Exclude EMAIL_ADDRESS matches var exclusionRule = new ExclusionRule { ExcludeInfoTypes = new ExcludeInfoTypes { InfoTypes = { new InfoType { Name = "EMAIL_ADDRESS" } } }, MatchingType = MatchingType.PartialMatch }; // Construct a ruleset that applies the exclusion rule to the PERSON_NAME infotype. // If a PERSON_NAME match overlaps with an EMAIL_ADDRESS match, the PERSON_NAME match will // be excluded. var ruleSet = new InspectionRuleSet { InfoTypes = { new InfoType { Name = "PERSON_NAME" } }, Rules = { new InspectionRule { ExclusionRule = exclusionRule } } }; // Construct the configuration for the Inspect request, including the ruleset. var config = new InspectConfig { InfoTypes = { infoTypes }, IncludeQuote = true, RuleSet = { ruleSet } }; // Construct the Inspect request to be sent by the client. var request = new InspectContentRequest { Parent = new LocationName(projectId, "global").ToString(), Item = contentItem, InspectConfig = config }; // Use the client to send the API request. var response = dlp.InspectContent(request); // Parse the response and process results Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect) { var dlp = DlpServiceClient.Create(); var byteItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteItem }; var customInfoType = new CustomInfoType { InfoType = new InfoType { Name = "VIP_DETECTOR" }, Regex = new CustomInfoType.Types.Regex { Pattern = "Larry Page|Sergey Brin" }, ExclusionType = ExclusionType.Exclude }; var exclusionRule = new ExclusionRule { ExcludeInfoTypes = new ExcludeInfoTypes { InfoTypes = { customInfoType.InfoType } }, MatchingType = MatchingType.FullMatch }; var ruleSet = new InspectionRuleSet { InfoTypes = { new InfoType { Name = "PERSON_NAME" } }, Rules = { new InspectionRule { ExclusionRule = exclusionRule } } }; var config = new InspectConfig { InfoTypes = { new InfoType { Name = "PERSON_NAME" } }, CustomInfoTypes = { customInfoType }, IncludeQuote = true, RuleSet = { ruleSet } }; var request = new InspectContentRequest { Parent = new LocationName(projectId, "global").ToString(), Item = contentItem, InspectConfig = config }; var response = dlp.InspectContent(request); Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect, string customHotword) { var dlp = DlpServiceClient.Create(); var byteContentItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteContentItem }; var hotwordRule = new DetectionRule.Types.HotwordRule { HotwordRegex = new Regex { Pattern = customHotword }, Proximity = new DetectionRule.Types.Proximity { WindowBefore = 50 }, LikelihoodAdjustment = new DetectionRule.Types.LikelihoodAdjustment { FixedLikelihood = Likelihood.VeryLikely } }; var infoType = new InfoType { Name = "PERSON_NAME" }; var inspectionRuleSet = new InspectionRuleSet { InfoTypes = { infoType }, Rules = { new InspectionRule { HotwordRule = hotwordRule } } }; var inspectConfig = new InspectConfig { InfoTypes = { infoType }, IncludeQuote = true, RuleSet = { inspectionRuleSet }, MinLikelihood = Likelihood.VeryLikely }; var request = new InspectContentRequest { Parent = new LocationName(projectId, "global").ToString(), Item = contentItem, InspectConfig = inspectConfig }; var response = dlp.InspectContent(request); Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }
public static InspectContentResponse Inspect(string projectId, string textToInspect, string customDetectorPattern, List <String> excludedSubstringList) { var dlp = DlpServiceClient.Create(); var byteContentItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.TextUtf8, Data = Google.Protobuf.ByteString.CopyFromUtf8(textToInspect) }; var contentItem = new ContentItem { ByteItem = byteContentItem }; var infoType = new InfoType { Name = "CUSTOM_NAME_DETECTOR" }; var customInfoType = new CustomInfoType { InfoType = infoType, Regex = new CustomInfoType.Types.Regex { Pattern = customDetectorPattern } }; var exclusionRule = new ExclusionRule { MatchingType = MatchingType.PartialMatch, Dictionary = new CustomInfoType.Types.Dictionary { WordList = new CustomInfoType.Types.Dictionary.Types.WordList { Words = { excludedSubstringList } } } }; var ruleSet = new InspectionRuleSet { InfoTypes = { infoType }, Rules = { new InspectionRule { ExclusionRule = exclusionRule } } }; var config = new InspectConfig { CustomInfoTypes = { customInfoType }, IncludeQuote = true, RuleSet = { ruleSet } }; var request = new InspectContentRequest { ParentAsProjectName = new ProjectName(projectId), Item = contentItem, InspectConfig = config }; var response = dlp.InspectContent(request); Console.WriteLine($"Findings: {response.Result.Findings.Count}"); foreach (var f in response.Result.Findings) { Console.WriteLine("\tQuote: " + f.Quote); Console.WriteLine("\tInfo type: " + f.InfoType.Name); Console.WriteLine("\tLikelihood: " + f.Likelihood); } return(response); }