Skip to content

Commit f78194f

Browse files
jason810496nailo2c
authored andcommitted
Fix static check (apache#47302)
1 parent e3e2279 commit f78194f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6697,6 +6697,8 @@ paths:
66976697
summary: Get Log
66986698
description: Get logs for a specific task instance.
66996699
operationId: get_log
6700+
security:
6701+
- OAuth2PasswordBearer: []
67006702
parameters:
67016703
- name: dag_id
67026704
in: path

airflow/api_fastapi/core_api/routes/public/log.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import textwrap
2121

22-
from fastapi import HTTPException, Request, Response, status
22+
from fastapi import Depends, HTTPException, Request, Response, status
2323
from itsdangerous import BadSignature, URLSafeSerializer
2424
from pydantic import PositiveInt
2525
from sqlalchemy.orm import joinedload
@@ -31,6 +31,7 @@
3131
from airflow.api_fastapi.common.types import Mimetype
3232
from airflow.api_fastapi.core_api.datamodels.log import TaskInstancesLogResponse
3333
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
34+
from airflow.api_fastapi.core_api.security import DagAccessEntity, requires_access_dag
3435
from airflow.exceptions import TaskNotFound
3536
from airflow.models import TaskInstance, Trigger
3637
from airflow.models.taskinstancehistory import TaskInstanceHistory
@@ -63,6 +64,7 @@
6364
"content": text_example_response_for_get_log,
6465
},
6566
},
67+
dependencies=[Depends(requires_access_dag("GET", DagAccessEntity.TASK_LOGS))],
6668
response_model=TaskInstancesLogResponse,
6769
response_model_exclude_unset=True,
6870
)

tests/api_fastapi/core_api/routes/public/test_log.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ def test_bad_signature_raises(self):
341341
# assert response.status_code == 400
342342
assert response.json() == {"detail": "Bad Signature. Please use only the tokens provided by the API."}
343343

344+
def test_should_raises_401_unauthenticated(self, unauthenticated_test_client):
345+
response = unauthenticated_test_client.get(
346+
f"public/dags/{self.DAG_ID}/dagRuns/{self.RUN_ID}/taskInstances/{self.TASK_ID}/logs/1",
347+
headers={"Accept": "application/json"},
348+
)
349+
assert response.status_code == 401
350+
351+
def test_should_raises_403_unauthorized(self, unauthorized_test_client):
352+
response = unauthorized_test_client.get(
353+
f"public/dags/{self.DAG_ID}/dagRuns/{self.RUN_ID}/taskInstances/{self.TASK_ID}/logs/1",
354+
headers={"Accept": "application/json"},
355+
)
356+
assert response.status_code == 403
357+
344358
def test_raises_404_for_invalid_dag_run_id(self):
345359
response = self.client.get(
346360
f"public/dags/{self.DAG_ID}/dagRuns/NO_DAG_RUN/" # invalid run_id

0 commit comments

Comments
 (0)