After updating Airflow
to 1.9
all variables are created as encrypted.
Is it possible to disable encryption ?
Securing VariablesAirflow uses Fernet to encrypt variables stored in the metastore database. It guarantees that without the encryption password, content cannot be manipulated or read without the key.
For the Airflow Variables section, Airflow will automatically hide any values if the variable name contains secret or password . The check for this value is case-insensitive, so the value of a variable with a name containing SECRET will also be hidden.
The universal order of precedence for all configuration options is as follows: set as an environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN ) set as a command environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN_CMD ) set as a secret environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN_SECRET )
1-The Croods way....
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-The right way will be using get_val() from Variable model:
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
but i don't know how ,that is home work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With