将Airflow
更新为1.9
后,所有变量都会创建为加密变量。
是否可以禁用加密?
答案 0 :(得分:1)
1-The Croods方式....
from airflow.models import get_fernet
from airflow.models import Variable
var_to_decryp = Variable.get("var_name",deserialize_json=True)
fernet = get_fernet()
decryp_value = fernet.decrypt(bytes(var_to_decryp, 'utf-8')).decode()
2-正确的方法是使用Variable模型中的get_val():
def get_val(self):
log = LoggingMixin().log
if self._val and self.is_encrypted:
try:
fernet = get_fernet()
return fernet.decrypt(bytes(self._val, 'utf-8')).decode()
except InvalidFernetToken:
log.error("Can't decrypt _val for key={}, invalid token "
"or value".format(self.key))
return None
except Exception:
log.error("Can't decrypt _val for key={}, FERNET_KEY "
"configuration missing".format(self.key))
return None
else:
return self._val
但是我不知道那是家庭作业。