anishgirianish commented on code in PR #62343:
URL: https://github.com/apache/airflow/pull/62343#discussion_r3302014853


##########
airflow-core/src/airflow/models/crypto.py:
##########
@@ -93,6 +96,65 @@ def rotate(self, msg: bytes | str) -> bytes:
         return self._fernet.rotate(msg)
 
 
+class FernetFieldsMixin:
+    """Mixin providing Fernet-encrypted ``password`` and ``extra`` fields."""
+
+    _password: Mapped[str | None] = mapped_column("password", Text(), 
nullable=True)
+    _extra: Mapped[str | None] = mapped_column("extra", Text(), nullable=True)
+    is_encrypted: Mapped[bool] = mapped_column(Boolean, unique=False, 
default=False, nullable=False)
+    is_extra_encrypted: Mapped[bool] = mapped_column(Boolean, unique=False, 
default=False, nullable=False)
+
+    def get_password(self) -> str | None:
+        """Decrypt and return password."""
+        if self._password and self.is_encrypted:
+            fernet = get_fernet()
+            if not fernet.is_encrypted:
+                raise ValueError("Can't decrypt encrypted password, FERNET_KEY 
configuration is missing")
+            return fernet.decrypt(bytes(self._password, "utf-8")).decode()
+        return self._password
+
+    def set_password(self, value: str | None):
+        """Encrypt and store password."""
+        if value:
+            fernet = get_fernet()
+            self._password = fernet.encrypt(bytes(value, "utf-8")).decode()
+            self.is_encrypted = fernet.is_encrypted
+        else:

Review Comment:
   Done. thank you



-- 
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]

Reply via email to