Exemplo n.º 1
0
    /// <summary>
    /// Replace sensitive information with masking characters using the DLP API.
    ///</summary>
    /// <param name="projectId">Your Google Cloud Project ID.</param>
    /// <param name="text">The text in which sensitive data will be masked.
    /// </param>
    /// <returns>The text with sensitive data masked.</returns>
    public string DeidentiyMasking(
        string projectId = "YOUR-PROJECT-ID",
        string text      = "My SSN is 372819127.")
    {
        // Instantiate a client.
        DlpServiceClient dlp = DlpServiceClient.Create();

        // Construct a request.
        var transformation = new InfoTypeTransformations.Types.InfoTypeTransformation
        {
            PrimitiveTransformation = new PrimitiveTransformation
            {
                CharacterMaskConfig = new CharacterMaskConfig
                {
                    MaskingCharacter = "*",
                    NumberToMask     = 5,
                    ReverseOrder     = false,
                }
            }
        };
        var request = new DeidentifyContentRequest
        {
            ParentAsProjectName = new ProjectName(projectId),
            InspectConfig       = new InspectConfig
            {
                InfoTypes =
                {
                    new InfoType {
                        Name = "US_SOCIAL_SECURITY_NUMBER"
                    }
                }
            },
            DeidentifyConfig = new DeidentifyConfig
            {
                InfoTypeTransformations = new InfoTypeTransformations
                {
                    Transformations = { transformation }
                }
            },
            Item = new ContentItem {
                Value = text
            }
        };

        // Call the API.
        var response = dlp.DeidentifyContent(request);

        // Inspect the results.
        Console.WriteLine($"Deidentified content: {response.Item.Value}");
        return(response.Item.Value);
    }
Exemplo n.º 2
0
 /// <summary>Snippet for DeidentifyContent</summary>
 public void DeidentifyContent_RequestObject()
 {
     // Snippet: DeidentifyContent(DeidentifyContentRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     DeidentifyContentRequest request = new DeidentifyContentRequest
     {
         ParentAsProjectName = new ProjectName("[PROJECT]"),
     };
     // Make the request
     DeidentifyContentResponse response = dlpServiceClient.DeidentifyContent(request);
     // End snippet
 }
Exemplo n.º 3
0
    public static DeidentifyContentResponse Deidentify(string projectId, string text)
    {
        // Instantiate a client.
        var dlp = DlpServiceClient.Create();

        // Construct a request.
        var transformation = new InfoTypeTransformations.Types.InfoTypeTransformation
        {
            PrimitiveTransformation = new PrimitiveTransformation
            {
                CharacterMaskConfig = new CharacterMaskConfig
                {
                    MaskingCharacter = "*",
                    NumberToMask     = 5,
                    ReverseOrder     = false,
                }
            }
        };
        var request = new DeidentifyContentRequest
        {
            Parent        = new LocationName(projectId, "global").ToString(),
            InspectConfig = new InspectConfig
            {
                InfoTypes =
                {
                    new InfoType {
                        Name = "US_SOCIAL_SECURITY_NUMBER"
                    }
                }
            },
            DeidentifyConfig = new DeidentifyConfig
            {
                InfoTypeTransformations = new InfoTypeTransformations
                {
                    Transformations = { transformation }
                }
            },
            Item = new ContentItem {
                Value = text
            }
        };

        // Call the API.
        var response = dlp.DeidentifyContent(request);

        // Inspect the results.
        Console.WriteLine($"Deidentified content: {response.Item.Value}");
        return(response);
    }
Exemplo n.º 4
0
        // [START dlp_deidentify_masking]
        public static object DeidMask(
            string projectId,
            string dataValue,
            IEnumerable <InfoType> infoTypes,
            string maskingCharacter,
            int numberToMask,
            bool reverseOrder)
        {
            var request = new DeidentifyContentRequest
            {
                ParentAsProjectName = new ProjectName(projectId),
                InspectConfig       = new InspectConfig
                {
                    InfoTypes = { infoTypes }
                },
                DeidentifyConfig = new DeidentifyConfig
                {
                    InfoTypeTransformations = new InfoTypeTransformations
                    {
                        Transformations =
                        {
                            new InfoTypeTransformations.Types.InfoTypeTransformation
                            {
                                PrimitiveTransformation = new PrimitiveTransformation
                                {
                                    CharacterMaskConfig = new CharacterMaskConfig
                                    {
                                        MaskingCharacter = maskingCharacter,
                                        NumberToMask     = numberToMask,
                                        ReverseOrder     = reverseOrder
                                    }
                                }
                            }
                        }
                    }
                },
                Item = new ContentItem
                {
                    Value = dataValue
                }
            };

            DlpServiceClient dlp = DlpServiceClient.Create();
            var response         = dlp.DeidentifyContent(request);

            Console.WriteLine($"Deidentified content: {response.Item.Value}");
            return(0);
        }
Exemplo n.º 5
0
 /// <summary>Snippet for DeidentifyContent</summary>
 public void DeidentifyContent_RequestObject()
 {
     // Snippet: DeidentifyContent(DeidentifyContentRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     DeidentifyContentRequest request = new DeidentifyContentRequest
     {
         DeidentifyConfig = new DeidentifyConfig(),
         InspectConfig    = new InspectConfig(),
         Items            = { },
     };
     // Make the request
     DeidentifyContentResponse response = dlpServiceClient.DeidentifyContent(request);
     // End snippet
 }
Exemplo n.º 6
0
        /// <summary>Snippet for DeidentifyContentAsync</summary>
        public async Task DeidentifyContentAsync_RequestObject()
        {
            // Snippet: DeidentifyContentAsync(DeidentifyContentRequest,CallSettings)
            // Additional: DeidentifyContentAsync(DeidentifyContentRequest,CancellationToken)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

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

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

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

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

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

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 9
0
        public void Intro()
        {
            string projectId = TestEnvironment.GetTestProjectId();
            // Sample: Intro
            DlpServiceClient         client  = DlpServiceClient.Create();
            DeidentifyContentRequest request = new DeidentifyContentRequest
            {
                ParentAsProjectName = new ProjectName(projectId),
                Item = new ContentItem
                {
                    Value = "Hi! My phone number is 555-1234-567. Please call me!"
                },
                DeidentifyConfig = new DeidentifyConfig
                {
                    InfoTypeTransformations = new InfoTypeTransformations
                    {
                        Transformations =
                        {
                            new InfoTypeTransformation
                            {
                                PrimitiveTransformation = new PrimitiveTransformation
                                {
                                    ReplaceConfig = new ReplaceValueConfig
                                    {
                                        NewValue = new Value{
                                            StringValue = "(Redacted)"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            DeidentifyContentResponse response = client.DeidentifyContent(request);

            Console.WriteLine(response.Item.Value);
            // End sample
            Assert.Equal("Hi! My phone number is (Redacted). Please call me!", response.Item.Value);
        }
Exemplo n.º 10
0
    public static DeidentifyContentResponse Deidentify(string projectId, string text)
    {
        // Instantiate a client.
        var dlp = DlpServiceClient.Create();

        var contentItem = new ContentItem {
            Value = text
        };

        var wordList = new CustomInfoType.Types.Dictionary.Types.WordList
        {
            Words = { new string[] { "*****@*****.**", "*****@*****.**" } }
        };

        var exclusionRule = new ExclusionRule
        {
            MatchingType = MatchingType.FullMatch,
            Dictionary   = new CustomInfoType.Types.Dictionary
            {
                WordList = wordList
            }
        };

        var infoType = new InfoType {
            Name = "EMAIL_ADDRESS"
        };

        var inspectionRuleSet = new InspectionRuleSet
        {
            InfoTypes = { infoType },
            Rules     = { new InspectionRule {
                              ExclusionRule = exclusionRule
                          } }
        };

        var inspectConfig = new InspectConfig
        {
            InfoTypes = { infoType },
            RuleSet   = { inspectionRuleSet }
        };
        var primitiveTransformation = new PrimitiveTransformation
        {
            ReplaceWithInfoTypeConfig = new ReplaceWithInfoTypeConfig {
            }
        };

        var transformation = new InfoTypeTransformations.Types.InfoTypeTransformation
        {
            InfoTypes = { infoType },
            PrimitiveTransformation = primitiveTransformation
        };

        var deidentifyConfig = new DeidentifyConfig
        {
            InfoTypeTransformations = new InfoTypeTransformations
            {
                Transformations = { transformation }
            }
        };

        var request = new DeidentifyContentRequest
        {
            Parent           = new LocationName(projectId, "global").ToString(),
            InspectConfig    = inspectConfig,
            DeidentifyConfig = deidentifyConfig,
            Item             = contentItem
        };

        // Call the API.
        var response = dlp.DeidentifyContent(request);

        // Inspect the results.
        Console.WriteLine($"Deidentified content: {response.Item.Value}");
        return(response);
    }
    public static DeidentifyContentResponse Deidentify(string projectId, string text)
    {
        // Instantiate a client.
        var dlp = DlpServiceClient.Create();

        var contentItem = new ContentItem {
            Value = text
        };

        var wordList = new CustomInfoType.Types.Dictionary.Types.WordList
        {
            Words = { new string[] { "RM-GREEN", "RM-YELLOW", "RM-ORANGE" } }
        };

        var infoType = new InfoType
        {
            Name = "CUSTOM_ROOM_ID"
        };

        var customInfoType = new CustomInfoType
        {
            InfoType   = infoType,
            Dictionary = new CustomInfoType.Types.Dictionary
            {
                WordList = wordList
            }
        };

        var inspectConfig = new InspectConfig
        {
            CustomInfoTypes =
            {
                customInfoType,
            }
        };
        var primitiveTransformation = new PrimitiveTransformation
        {
            ReplaceWithInfoTypeConfig = new ReplaceWithInfoTypeConfig {
            }
        };

        var transformation = new InfoTypeTransformations.Types.InfoTypeTransformation
        {
            InfoTypes = { infoType },
            PrimitiveTransformation = primitiveTransformation
        };

        var deidentifyConfig = new DeidentifyConfig
        {
            InfoTypeTransformations = new InfoTypeTransformations
            {
                Transformations = { transformation }
            }
        };

        var request = new DeidentifyContentRequest
        {
            Parent           = new LocationName(projectId, "global").ToString(),
            InspectConfig    = inspectConfig,
            DeidentifyConfig = deidentifyConfig,
            Item             = contentItem
        };

        // Call the API.
        var response = dlp.DeidentifyContent(request);

        // Inspect the results.
        Console.WriteLine($"Deidentified content: {response.Item.Value}");
        return(response);
    }