docstr: Import saved queries with associated databases.
  ---
  post:
    summary: Import saved queries with associated databases
    requestBody:
      required: true
      content:
        multipart/form-data:
          schema:
            type: object
            properties:
              formData:
                description: upload file (ZIP)
                type: string
                format: binary
              passwords:
                description: >-
                  JSON map of passwords for each featured database in the
                  ZIP file. If the ZIP includes a database config in the path
                  `databases/MyDatabase.yaml`, the password should be provided
                  in the following format:
                  `{"databases/MyDatabase.yaml": "my_password"}`.
                type: string
              overwrite:
                description: overwrite existing saved queries?
                type: boolean
              ssh_tunnel_passwords:
                description: >-
                  JSON map of passwords for each ssh_tunnel associated to a
                  featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the password should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_password"}`.
                type: string
              ssh_tunnel_private_keys:
                description: >-
                  JSON map of private_keys for each ssh_tunnel associated to a
                  featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the private_key should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_private_key"}`.
                type: string
              ssh_tunnel_private_key_passwords:
                description: >-
                  JSON map of private_key_passwords for each ssh_tunnel associated
                  to a featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the private_key should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_private_key_password"}`.
                type: string
    responses:
      200:
        description: Saved Query import result
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      422:
        $ref: '#/components/responses/422'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Import","saved","queries","with","associated","databases",".","--","-","post",":","summary",":","Import","saved","queries","with","associated","databases","requestBody",":","required",":","true","content",":","multipart\/form-data",":","schema",":","type",":","object","properties",":","formData",":","description",":","upload","file","(","ZIP",")","type",":","string","format",":","binary","passwords",":","description",":",">","-","JSON","map","of","passwords","for","each","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","database","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","password","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_password","''","}","`",".","type",":","string","overwrite",":","description",":","overwrite","existing","saved","queries","?","type",":","boolean","ssh_tunnel_passwords",":","description",":",">","-","JSON","map","of","passwords","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","password","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_password","''","}","`",".","type",":","string","ssh_tunnel_private_keys",":","description",":",">","-","JSON","map","of","private_keys","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","private_key","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_private_key","''","}","`",".","type",":","string","ssh_tunnel_private_key_passwords",":","description",":",">","-","JSON","map","of","private_key_passwords","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","private_key","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_private_key_password","''","}","`",".","type",":","string","responses",":","200",":","description",":","Saved","Query","import","result","content",":","application\/json",":","schema",":","type",":","object","properties",":","message",":","type",":","string","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","422",":","$","ref",":","'","#","\/components\/responses\/422'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def import_(self) -> Response:
      """Import saved queries with associated databases.
      ---
      post:
        summary: Import saved queries with associated databases
        requestBody:
          required: true
          content:
            multipart/form-data:
              schema:
                type: object
                properties:
                  formData:
                    description: upload file (ZIP)
                    type: string
                    format: binary
                  passwords:
                    description: >-
                      JSON map of passwords for each featured database in the
                      ZIP file. If the ZIP includes a database config in the path
                      `databases/MyDatabase.yaml`, the password should be provided
                      in the following format:
                      `{"databases/MyDatabase.yaml": "my_password"}`.
                    type: string
                  overwrite:
                    description: overwrite existing saved queries?
                    type: boolean
                  ssh_tunnel_passwords:
                    description: >-
                      JSON map of passwords for each ssh_tunnel associated to a
                      featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the password should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_password"}`.
                    type: string
                  ssh_tunnel_private_keys:
                    description: >-
                      JSON map of private_keys for each ssh_tunnel associated to a
                      featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the private_key should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_private_key"}`.
                    type: string
                  ssh_tunnel_private_key_passwords:
                    description: >-
                      JSON map of private_key_passwords for each ssh_tunnel associated
                      to a featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the private_key should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_private_key_password"}`.
                    type: string
        responses:
          200:
            description: Saved Query import result
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    message:
                      type: string
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          422:
            $ref: '#/components/responses/422'
          500:
            $ref: '#/components/responses/500'
      """
      upload = request.files.get("formData")
      if not upload:
          return self.response_400()
      if not is_zipfile(upload):
          raise IncorrectFormatError("Not a ZIP file")
      with ZipFile(upload) as bundle:
          contents = get_contents_from_bundle(bundle)
  
      if not contents:
          raise NoValidFilesFoundError()
  
      passwords = (
          json.loads(request.form["passwords"])
          if "passwords" in request.form
          else None
      )
      overwrite = request.form.get("overwrite") == "true"
      ssh_tunnel_passwords = (
          json.loads(request.form["ssh_tunnel_passwords"])
          if "ssh_tunnel_passwords" in request.form
          else None
      )
      ssh_tunnel_private_keys = (
          json.loads(request.form["ssh_tunnel_private_keys"])
          if "ssh_tunnel_private_keys" in request.form
          else None
      )
      ssh_tunnel_priv_key_passwords = (
          json.loads(request.form["ssh_tunnel_private_key_passwords"])
          if "ssh_tunnel_private_key_passwords" in request.form
          else None
      )
  
      command = ImportSavedQueriesCommand(
          contents,
          passwords=passwords,
          overwrite=overwrite,
          ssh_tunnel_passwords=ssh_tunnel_passwords,
          ssh_tunnel_private_keys=ssh_tunnel_private_keys,
          ssh_tunnel_priv_key_passwords=ssh_tunnel_priv_key_passwords,
      )
      command.run()
      return self.response(200, message="OK")
  
imports: import json
  import logging
  from datetime import datetime
  from io import BytesIO
  from typing import Any
  from zipfile import is_zipfile, ZipFile
  from flask import g, request, Response, send_file
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from flask_babel import ngettext
  from superset import is_feature_enabled
  from superset.commands.importers.exceptions import IncorrectFormatError, NoValidFilesFoundError
  from superset.commands.importers.v1.utils import get_contents_from_bundle
  from superset.commands.query.delete import DeleteSavedQueryCommand
  from superset.commands.query.exceptions import SavedQueryDeleteFailedError, SavedQueryNotFoundError
  from superset.commands.query.export import ExportSavedQueriesCommand
  from superset.commands.query.importers.dispatcher import ImportSavedQueriesCommand
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.databases.filters import DatabaseFilter
  from superset.extensions import event_logger
  from superset.models.sql_lab import SavedQuery
  from superset.queries.saved_queries.filters import SavedQueryAllTextFilter, SavedQueryFavoriteFilter, SavedQueryFilter, SavedQueryTagFilter
  from superset.queries.saved_queries.schemas import get_delete_ids_schema, get_export_ids_schema, openapi_spec_methods_override
  from superset.views.base_api import BaseSupersetModelRestApi, requires_form_data, statsd_metrics
label_desc: Use image node_id 5 for calling the SavedQueryRestApi obj's underlying member method code with example usage: obj.import_() and returns: self, self