示例#1
0
 /// <summary>Snippet for DeidentifyContent</summary>
 public void DeidentifyContent()
 {
     // Snippet: DeidentifyContent(DeidentifyConfig,InspectConfig,IEnumerable<ContentItem>,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     DeidentifyConfig          deidentifyConfig = new DeidentifyConfig();
     InspectConfig             inspectConfig    = new InspectConfig();
     IEnumerable <ContentItem> items            = new List <ContentItem>();
     // Make the request
     DeidentifyContentResponse response = dlpServiceClient.DeidentifyContent(deidentifyConfig, inspectConfig, items);
     // End snippet
 }
示例#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
 }
示例#3
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
 }
示例#4
0
        /// <summary>Snippet for DeidentifyContentAsync</summary>
        public async Task DeidentifyContentAsync()
        {
            // Snippet: DeidentifyContentAsync(DeidentifyConfig,InspectConfig,IEnumerable<ContentItem>,CallSettings)
            // Additional: DeidentifyContentAsync(DeidentifyConfig,InspectConfig,IEnumerable<ContentItem>,CancellationToken)
            // Create client
            DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync();

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

            // End snippet
        }
示例#5
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();
        }
示例#8
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);
        }
示例#9
0
        // [END dlp_reidentify_fpe]

        // [START dlp_deidentify_date_shift]
        public static object DeidDateShift(
            string projectId,
            string inputCsvFile,
            string outputCsvFile,
            int lowerBoundDays,
            int upperBoundDays,
            string dateFields,
            string contextField = "",
            string keyName      = "",
            string wrappedKey   = "")
        {
            var dlp = DlpServiceClient.Create();

            // Read file
            string[] csvLines   = File.ReadAllLines(inputCsvFile);
            string[] csvHeaders = csvLines[0].Split(',');
            string[] csvRows    = csvLines.Skip(1).ToArray();

            // Convert dates to protobuf format, and everything else to a string
            var protoHeaders = csvHeaders.Select(header => new FieldId {
                Name = header
            });
            var protoRows = csvRows.Select(CsvRow =>
            {
                var rowValues   = CsvRow.Split(',');
                var protoValues = rowValues.Select(RowValue =>
                {
                    System.DateTime parsedDate;
                    if (System.DateTime.TryParse(RowValue, out parsedDate))
                    {
                        return(new Value
                        {
                            DateValue = new Google.Type.Date
                            {
                                Year = parsedDate.Year,
                                Month = parsedDate.Month,
                                Day = parsedDate.Day
                            }
                        });
                    }
                    else
                    {
                        return(new Value
                        {
                            StringValue = RowValue
                        });
                    }
                });

                var rowObject = new Table.Types.Row();
                rowObject.Values.Add(protoValues);
                return(rowObject);
            });

            var dateFieldList = dateFields
                                .Split(',')
                                .Select(field => new FieldId {
                Name = field
            });

            // Construct + execute the request
            var dateShiftConfig = new DateShiftConfig
            {
                LowerBoundDays = lowerBoundDays,
                UpperBoundDays = upperBoundDays
            };
            bool hasKeyName    = !String.IsNullOrEmpty(keyName);
            bool hasWrappedKey = !String.IsNullOrEmpty(wrappedKey);
            bool hasContext    = !String.IsNullOrEmpty(contextField);

            if (hasKeyName && hasWrappedKey && hasContext)
            {
                dateShiftConfig.Context = new FieldId {
                    Name = contextField
                };
                dateShiftConfig.CryptoKey = new CryptoKey
                {
                    KmsWrapped = new KmsWrappedCryptoKey
                    {
                        WrappedKey    = ByteString.FromBase64(wrappedKey),
                        CryptoKeyName = keyName
                    }
                };
            }
            else if (hasKeyName || hasWrappedKey || hasContext)
            {
                throw new ArgumentException("Must specify ALL or NONE of: {contextFieldId, keyName, wrappedKey}!");
            }

            var deidConfig = new DeidentifyConfig
            {
                RecordTransformations = new RecordTransformations
                {
                    FieldTransformations =
                    {
                        new FieldTransformation
                        {
                            PrimitiveTransformation = new PrimitiveTransformation
                            {
                                DateShiftConfig = dateShiftConfig
                            },
                            Fields ={ dateFieldList          }
                        }
                    }
                }
            };

            DeidentifyContentResponse response = dlp.DeidentifyContent(
                new DeidentifyContentRequest
            {
                Parent           = $"projects/{projectId}",
                DeidentifyConfig = deidConfig,
                Item             = new ContentItem
                {
                    Table = new Table
                    {
                        Headers = { protoHeaders },
                        Rows    = { protoRows }
                    }
                }
            });

            // Save the results
            List <String> outputLines = new List <string>();

            outputLines.Add(csvLines[0]);

            outputLines.AddRange(response.Item.Table.Rows.Select(ProtoRow =>
            {
                var Values = ProtoRow.Values.Select(ProtoValue =>
                {
                    if (ProtoValue.DateValue != null)
                    {
                        var ProtoDate        = ProtoValue.DateValue;
                        System.DateTime Date = new System.DateTime(
                            ProtoDate.Year, ProtoDate.Month, ProtoDate.Day);
                        return(Date.ToShortDateString());
                    }
                    else
                    {
                        return(ProtoValue.StringValue);
                    }
                });
                return(String.Join(',', Values));
            }));

            File.WriteAllLines(outputCsvFile, outputLines);

            return(0);
        }