fix: ignore system files on import (#12526)

This commit is contained in:
Beto Dealmeida 2021-01-15 15:53:55 -08:00 committed by GitHub
parent 192832c262
commit 7bef5ab4d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 21 deletions

View File

@ -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 is_valid_config, remove_root
from superset.commands.importers.v1.utils import get_contents_from_bundle
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.exceptions import SupersetSecurityException
from superset.extensions import event_logger
@ -1013,11 +1013,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
if not upload:
return self.response_400()
with ZipFile(upload) as bundle:
contents = {
remove_root(file_name): bundle.read(file_name).decode()
for file_name in bundle.namelist()
if is_valid_config(file_name)
}
contents = get_contents_from_bundle(bundle)
passwords = (
json.loads(request.form["passwords"])

View File

@ -16,6 +16,7 @@
import logging
from pathlib import Path
from typing import Any, Dict
from zipfile import ZipFile
import yaml
from marshmallow import fields, Schema, validate
@ -87,3 +88,11 @@ def is_valid_config(file_name: str) -> bool:
return False
return True
def get_contents_from_bundle(bundle: ZipFile) -> Dict[str, str]:
return {
remove_root(file_name): bundle.read(file_name).decode()
for file_name in bundle.namelist()
if is_valid_config(file_name)
}

View File

@ -31,7 +31,7 @@ from werkzeug.wsgi import FileWrapper
from superset import is_feature_enabled, thumbnail_cache
from superset.commands.exceptions import CommandInvalidError
from superset.commands.importers.v1.utils import remove_root
from superset.commands.importers.v1.utils import get_contents_from_bundle
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.dashboards.commands.bulk_delete import BulkDeleteDashboardCommand
from superset.dashboards.commands.create import CreateDashboardCommand
@ -729,10 +729,7 @@ class DashboardRestApi(BaseSupersetModelRestApi):
if not upload:
return self.response_400()
with ZipFile(upload) as bundle:
contents = {
remove_root(file_name): bundle.read(file_name).decode()
for file_name in bundle.namelist()
}
contents = get_contents_from_bundle(bundle)
passwords = (
json.loads(request.form["passwords"])

View File

@ -29,7 +29,7 @@ from sqlalchemy.exc import NoSuchTableError, OperationalError, SQLAlchemyError
from superset import event_logger
from superset.commands.exceptions import CommandInvalidError
from superset.commands.importers.v1.utils import remove_root
from superset.commands.importers.v1.utils import get_contents_from_bundle
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.databases.commands.create import CreateDatabaseCommand
from superset.databases.commands.delete import DeleteDatabaseCommand
@ -778,10 +778,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
if not upload:
return self.response_400()
with ZipFile(upload) as bundle:
contents = {
remove_root(file_name): bundle.read(file_name).decode()
for file_name in bundle.namelist()
}
contents = get_contents_from_bundle(bundle)
passwords = (
json.loads(request.form["passwords"])

View File

@ -31,7 +31,7 @@ from marshmallow import ValidationError
from superset import event_logger, is_feature_enabled
from superset.commands.exceptions import CommandInvalidError
from superset.commands.importers.v1.utils import remove_root
from superset.commands.importers.v1.utils import get_contents_from_bundle
from superset.connectors.sqla.models import SqlaTable
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.databases.filters import DatabaseFilter
@ -687,10 +687,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
if not upload:
return self.response_400()
with ZipFile(upload) as bundle:
contents = {
remove_root(file_name): bundle.read(file_name).decode()
for file_name in bundle.namelist()
}
contents = get_contents_from_bundle(bundle)
passwords = (
json.loads(request.form["passwords"])