Skip to content

Commit b657ae9

Browse files
authored
D401 Support - Airflow/api thru Airflow/auth (#33333)
1 parent 740c263 commit b657ae9

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

airflow/api_connexion/endpoints/role_and_permission_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
def _check_action_and_resource(sm: AirflowSecurityManager, perms: list[tuple[str, str]]) -> None:
4444
"""
45-
Checks if the action or resource exists and otherwise raise 400.
45+
Check if the action or resource exists and otherwise raise 400.
4646
4747
This function is intended for use in the REST API because it raise 400
4848
"""

airflow/api_connexion/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141
def common_error_handler(exception: BaseException) -> flask.Response:
42-
"""Used to capture connexion exceptions and add link to the type field."""
42+
"""Use to capture connexion exceptions and add link to the type field."""
4343
if isinstance(exception, ProblemException):
4444

4545
link = EXCEPTIONS_LINK_MAP.get(exception.status)

airflow/api_connexion/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
def validate_istimezone(value: datetime) -> None:
36-
"""Validates that a datetime is not naive."""
36+
"""Validate that a datetime is not naive."""
3737
if not value.tzinfo:
3838
raise BadRequest("Invalid datetime format", detail="Naive datetime is disallowed")
3939

@@ -85,7 +85,7 @@ def check_limit(value: int) -> int:
8585

8686
def format_parameters(params_formatters: dict[str, Callable[[Any], Any]]) -> Callable[[T], T]:
8787
"""
88-
Decorator factory that create decorator that convert parameters using given formatters.
88+
Create a decorator to convert parameters using given formatters.
8989
9090
Using it allows you to separate parameter formatting from endpoint logic.
9191

airflow/api_connexion/schemas/dag_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def get_concurrency(obj: DAG):
117117

118118
@staticmethod
119119
def get_tags(obj: DAG):
120-
"""Dumps tags as objects."""
120+
"""Dump tags as objects."""
121121
tags = obj.tags
122122
if tags:
123123
return [DagTagSchema().dump(dict(name=tag)) for tag in tags]
@@ -132,12 +132,12 @@ def get_owners(obj: DAG):
132132

133133
@staticmethod
134134
def get_is_paused(obj: DAG):
135-
"""Checks entry in DAG table to see if this DAG is paused."""
135+
"""Check entry in DAG table to see if this DAG is paused."""
136136
return obj.get_is_paused()
137137

138138
@staticmethod
139139
def get_is_active(obj: DAG):
140-
"""Checks entry in DAG table to see if this DAG is active."""
140+
"""Check entry in DAG table to see if this DAG is active."""
141141
return obj.get_is_active()
142142

143143
@staticmethod

airflow/api_connexion/schemas/pool_schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,32 @@ class Meta:
4646

4747
@staticmethod
4848
def get_occupied_slots(obj: Pool) -> int:
49-
"""Returns the occupied slots of the pool."""
49+
"""Return the occupied slots of the pool."""
5050
return obj.occupied_slots()
5151

5252
@staticmethod
5353
def get_running_slots(obj: Pool) -> int:
54-
"""Returns the running slots of the pool."""
54+
"""Return the running slots of the pool."""
5555
return obj.running_slots()
5656

5757
@staticmethod
5858
def get_queued_slots(obj: Pool) -> int:
59-
"""Returns the queued slots of the pool."""
59+
"""Return the queued slots of the pool."""
6060
return obj.queued_slots()
6161

6262
@staticmethod
6363
def get_scheduled_slots(obj: Pool) -> int:
64-
"""Returns the scheduled slots of the pool."""
64+
"""Return the scheduled slots of the pool."""
6565
return obj.scheduled_slots()
6666

6767
@staticmethod
6868
def get_deferred_slots(obj: Pool) -> int:
69-
"""Returns the deferred slots of the pool."""
69+
"""Return the deferred slots of the pool."""
7070
return obj.deferred_slots()
7171

7272
@staticmethod
7373
def get_open_slots(obj: Pool) -> float:
74-
"""Returns the open slots of the pool."""
74+
"""Return the open slots of the pool."""
7575
return obj.open_slots()
7676

7777

airflow/api_connexion/schemas/task_instance_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ClearTaskInstanceFormSchema(Schema):
135135

136136
@validates_schema
137137
def validate_form(self, data, **kwargs):
138-
"""Validates clear task instance form."""
138+
"""Validate clear task instance form."""
139139
if data["only_failed"] and data["only_running"]:
140140
raise ValidationError("only_failed and only_running both are set to True")
141141
if data["start_date"] and data["end_date"]:
@@ -169,7 +169,7 @@ class SetTaskInstanceStateFormSchema(Schema):
169169

170170
@validates_schema
171171
def validate_form(self, data, **kwargs):
172-
"""Validates set task instance state form."""
172+
"""Validate set task instance state form."""
173173
if not exactly_one(data.get("execution_date"), data.get("dag_run_id")):
174174
raise ValidationError("Exactly one of execution_date or dag_run_id must be provided")
175175

airflow/api_connexion/security.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def check_authentication() -> None:
31-
"""Checks that the request has valid authorization information."""
31+
"""Check that the request has valid authorization information."""
3232
for auth in get_airflow_app().api_auth:
3333
response = auth.requires_authentication(Response)()
3434
if response.status_code == 200:
@@ -39,7 +39,7 @@ def check_authentication() -> None:
3939

4040

4141
def requires_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
42-
"""Factory for decorator that checks current user's permissions against required permissions."""
42+
"""Check current user's permissions against required permissions."""
4343
appbuilder = get_airflow_app().appbuilder
4444
if appbuilder.update_perms:
4545
appbuilder.sm.sync_resource_permissions(permissions)

airflow/api_internal/endpoints/rpc_api_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _initialize_map() -> dict[str, Callable]:
6565

6666

6767
def internal_airflow_api(body: dict[str, Any]) -> APIResponse:
68-
"""Handler for Internal API /internal_api/v1/rpcapi endpoint."""
68+
"""Handle Internal API /internal_api/v1/rpcapi endpoint."""
6969
log.debug("Got request")
7070
json_rpc = body.get("jsonrpc")
7171
if json_rpc != "2.0":

airflow/api_internal/internal_api_call.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class InternalApiConfig:
4242

4343
@staticmethod
4444
def force_database_direct_access():
45-
"""Current component will not use Internal API.
45+
"""
46+
Block current component from using Internal API.
4647
4748
All methods decorated with internal_api_call will always be executed locally.
4849
This mode is needed for "trusted" components like Scheduler, Webserver or Internal Api server.
@@ -80,7 +81,8 @@ def _init_values():
8081

8182

8283
def internal_api_call(func: Callable[PS, RT]) -> Callable[PS, RT]:
83-
"""Decorator for methods which may be executed in database isolation mode.
84+
"""
85+
Allow methods to be executed in database isolation mode.
8486
8587
If [core]database_access_isolation is true then such method are not executed locally,
8688
but instead RPC call is made to Database API (aka Internal API). This makes some components

0 commit comments

Comments
 (0)