aminghadersohi commented on code in PR #43827: URL: https://github.com/apache/superset/pull/43827#discussion_r4042433272
########## superset/commands/semantic_layer/utils.py: ########## @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Shared validation for semantic layer configuration commands.""" + +from __future__ import annotations + +from typing import Any + +from pydantic import ValidationError +from superset_core.semantic_layers.layer import SemanticLayer + +from superset.commands.semantic_layer.exceptions import SemanticLayerInvalidError + + +def validate_configuration( + layer_class: type[SemanticLayer[Any, Any]], configuration: dict[str, Any] +) -> None: + """Validate provider configuration without exposing values in error traces.""" + try: + layer_class.from_configuration(configuration) + except ValidationError as ex: + # Messages and context can contain credentials even when input is omitted. + # Retain only structural paths and error codes, never the original cause. + details: str = "; ".join( + f"{'.'.join(map(str, error['loc'])) or '<root>'}: {error['type']}" + for error in ex.errors( + include_input=False, include_url=False, include_context=False + ) + ) + raise SemanticLayerInvalidError(f"Invalid configuration: {details}") from None Review Comment: Only `ValidationError` is caught, so any other provider exception carries the restored credential into `api.py`'s `exc_info=True` sink. Reproduced on PUT with the client sending only the mask; the merge base logs nothing — the new recursive restore is what reaches it. ```suggestion raise SemanticLayerInvalidError(f"Invalid configuration: {details}") from None except Exception: # pylint: disable=broad-except # A provider may interpolate the restored credential into a # non-pydantic error; never let one reach an exc_info log sink. raise ValueError("Provider rejected the configuration") from None ``` -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
