mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: add modal to import datasets (#11910)
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import urllib.parse
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from marshmallow import Schema, validate
|
||||
@@ -48,11 +47,9 @@ class ImportDatabasesCommand(BaseCommand):
|
||||
"""Import databases"""
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def __init__(
|
||||
self, contents: Dict[str, str], *args: Any, **kwargs: Any,
|
||||
):
|
||||
def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
|
||||
self.contents = contents
|
||||
self.passwords = kwargs.get("passwords") or {}
|
||||
self.passwords: Dict[str, str] = kwargs.get("passwords") or {}
|
||||
self._configs: Dict[str, Any] = {}
|
||||
|
||||
def _import_bundle(self, session: Session) -> None:
|
||||
@@ -87,6 +84,14 @@ class ImportDatabasesCommand(BaseCommand):
|
||||
def validate(self) -> None:
|
||||
exceptions: List[ValidationError] = []
|
||||
|
||||
# load existing databases so we can apply the password validation
|
||||
db_passwords = {
|
||||
str(uuid): password
|
||||
for uuid, password in db.session.query(
|
||||
Database.uuid, Database.password
|
||||
).all()
|
||||
}
|
||||
|
||||
# verify that the metadata file is present and valid
|
||||
try:
|
||||
metadata: Optional[Dict[str, str]] = load_metadata(self.contents)
|
||||
@@ -94,14 +99,20 @@ class ImportDatabasesCommand(BaseCommand):
|
||||
exceptions.append(exc)
|
||||
metadata = None
|
||||
|
||||
# validate databases and dataset
|
||||
for file_name, content in self.contents.items():
|
||||
prefix = file_name.split("/")[0]
|
||||
schema = schemas.get(f"{prefix}/")
|
||||
if schema:
|
||||
try:
|
||||
config = load_yaml(file_name, content)
|
||||
|
||||
# populate passwords from the request or from existing DBs
|
||||
if file_name in self.passwords:
|
||||
config["password"] = self.passwords[file_name]
|
||||
elif prefix == "databases" and config["uuid"] in db_passwords:
|
||||
config["password"] = db_passwords[config["uuid"]]
|
||||
|
||||
schema.load(config)
|
||||
self._configs[file_name] = config
|
||||
except ValidationError as exc:
|
||||
|
||||
Reference in New Issue
Block a user