Lee-W commented on code in PR #43492:
URL: https://github.com/apache/airflow/pull/43492#discussion_r1843378092
##########
airflow/api_connexion/endpoints/dag_source_endpoint.py:
##########
@@ -41,32 +41,42 @@
@mark_fastapi_migration_done
@security.requires_access_dag("GET", DagAccessEntity.CODE)
@provide_session
-def get_dag_source(*, file_token: str, session: Session = NEW_SESSION) ->
Response:
- """Get source code using file token."""
- secret_key = current_app.config["SECRET_KEY"]
- auth_s = URLSafeSerializer(secret_key)
- try:
- path = auth_s.loads(file_token)
- dag_ids = session.query(DagModel.dag_id).filter(DagModel.fileloc ==
path).all()
- requests: Sequence[IsAuthorizedDagRequest] = [
- {
- "method": "GET",
- "details": DagDetails(id=dag_id[0]),
- }
- for dag_id in dag_ids
- ]
+def get_dag_source(
+ *,
+ dag_id: str,
+ version_number: int | None = None,
+ session: Session = NEW_SESSION,
+) -> Response:
+ """Get source code from DagCode."""
+ dag_version = DagVersion.get_version(dag_id, version_number,
session=session)
+ if not dag_version:
+ raise NotFound(f"The source code of the DAG {dag_id}, version_number
{version_number} was not found")
+ path = dag_version.dag_code.fileloc
+ dag_ids = session.scalars(select(DagModel.dag_id).where(DagModel.fileloc
== path)).all()
+ requests: Sequence[IsAuthorizedDagRequest] = [
+ {
+ "method": "GET",
+ "details": DagDetails(id=dag_id[0]),
+ }
+ for dag_id in dag_ids
+ ]
- # Check if user has read access to all the DAGs defined in the file
- if not get_auth_manager().batch_is_authorized_dag(requests):
- raise PermissionDenied()
- dag_source = DagCode.code(path, session=session)
- except (BadSignature, FileNotFoundError):
- raise NotFound("Dag source not found")
+ # Check if user has read access to all the DAGs defined in the file
Review Comment:
ah, got it, makes sense
--
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]