Antonio-RiveroMartnez commented on code in PR #21912:
URL: https://github.com/apache/superset/pull/21912#discussion_r1037480649


##########
superset/databases/ssh_tunnel/commands/update.py:
##########
@@ -0,0 +1,63 @@
+# 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.
+import logging
+from typing import Any, Dict, List, Optional
+
+from flask_appbuilder.models.sqla import Model
+from marshmallow import ValidationError
+
+from superset.commands.base import BaseCommand
+from superset.dao.exceptions import DAOUpdateFailedError
+from superset.databases.ssh_tunnel.commands.exceptions import (
+    SSHTunnelDeleteFailedError,
+    SSHTunnelInvalidError,
+    SSHTunnelNotFoundError,
+    SSHTunnelUpdateFailedError,
+)
+from superset.databases.ssh_tunnel.dao import SSHTunnelDAO
+from superset.databases.ssh_tunnel.models import SSHTunnel
+
+logger = logging.getLogger(__name__)
+
+
+class UpdateSSHTunnelCommand(BaseCommand):
+    def __init__(self, model_id: int, data: Dict[str, Any]):
+        self._properties = data.copy()
+        self._model_id = model_id
+        self._model: Optional[SSHTunnel] = None
+
+    def run(self) -> Model:
+        self.validate()
+        if not self._model:
+            raise SSHTunnelNotFoundError()
+
+        try:
+            tunnel = SSHTunnelDAO.update(self._model, self._properties, 
commit=True)
+        except DAOUpdateFailedError as ex:
+            raise SSHTunnelUpdateFailedError() from ex
+        return tunnel
+
+    def validate(self) -> None:

Review Comment:
   The API validates required fields (POST AND PUT call) and it throws errors 
if any of them is missing as evidenced in the API PR: 
https://github.com/apache/superset/pull/22199/files#diff-b94e273d2b41d3fe8a552cbf34cfa59ab9495154d16823b411470ae782cea38aR514
   
   Other than that, the PUT call works like a PATCH behind the scene (based on 
experimentation while writing the API tests), so users would be able to send: 
`required field + any combination of optional fields` and the update will work.
   
   Does this meet the validation you mention or do you want to validate also:
   1. If `private_key_password` was sent, then `private_key` is required ? (the 
other way around I believe is not needed)



-- 
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