使用Apache Airflow存储和访问密码

编程入门 行业动态 更新时间:2024-10-22 09:31:23
本文介绍了使用Apache Airflow存储和访问密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们使用气流作为调度程序。我想在DAG中调用一个简单的bash运算符。 bash脚本需要使用密码作为参数来进行进一步处理。

We are using airflow as a scheduler. I want to invoke a simple bash operator in a DAG. The bash script needs password as an argument to do further processing.

我如何安全地将密码存储在气流中(配置/变量/连接)并在dag定义文件中访问它。

How can I store a password securely in airflow (config/variables/connection) and access it in dag definition file.

我是气流和Python的新手,所以会感谢代码段。

I am new to airflow and Python so a code snippet will be appreciated.

推荐答案

您可以将密码存储在挂钩中-只要您设置了Fernet密钥,该密码就会被加密。

You can store the password in a Hook - this will be encrypted so long as you have setup your fernet key.

以下是创建密码的方法连接。

Here is how you can create a connection.

from airflow.models import Connection def create_conn(username, password, host=None): new_conn = Connection(conn_id=f'{username}_connection', login=username, host=host if host else None) new_conn.set_password(password)

然后,此密码在您设置的数据库中被加密。

Then, this password is encryted in the db you setup.

要访问此密码:

from airflow.hooks.base_hook import BaseHook connection = BaseHook.get_connection("username_connection") password = connection.password # This is a getter that returns the unencrypted password.

编辑:

更容易通过UI创建连接的方法:

There is an easier way to create a connection via the UI:

然后:

Then:

更多推荐

使用Apache Airflow存储和访问密码

本文发布于:2023-11-24 04:28:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码   Apache   Airflow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!