Skip to content

Commit 0206214

Browse files
jason810496nailo2c
authored andcommitted
AIP-84 | Add Auth for Job (apache#47271)
1 parent 33ed4d1 commit 0206214

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
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
@@ -3953,6 +3953,8 @@ paths:
39533953
summary: Get Jobs
39543954
description: Get all jobs.
39553955
operationId: get_jobs
3956+
security:
3957+
- OAuth2PasswordBearer: []
39563958
parameters:
39573959
- name: is_alive
39583960
in: query

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
JobCollectionResponse,
4040
)
4141
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
42+
from airflow.api_fastapi.core_api.security import AccessView, requires_access_view
4243
from airflow.jobs.job import Job
4344
from airflow.utils.state import JobState
4445

@@ -48,6 +49,7 @@
4849
@job_router.get(
4950
"",
5051
responses=create_openapi_http_exception_doc([status.HTTP_400_BAD_REQUEST]),
52+
dependencies=[Depends(requires_access_view(AccessView.JOBS))],
5153
)
5254
def get_jobs(
5355
start_date_range: Annotated[

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,11 @@ def test_get_jobs(
163163
"unixname": self.scheduler_jobs[idx].unixname,
164164
}
165165
assert resp_job == expected_job
166+
167+
def test_should_raises_401_unauthenticated(self, unauthenticated_test_client):
168+
response = unauthenticated_test_client.get("/public/jobs")
169+
assert response.status_code == 401
170+
171+
def test_should_raises_403_unauthorized(self, unauthorized_test_client):
172+
response = unauthorized_test_client.get("/public/jobs")
173+
assert response.status_code == 403

0 commit comments

Comments
 (0)