Пример #1
0
        // [END dlp_inspect_gcs]

        static bool EnsureJobFinishes(string projectId, string jobName)
        {
            DlpServiceClient client = DlpServiceClient.Create();
            var request             = new GetDlpJobRequest
            {
                DlpJobName = new DlpJobName(projectId, jobName),
            };

            // Simple logic that gives the job 5*30 sec at most to complete - for testing purposes only
            int numOfAttempts = 5;

            do
            {
                var dlpJob = client.GetDlpJob(request);
                numOfAttempts--;
                if (dlpJob.State != DlpJob.Types.JobState.Running)
                {
                    return(true);
                }

                Thread.Sleep(TimeSpan.FromSeconds(30));
            } while (numOfAttempts > 0);

            return(false);
        }
Пример #2
0
        public void CreateInspectOperation()
        {
            // Snippet: CreateInspectOperation(InspectConfig,StorageConfig,OutputStorageConfig,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
            // Initialize request argument(s)
            InspectConfig       inspectConfig = new InspectConfig();
            StorageConfig       storageConfig = new StorageConfig();
            OutputStorageConfig outputConfig  = new OutputStorageConfig();
            // Make the request
            Operation <InspectOperationResult, InspectOperationMetadata> response =
                dlpServiceClient.CreateInspectOperation(inspectConfig, storageConfig, outputConfig);

            // Poll until the returned long-running operation is complete
            Operation <InspectOperationResult, InspectOperationMetadata> completedResponse =
                response.PollUntilCompleted();
            // Retrieve the operation result
            InspectOperationResult result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <InspectOperationResult, InspectOperationMetadata> retrievedResponse =
                dlpServiceClient.PollOnceCreateInspectOperation(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                InspectOperationResult retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Пример #3
0
    private static DlpJob EnsureJobFinishes(string projectId, string jobName)
    {
        var client  = DlpServiceClient.Create();
        var request = new GetDlpJobRequest
        {
            DlpJobName = new DlpJobName(projectId, jobName),
        };

        // Simple logic that gives the job 5*30 sec at most to complete - for testing purposes only
        var numOfAttempts = 5;

        do
        {
            var dlpJob = client.GetDlpJob(request);
            numOfAttempts--;
            if (dlpJob.State != DlpJob.Types.JobState.Running)
            {
                return(dlpJob);
            }

            Thread.Sleep(TimeSpan.FromSeconds(30));
        } while (numOfAttempts > 0);

        throw new InvalidOperationException("Job did not complete in time");
    }
Пример #4
0
        // [END dlp_delete_inspect_template]

        // [START dlp_list_inspect_templates]
        public static object ListInspectTemplate(string projectId)
        {
            DlpServiceClient client = DlpServiceClient.Create();

            var response = client.ListInspectTemplates(
                new ListInspectTemplatesRequest
            {
                Parent = $"projects/{projectId}",
            }
                );

            foreach (var template in response)
            {
                Console.WriteLine($"Template {template.Name}:");
                Console.WriteLine($"\tDisplay Name: {template.DisplayName}");
                Console.WriteLine($"\tDescription: {template.Description}");
                Console.WriteLine($"\tCreated: {template.CreateTime}");
                Console.WriteLine($"\tUpdated: {template.UpdateTime}");
                Console.WriteLine("Configuration:");
                Console.WriteLine($"\tMin Likelihood: {template.InspectConfig.MinLikelihood}");
                Console.WriteLine($"\tInclude quotes: {template.InspectConfig.IncludeQuote}");
                Console.WriteLine($"\tMax findings per request: {template.InspectConfig.Limits.MaxFindingsPerRequest}");
            }

            return(null);
        }
Пример #5
0
        public void Intro()
        {
            // Sample: Intro
            DlpServiceClient client = DlpServiceClient.Create();
            var request             = new RedactContentRequest
            {
                Items =
                {
                    new ContentItem
                    {
                        Type  = "text/plain",
                        Value = "Hi! My phone number is 555-1234-567. Please call me!"
                    }
                },
                ReplaceConfigs = { new ReplaceConfig {
                                       ReplaceWith = "(Redacted)"
                                   } }
            };
            var response = client.RedactContent(request);
            var item     = response.Items[0];

            Console.WriteLine(item.Value);
            // End sample
            Assert.Equal("Hi! My phone number is (Redacted). Please call me!", item.Value);
        }
Пример #6
0
        /// <summary>Snippet for AnalyzeDataSourceRisk</summary>
        public void AnalyzeDataSourceRisk_RequestObject()
        {
            // Snippet: AnalyzeDataSourceRisk(AnalyzeDataSourceRiskRequest,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
            // Initialize request argument(s)
            AnalyzeDataSourceRiskRequest request = new AnalyzeDataSourceRiskRequest
            {
                PrivacyMetric = new PrivacyMetric(),
                SourceTable   = new BigQueryTable(),
            };
            // Make the request
            Operation <RiskAnalysisOperationResult, RiskAnalysisOperationMetadata> response =
                dlpServiceClient.AnalyzeDataSourceRisk(request);

            // Poll until the returned long-running operation is complete
            Operation <RiskAnalysisOperationResult, RiskAnalysisOperationMetadata> completedResponse =
                response.PollUntilCompleted();
            // Retrieve the operation result
            RiskAnalysisOperationResult result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <RiskAnalysisOperationResult, RiskAnalysisOperationMetadata> retrievedResponse =
                dlpServiceClient.PollOnceAnalyzeDataSourceRisk(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                RiskAnalysisOperationResult retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Пример #7
0
 /// <summary>Snippet for RedactContent</summary>
 public void RedactContent_RequestObject()
 {
     // Snippet: RedactContent(RedactContentRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     RedactContentRequest request = new RedactContentRequest
     {
         InspectConfig = new InspectConfig
         {
             InfoTypes =
             {
                 new InfoType
                 {
                     Name = "EMAIL_ADDRESS",
                 },
             },
         },
         Items =
         {
             new ContentItem
             {
                 Type  = "text/plain",
                 Value = "My email is [email protected].",
             },
         },
     };
     // Make the request
     RedactContentResponse response = dlpServiceClient.RedactContent(request);
     // End snippet
 }
 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
 }
        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);
        }
Пример #10
0
        // [END dlp_deidentify_masking]

        // [START dlp_deidentify_fpe]
        public static object DeidFpe(
            string projectId,
            string dataValue,
            IEnumerable <InfoType> infoTypes,
            string keyName,
            string wrappedKey,
            string alphabet)
        {
            var deidentifyConfig = new DeidentifyConfig
            {
                InfoTypeTransformations = new InfoTypeTransformations
                {
                    Transformations =
                    {
                        new InfoTypeTransformations.Types.InfoTypeTransformation
                        {
                            PrimitiveTransformation = new PrimitiveTransformation
                            {
                                CryptoReplaceFfxFpeConfig = new CryptoReplaceFfxFpeConfig
                                {
                                    CommonAlphabet = (FfxCommonNativeAlphabet)Enum.Parse(typeof(FfxCommonNativeAlphabet), alphabet),
                                    CryptoKey      = new CryptoKey
                                    {
                                        KmsWrapped = new KmsWrappedCryptoKey
                                        {
                                            CryptoKeyName = keyName,
                                            WrappedKey    = ByteString.FromBase64(wrappedKey)
                                        }
                                    },
                                    SurrogateInfoType = new InfoType
                                    {
                                        Name = "TOKEN"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            DlpServiceClient dlp = DlpServiceClient.Create();
            var response         = dlp.DeidentifyContent(
                new DeidentifyContentRequest
            {
                ParentAsProjectName = new ProjectName(projectId),
                InspectConfig       = new InspectConfig
                {
                    InfoTypes = { infoTypes }
                },
                DeidentifyConfig = deidentifyConfig,
                Item             = new ContentItem {
                    Value = dataValue
                }
            });

            Console.WriteLine($"Deidentified content: {response.Item.Value}");
            return(0);
        }
Пример #11
0
    public static DlpJob GetDlpJob(string jobName)
    {
        var dlp = DlpServiceClient.Create();

        var response = dlp.GetDlpJob(jobName);

        Console.WriteLine($"Job: {response.Name} status: {response.State}");

        return(response);
    }
Пример #12
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);
        }
        public void CreateInspectOperation_RequestObject()
        {
            // Snippet: CreateInspectOperation(CreateInspectOperationRequest,CallSettings)
            // Create client
            DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
            // Initialize request argument(s)
            CreateInspectOperationRequest request = new CreateInspectOperationRequest
            {
                InspectConfig = new InspectConfig
                {
                    InfoTypes =
                    {
                        new InfoType
                        {
                            Name = "EMAIL_ADDRESS",
                        },
                    },
                },
                StorageConfig = new StorageConfig
                {
                    CloudStorageOptions = new CloudStorageOptions
                    {
                        FileSet = new CloudStorageOptions.Types.FileSet
                        {
                            Url = "gs://example_bucket/example_file.png",
                        },
                    },
                },
                OutputConfig = new OutputStorageConfig(),
            };
            // Make the request
            Operation <InspectOperationResult, InspectOperationMetadata> response =
                dlpServiceClient.CreateInspectOperation(request);

            // Poll until the returned long-running operation is complete
            Operation <InspectOperationResult, InspectOperationMetadata> completedResponse =
                response.PollUntilCompleted();
            // Retrieve the operation result
            InspectOperationResult result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <InspectOperationResult, InspectOperationMetadata> retrievedResponse =
                dlpServiceClient.PollOnceCreateInspectOperation(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                InspectOperationResult retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Пример #14
0
    public static void DeleteJob(string jobName)
    {
        var dlp = DlpServiceClient.Create();

        dlp.DeleteDlpJob(new DeleteDlpJobRequest
        {
            Name = jobName
        });

        Console.WriteLine($"Successfully deleted job {jobName}.");
    }
Пример #15
0
 /// <summary>Snippet for GetInspectTemplate</summary>
 public void GetInspectTemplate_RequestObject()
 {
     // Snippet: GetInspectTemplate(GetInspectTemplateRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     GetInspectTemplateRequest request = new GetInspectTemplateRequest();
     // Make the request
     InspectTemplate response = dlpServiceClient.GetInspectTemplate(request);
     // End snippet
 }
Пример #16
0
 /// <summary>Snippet for ListInfoTypes</summary>
 public void ListInfoTypes_RequestObject()
 {
     // Snippet: ListInfoTypes(ListInfoTypesRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     ListInfoTypesRequest request = new ListInfoTypesRequest();
     // Make the request
     ListInfoTypesResponse response = dlpServiceClient.ListInfoTypes(request);
     // End snippet
 }
Пример #17
0
        public void TestGetDlpJob()
        {
            var dlp    = DlpServiceClient.Create();
            var dlpJob = dlp.CreateDlpJob(Fixture.GetTestRiskAnalysisJobRequest());

            TestRetryRobot.ShouldRetry = ex => true;
            TestRetryRobot.Eventually(() =>
            {
                Assert.Equal(dlpJob, JobsGet.GetDlpJob(dlpJob.Name));
            });
        }
Пример #18
0
        public void ListRootCategories()
        {
            // Snippet: ListRootCategories(string, *)
            DlpServiceClient client = DlpServiceClient.Create();

            foreach (var category in client.ListRootCategories("en-US").Categories)
            {
                Console.WriteLine($"{category.Name}: {category.DisplayName}");
            }
            // End snippet
        }
 public void ListRootCategories()
 {
     // Snippet: ListRootCategories(string,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     string languageCode = "en";
     // Make the request
     ListRootCategoriesResponse response = dlpServiceClient.ListRootCategories(languageCode);
     // End snippet
 }
 public void ListInspectFindings()
 {
     // Snippet: ListInspectFindings(ResultName,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     ResultName name = new ResultName("[RESULT]");
     // Make the request
     ListInspectFindingsResponse response = dlpServiceClient.ListInspectFindings(name);
     // End snippet
 }
Пример #21
0
    public static void Delete(string triggerName)
    {
        var dlp = DlpServiceClient.Create();

        dlp.DeleteJobTrigger(
            new DeleteJobTriggerRequest
        {
            Name = triggerName
        });

        Console.WriteLine($"Successfully deleted trigger {triggerName}.");
    }
Пример #22
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
 }
Пример #23
0
        // [END dlp_list_triggers]

        // [START dlp_delete_trigger]
        public static object DeleteJobTrigger(string triggerName)
        {
            DlpServiceClient dlp = DlpServiceClient.Create();

            dlp.DeleteJobTrigger(
                new DeleteJobTriggerRequest
            {
                Name = triggerName
            });

            Console.WriteLine($"Successfully deleted trigger {triggerName}.");
            return(0);
        }
Пример #24
0
 public void RedactContent()
 {
     // Snippet: RedactContent(InspectConfig,IEnumerable<ContentItem>,IEnumerable<RedactContentRequest.Types.ReplaceConfig>,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     InspectConfig             inspectConfig = new InspectConfig();
     IEnumerable <ContentItem> items         = new List <ContentItem>();
     IEnumerable <RedactContentRequest.Types.ReplaceConfig> replaceConfigs = new List <RedactContentRequest.Types.ReplaceConfig>();
     // Make the request
     RedactContentResponse response = dlpServiceClient.RedactContent(inspectConfig, items, replaceConfigs);
     // End snippet
 }
Пример #25
0
    public static PagedEnumerable <ListDlpJobsResponse, DlpJob> ListDlpJobs(string projectId, string filter, string jobType)
    {
        var dlp = DlpServiceClient.Create();

        var response = dlp.ListDlpJobs(new ListDlpJobsRequest
        {
            ParentAsProjectName = new ProjectName(projectId),
            Filter = filter,
            Type   = (DlpJobType)Enum.Parse(typeof(DlpJobType), jobType)
        });

        return(response);
    }
Пример #26
0
        public void TestListDlpJobs()
        {
            var dlp    = DlpServiceClient.Create();
            var dlpJob = dlp.CreateDlpJob(Fixture.GetTestRiskAnalysisJobRequest());

            TestRetryRobot.ShouldRetry = ex => true;
            TestRetryRobot.Eventually(() =>
            {
                var response = JobsList.ListDlpJobs(Fixture.ProjectId, "state=DONE", "RiskAnalysisJob");

                Assert.True(response.Any());
            });
        }
Пример #27
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);
    }
 public void ListInspectFindings_RequestObject()
 {
     // Snippet: ListInspectFindings(ListInspectFindingsRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     ListInspectFindingsRequest request = new ListInspectFindingsRequest
     {
         ResultName = new ResultName("[RESULT]"),
     };
     // Make the request
     ListInspectFindingsResponse response = dlpServiceClient.ListInspectFindings(request);
     // End snippet
 }
 public void ListRootCategories_RequestObject()
 {
     // Snippet: ListRootCategories(ListRootCategoriesRequest,CallSettings)
     // Create client
     DlpServiceClient dlpServiceClient = DlpServiceClient.Create();
     // Initialize request argument(s)
     ListRootCategoriesRequest request = new ListRootCategoriesRequest
     {
         LanguageCode = "en",
     };
     // Make the request
     ListRootCategoriesResponse response = dlpServiceClient.ListRootCategories(request);
     // End snippet
 }
Пример #30
0
        // [END dlp_create_inspect_template]

        // [START dlp_delete_inspect_template]
        public static object DeleteInspectTemplate(string projectId, string templateName)
        {
            DlpServiceClient client = DlpServiceClient.Create();

            var request = new DeleteInspectTemplateRequest
            {
                Name = templateName
            };

            client.DeleteInspectTemplate(request);
            Console.WriteLine($"Successfully deleted template {templateName}.");

            return(templateName);
        }