Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 使用Google Cloud DLP API时如何获取扫描文件的位置?_Google Cloud Platform_Google Cloud Dlp - Fatal编程技术网

Google cloud platform 使用Google Cloud DLP API时如何获取扫描文件的位置?

Google cloud platform 使用Google Cloud DLP API时如何获取扫描文件的位置?,google-cloud-platform,google-cloud-dlp,Google Cloud Platform,Google Cloud Dlp,我正在扫描云存储桶中的嵌套目录。结果不包含匹配的值(quote),尽管我在上有include_quote。另外,如何获取具有匹配值的文件的名称以及匹配值?我正在使用Python。这就是我目前所拥有的。如您所见,API找到了匹配项,但我没有得到标记单词(和文件)的详细信息 inspect_job = { 'inspect_config': { 'info_types': info_types, 'min_likelihood': MIN_LIKELIHOOD,

我正在扫描云存储桶中的嵌套目录。结果不包含匹配的值(quote),尽管我在上有include_quote。另外,如何获取具有匹配值的文件的名称以及匹配值?我正在使用Python。这就是我目前所拥有的。如您所见,API找到了匹配项,但我没有得到标记单词(和文件)的详细信息

inspect_job = {
  'inspect_config': {
      'info_types': info_types,
      'min_likelihood': MIN_LIKELIHOOD,
      'include_quote': True,
      'limits': {
          'max_findings_per_request': MAX_FINDINGS
      },
  },
  'storage_config': {
      'cloud_storage_options': {
          'file_set': {
              'url':
                  'gs://{bucket_name}/{dir_name}/**'.format(
                      bucket_name=STAGING_BUCKET, dir_name=DIR_NAME)
          }
      }
  }


operation = dlp.create_dlp_job(parent, inspect_job)
dlp.get_dlp_job(operation.name)
结果如下:

result {
processed_bytes: 64
total_estimated_bytes: 64
info_type_stats {
  info_type {
    name: "EMAIL_ADDRESS"
  }
  count: 1
}
info_type_stats {
  info_type {
    name: "PHONE_NUMBER"
  }
  count: 1
}
info_type_stats {
  info_type {
    name: "FIRST_NAME"
  }
  count: 2
}

您需要遵循中的“检索检查结果”部分,并指定“保存结果”操作。我认为您没有获得报价值,因为您的inspectConfig不太正确: 根据位于的文档,您应该进行设置

  "includeQuote": true 
编辑:添加有关获取文件的信息: 下面这个例子:

云函数resolve_DLP的代码从如下作业详细信息中获取文件名

def resolve_DLP(data, context):
...
job = dlp.get_dlp_job(job_name)
...
file_path = (
      job.inspect_details.requested_options.job_config.storage_config
      .cloud_storage_options.file_set.url)
  file_name = os.path.basename(file_path)
...
编辑2:现在我看到最新的python api客户端使用“include”:作为dict键。。。。所以不是这样

编辑3:从python api代码:

message Finding {
  // The content that was found. Even if the content is not textual, it
  // may be converted to a textual representation here.
  // Provided if `include_quote` is true and the finding is
  // less than or equal to 4096 bytes long. If the finding exceeds 4096 bytes
  // in length, the quote may be omitted.
  string quote = 1;

因此,也许较小的文件将产生引号

回旋曲,感谢您的输入。我相信您提到的云存储示例只针对每个作业扫描一个文件。它不使用savefindings对象

乔希,你说得对。似乎需要将输出定向到Bigquery或Pub/sub以查看完整的结果

发件人:

对于完整的检验作业结果,您有两个选项。根据您选择的操作,检查作业包括:

保存到指定表中的BigQuery(SaveFindings对象)。在查看或分析结果之前,首先使用projects.dlpJobs.get方法(如下所述)确保作业已完成。请注意,可以使用OutputSchema对象指定用于存储结果的模式。 发布到云发布/子主题(PublishTopubSubsub对象)。主题必须已向运行发送通知的DlpJob的云DLP服务帐户授予发布访问权限

我通过修改解决方案使它起作用

这是我最后的工作脚本:

import google.cloud.dlp
dlp = google.cloud.dlp.DlpServiceClient()

inspect_job_data = {
    'storage_config': {
      'cloud_storage_options': {
          'file_set': {
              'url':
                  'gs://{bucket_name}/{dir_name}/**'.format(
                      bucket_name=STAGING_BUCKET, dir_name=DIR_NAME)
          }
      }
  },
'inspect_config': {
    'include_quote': include_quote,
    'info_types': [
        {'name': 'ALL_BASIC'},
    ],
},
'actions': [
    {
        'save_findings': {
            'output_config':{
                'table':{
                    'project_id': GCP_PROJECT_ID,
                    'dataset_id': DATASET_ID,
                    'table_id': '{}_DLP'.format(TABLE_ID)
                }
            }

        },
    },
]
}

operation = dlp.create_dlp_job(parent=dlp.project_path(GCP_PROJECT_ID), 
inspect_job=inspect_job_data)