首页 > 解决方案 > 如何防止记录加密的气流变量?

问题描述

我已经设置了一个声明了加密变量的气流。我正在使用BigQueryOperator。我在提供给类的 SQL 中使用加密变量。但气流在解密变量后记录 SQL。我怎样才能防止这种情况发生?

标签: etlairflow

解决方案


不幸的是,没有内置的方法来实现这一点。

一种可能的解决方法是删除self.log.info('Executing: %s', self.sql)line inBigQueryOperator或创建一个新的 Operator 继承BigQueryOperator,如下所示:

class CustomBQOperator(BigQueryOperator):
    @apply_defaults
    def __init__(self, *args, **kwargs):
        super(CustomBQOperator).__init__(*args, **kwargs)

    def execute(self, context):
        if self.bq_cursor is None:

            hook = BigQueryHook(
                bigquery_conn_id=self.bigquery_conn_id,
                use_legacy_sql=self.use_legacy_sql,
                delegate_to=self.delegate_to)
            conn = hook.get_conn()
            self.bq_cursor = conn.cursor()
        self.bq_cursor.run_query(
            self.sql,
            destination_dataset_table=self.destination_dataset_table,
            write_disposition=self.write_disposition,
            allow_large_results=self.allow_large_results,
            flatten_results=self.flatten_results,
            udf_config=self.udf_config,
            maximum_billing_tier=self.maximum_billing_tier,
            maximum_bytes_billed=self.maximum_bytes_billed,
            create_disposition=self.create_disposition,
            query_params=self.query_params,
            labels=self.labels,
            schema_update_options=self.schema_update_options,
            priority=self.priority,
            time_partitioning=self.time_partitioning,
            api_resource_configs=self.api_resource_configs,
            cluster_fields=self.cluster_fields,
        )

然后用这个CustomBQOperator代替BigQueryOperator


推荐阅读