You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2021/01/13 18:40:36 UTC

[superset] 02/02: fix: import ZIP files that have been modified (#12425)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch 1.0
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 78e4b02305f36243d9b745efef26f7fa8d9986b2
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Jan 12 12:56:26 2021 -0800

    fix: import ZIP files that have been modified (#12425)
    
    * fix: import ZIP files that have been modified
    
    * Add unit test
---
 superset/charts/api.py                  |  3 ++-
 superset/commands/importers/v1/utils.py | 14 ++++++++++++++
 tests/commands_test.py                  | 11 +++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/superset/charts/api.py b/superset/charts/api.py
index 9611a26..2d46cce 100644
--- a/superset/charts/api.py
+++ b/superset/charts/api.py
@@ -63,7 +63,7 @@ from superset.charts.schemas import (
     thumbnail_query_schema,
 )
 from superset.commands.exceptions import CommandInvalidError
-from superset.commands.importers.v1.utils import remove_root
+from superset.commands.importers.v1.utils import is_valid_config, remove_root
 from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
 from superset.exceptions import SupersetSecurityException
 from superset.extensions import event_logger
@@ -976,6 +976,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
             contents = {
                 remove_root(file_name): bundle.read(file_name).decode()
                 for file_name in bundle.namelist()
+                if is_valid_config(file_name)
             }
 
         passwords = (
diff --git a/superset/commands/importers/v1/utils.py b/superset/commands/importers/v1/utils.py
index a94ae18..a5dd09c 100644
--- a/superset/commands/importers/v1/utils.py
+++ b/superset/commands/importers/v1/utils.py
@@ -73,3 +73,17 @@ def load_metadata(contents: Dict[str, str]) -> Dict[str, str]:
         raise exc
 
     return metadata
+
+
+def is_valid_config(file_name: str) -> bool:
+    path = Path(file_name)
+
+    # ignore system files that might've been added to the bundle
+    if path.name.startswith(".") or path.name.startswith("_"):
+        return False
+
+    # ensure extension is YAML
+    if path.suffix.lower() not in {".yaml", ".yml"}:
+        return False
+
+    return True
diff --git a/tests/commands_test.py b/tests/commands_test.py
index ee10903..08c8d7a 100644
--- a/tests/commands_test.py
+++ b/tests/commands_test.py
@@ -17,6 +17,7 @@
 # pylint: disable=no-self-use
 
 from superset.commands.exceptions import CommandInvalidError
+from superset.commands.importers.v1.utils import is_valid_config
 from tests.base_tests import SupersetTestCase
 
 
@@ -24,3 +25,13 @@ class TestCommandsExceptions(SupersetTestCase):
     def test_command_invalid_error(self):
         exception = CommandInvalidError("A test")
         assert str(exception) == "A test"
+
+
+class TestImportersV1Utils(SupersetTestCase):
+    def test_is_valid_config(self):
+        assert is_valid_config("metadata.yaml")
+        assert is_valid_config("databases/examples.yaml")
+        assert not is_valid_config(".DS_Store")
+        assert not is_valid_config(
+            "__MACOSX/chart_export_20210111T145253/databases/._examples.yaml"
+        )