amoghrajesh commented on code in PR #52876:
URL: https://github.com/apache/airflow/pull/52876#discussion_r2191926795
##########
airflow-core/src/airflow/models/dagbundle.py:
##########
@@ -40,6 +44,59 @@ class DagBundleModel(Base):
active = Column(Boolean, default=True)
version = Column(String(200), nullable=True)
last_refreshed = Column(UtcDateTime, nullable=True)
+ url_template = Column(String(200), nullable=True)
+ template_params = Column(JSONType, nullable=True)
- def __init__(self, *, name: str):
+ def __init__(self, *, name: str, version: str | None = None):
+ super().__init__()
self.name = name
+ self.version = version
+
+ def _unsign_url(self) -> str | None:
+ """
+ Unsign a URL token to get the original URL template.
+
+ :param signed_url: The signed URL token
+ :return: The original URL template or None if unsigning fails
+ """
+ try:
+ from itsdangerous import BadSignature, URLSafeSerializer
+
+ from airflow.configuration import conf
+
+ serializer = URLSafeSerializer(conf.get_mandatory_value("core",
"fernet_key"))
+ payload = serializer.loads(self.url_template)
+ if isinstance(payload, dict) and "url" in payload and
"bundle_name" in payload:
+ if payload["bundle_name"] == self.name:
+ return payload["url"]
+
+ return None
+ except (BadSignature, Exception):
+ return None
+
+ def render_url(self, version: str | None = None) -> str | None:
+ """
+ Render the URL template with the given version and stored template
parameters.
+
+ First unsigns the URL to get the original template, then formats it
with
+ the provided version and any additional parameters.
+
+ :param version: The version to substitute in the template
+ :return: The rendered URL or None if no template is available
+ """
+ if not self.url_template:
+ return None
+
+ url_template = self._unsign_url()
+
+ if url_template is None:
+ url_template = self.url_template
Review Comment:
What behaviour did we have earlier? If we couldn't construct the url, would
we return null?
--
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]