giftig commented on code in PR #31141:
URL: https://github.com/apache/superset/pull/31141#discussion_r1856632004


##########
superset/db_engine_specs/ydb.py:
##########
@@ -0,0 +1,94 @@
+# 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.
+from __future__ import annotations
+import json
+import logging
+from typing import (
+    Any,
+    TYPE_CHECKING,
+)
+
+from superset.constants import TimeGrain
+from superset.db_engine_specs.base import BaseEngineSpec
+
+if TYPE_CHECKING:
+    from superset.models.core import Database
+
+
+logger = logging.getLogger(__name__)
+
+
+class YDBEngineSpec(BaseEngineSpec):
+    engine = "yql"
+    engine_aliases = {"ydb", "yql+ydb"}
+    engine_name = "YDB"
+
+    default_driver = "ydb"
+
+    sqlalchemy_uri_placeholder = (
+        "ydb://{host}:{port}/{database_name}"
+    )
+
+    encrypted_extra_sensitive_fields = {"$.connect_args.credentials", 
"$.credentials"}
+
+    supports_file_upload = False
+
+    _time_grain_expressions = {
+        None: "{col}",
+    }
+
+    @staticmethod
+    def update_params_from_encrypted_extra(
+        database: Database,
+        params: dict[str, Any],
+    ) -> None:
+        if not database.encrypted_extra:
+            return
+
+        try:
+            encrypted_extra = json.loads(database.encrypted_extra)
+            connect_args = params.setdefault("connect_args", {})
+
+            if "protocol" in encrypted_extra:
+                connect_args["protocol"] = encrypted_extra.pop("protocol", 
"grpc")

Review Comment:
   I'd suggest avoiding mutating `encrypted_extra` in case the mutated data 
gets saved back to the database accidentally at some point. Just use `.get()` 
instead.
   
   Also that `"grpc"` string will never be used since you've checked the 
existence of the key first, you probably just meant to do
   
   ```python
   connect_args["protocol"] = encrypted_extra.pop("protocol", "grpc")
   ```
   in all cases



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to