Я настраиваю Google DLP-сканирование для большой таблицы запросов, чтобы найти идентифицируемую личную информацию. Я работал над примером кода Google для этого, но у меня были проблемы с элементом pub / sub кода
Это для облачной функции Google Python, вызывающей Google dlp, с использованием примера google здесь с использованием метода inspect_bigquery.
...
actions = [{
'pub_sub': {'topic': '{}/topics/{}'.format(parent, topic_id)},
'save_findings': {
'output_config': {
'table': {
'project_id': project,
'dataset_id': dataset_id,
'table_id': table_id + '_inspection_results',
}
}
},
}]
...
subscriber = google.cloud.pubsub.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_id)
# subscription = subscriber.subscribe(subscription_path, callback)
subscription = subscriber.subscribe(subscription_path)
...
def callback(message):
try:
if (message.attributes['DlpJobName'] == operation.name):
# This is the message we're looking for, so acknowledge it.
message.ack()
# Now that the job is done, fetch the results and print them.
job = dlp.get_dlp_job(operation.name)
if job.inspect_details.result.info_type_stats:
for finding in job.inspect_details.result.info_type_stats:
print('Info type: {}; Count: {}'.format(
finding.info_type.name, finding.count))
else:
print('No findings.')
# Signal to the main thread that we can exit.
job_done.set()
else:
# This is not the message we're looking for.
message.drop()
except Exception as e:
# Because this is executing in a thread, an exception won't be
# noted unless we print it manually.
print(e)
raise
# Register the callback and wait on the event.
subscription.open(callback)
finished = job_done.wait(timeout=timeout)
if not finished:
print('No event received before the timeout. Please verify that the '
'subscription provided is subscribed to the topic provided.')
Есть две ошибки, которые я получаю, когда я оставляю метод подписки только с путем подписки, он вызывает ошибку TypeError: subscribe (), пропускающий 1 обязательный позиционный аргумент: «обратный вызов».
Когда я помещаю функцию обратного вызова в метод подписки, она завершается с
Выполнение функции заняло 60002 мс, завершено со статусом «тайм-аут»
Событие не получено до истечения времени ожидания. Убедитесь, что указанная подписка подписана на указанную тему.
Однако действие сохранения результатов работает, и я могу увидеть результаты в большом запросе через пару секунд.
Спасибо