ashb commented on code in PR #23105:
URL: https://github.com/apache/airflow/pull/23105#discussion_r853799407
##########
airflow/models/connection.py:
##########
@@ -187,6 +188,21 @@ def _normalize_conn_type(conn_type):
conn_type = conn_type.replace('-', '_')
return conn_type
+ def _safe_fernet_decode(self, key: str, value: str) -> Optional[str]:
+ fernet = get_fernet()
+ if not fernet.is_encrypted:
+ raise AirflowException(
+ f"Can't decrypt encrypted {key!r} for login={self.login} "
+ f"FERNET_KEY configuration is missing"
+ )
+ try:
+ return fernet.decrypt(bytes(value, "utf-8")).decode()
+ except InvalidFernetToken:
+ self.log.error("Can't decrypt %s for login=%s, invalid token or
value", key, self.login)
+ except Exception:
+ self.log.error("Can't decrypt %s for login=%s, FERNET_KEY
configuration missing", key, self.login)
Review Comment:
Let's change these to use conn_id -- login (aka username) doesn't uniquely
identify the connection.
```suggestion
f"Can't decrypt encrypted {key!r} for conn_id={self.conn_id}
"
f"FERNET_KEY configuration is missing"
)
try:
return fernet.decrypt(bytes(value, "utf-8")).decode()
except InvalidFernetToken:
self.log.error("Can't decrypt %s for conn_id=%s, invalid token
or value", key, self.conn_id)
except Exception:
self.log.error("Can't decrypt %s for conn_id=%s, FERNET_KEY
configuration missing", key, self.conn_id)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]