bugraoz93 commented on code in PR #43102:
URL: https://github.com/apache/airflow/pull/43102#discussion_r1828225648
##########
airflow/api_fastapi/core_api/serializers/connections.py:
##########
@@ -34,8 +36,23 @@ class ConnectionResponse(BaseModel):
login: str | None
schema_: str | None = Field(alias="schema")
port: int | None
+ password: str | None
extra: str | None
+ @field_validator("password", mode="after")
+ @classmethod
+ def redact_password(cls, v: str | None, field_info: ValidationInfo) -> str
| None:
+ if v is None:
+ return None
+ try:
+ redacted_dict = json.loads(
+ json.dumps(redact(value={field_info.field_name: v},
name=field_info.field_name))
+ )
+ redacted_password = redacted_dict.get(field_info.field_name, "***")
+ return redacted_password
+ except (json.JSONDecodeError, ValueError) as ex:
+ raise ex
Review Comment:
This worked smoothly. Indeed, my mind just didn't accept the fact the same
approach wouldn't work with the same structure. I totally missed this part
where we can pass the name for a pre-defined hidden key like a password.
:facepalm: Thanks! :) Rebased, passed the `field_name` ("password") to
`redact()`
--
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]