You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/10/20 16:01:54 UTC

[superset] branch create-sshtunnelconfig-tbl updated: create migration

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

hugh pushed a commit to branch create-sshtunnelconfig-tbl
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/create-sshtunnelconfig-tbl by this push:
     new 2c1e7363c4 create migration
2c1e7363c4 is described below

commit 2c1e7363c4c94b5a0a7a3094e911190a86eac9b3
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Oct 20 12:01:38 2022 -0400

    create migration
---
 superset/databases/models.py                       | 30 ++++++-
 ...c2d8ec8595_create_ssh_tunnel_credentials_tbl.py | 98 ++++++++++++++++++++++
 2 files changed, 124 insertions(+), 4 deletions(-)

diff --git a/superset/databases/models.py b/superset/databases/models.py
index 2595ca452b..f1dfe5f1aa 100644
--- a/superset/databases/models.py
+++ b/superset/databases/models.py
@@ -20,6 +20,7 @@ import sqlalchemy as sa
 from flask_appbuilder import Model
 from sqlalchemy.orm import backref, relationship
 
+from superset import app
 from superset.models.core import Database
 from superset.models.helpers import (
     AuditMixinNullable,
@@ -27,20 +28,41 @@ from superset.models.helpers import (
     ImportExportMixin,
 )
 
+app_config = app.config
 
-class SSHTunnelConfiguration(
+
+class SSHTunnelCredentials(
     Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin
 ):
     """
-    A table/view in a database.
+    A ssh tunnel configuration in a database.
     """
 
-    __tablename__ = "sl_datasets"
+    __tablename__ = "ssh_tunnel_credentials"
 
     id = sa.Column(sa.Integer, primary_key=True)
     database_id = sa.Column(sa.Integer, sa.ForeignKey("dbs.id"), nullable=False)
     database: Database = relationship(
         "Database",
-        backref=backref("datasets", cascade="all, delete-orphan"),
+        backref=backref("ssh_tunnel_credentials", cascade="all, delete-orphan"),
         foreign_keys=[database_id],
     )
+
+    server_address = sa.Column(sa.EncryptedType(sa.String, app_config["SECRET_KEY"]))
+    server_port = sa.Column(sa.EncryptedType(sa.String, app_config["SECRET_KEY"]))
+
+    # basic authentication
+    username = sa.Column(
+        sa.EncryptedType(sa.String, app_config["SECRET_KEY"]), nullable=True
+    )
+    password = sa.Column(
+        sa.EncryptedType(sa.String, app_config["SECRET_KEY"]), nullable=True
+    )
+
+    # password protected pkey authentication
+    pkey = sa.Column(
+        sa.EncryptedType(sa.String, app_config["SECRET_KEY"]), nullable=True
+    )
+    private_key = sa.Column(
+        sa.EncryptedType(sa.String, app_config["SECRET_KEY"]), nullable=True
+    )
diff --git a/superset/migrations/versions/2022-10-20_10-48_f3c2d8ec8595_create_ssh_tunnel_credentials_tbl.py b/superset/migrations/versions/2022-10-20_10-48_f3c2d8ec8595_create_ssh_tunnel_credentials_tbl.py
new file mode 100644
index 0000000000..fa448a6888
--- /dev/null
+++ b/superset/migrations/versions/2022-10-20_10-48_f3c2d8ec8595_create_ssh_tunnel_credentials_tbl.py
@@ -0,0 +1,98 @@
+# 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.
+"""create_ssh_tunnel_credentials_tbl
+
+Revision ID: f3c2d8ec8595
+Revises: deb4c9d4a4ef
+Create Date: 2022-10-20 10:48:08.722861
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "f3c2d8ec8595"
+down_revision = "deb4c9d4a4ef"
+
+from uuid import uuid4
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy_utils import UUIDType
+
+from superset import app
+
+app_config = app.config
+
+
+def upgrade():
+    op.create_table(
+        "ssh_tunnel_credential",
+        # AuditMixinNullable
+        sa.Column("created_on", sa.DateTime(), nullable=True),
+        sa.Column("changed_on", sa.DateTime(), nullable=True),
+        sa.Column("created_by_fk", sa.Integer(), nullable=True),
+        sa.Column("changed_by_fk", sa.Integer(), nullable=True),
+        # ExtraJSONMixin
+        sa.Column("extra_json", sa.Text(), nullable=True),
+        # ImportExportMixin
+        sa.Column("uuid", UUIDType(binary=True), primary_key=False, default=uuid4),
+        # specific to model
+        sa.Column("server_port", sa.EncryptedType(sa.String, app_config["SECRET_KEY"])),
+        sa.Column(
+            "server_address", sa.EncryptedType(sa.String, app_config["SECRET_KEY"])
+        ),
+        sa.Column(
+            "username",
+            sa.EncryptedType(sa.String, app_config["SECRET_KEY"]),
+            nullable=True,
+        ),
+        sa.Column(
+            "password",
+            sa.EncryptedType(sa.String, app_config["SECRET_KEY"]),
+            nullable=True,
+        ),
+        sa.Column(
+            "pkey", sa.EncryptedType(sa.String, app_config["SECRET_KEY"]), nullable=True
+        ),
+        sa.Column(
+            "private_key_password",
+            sa.EncryptedType(sa.String, app_config["SECRET_KEY"]),
+            nullable=True,
+        ),
+    )
+
+    op.create_table(
+        "database_ssh_tunnel_credential",
+        sa.Column(
+            "ssh_tunnel_credential_id",
+            sa.INTEGER(),
+            autoincrement=False,
+            nullable=False,
+        ),
+        sa.Column("database_id", sa.INTEGER(), autoincrement=False, nullable=False),
+        sa.ForeignKeyConstraint(
+            ["database_id"], ["dbs.id"], name="database_ssh_tunnel_credential_ibfk_1"
+        ),
+        sa.ForeignKeyConstraint(
+            ["ssh_tunnel_credentials_id"],
+            ["ssh_tunnel_credentials.id"],
+            name="database_ssh_tunnel_credential_ibfk_2",
+        ),
+    )
+
+
+def downgrade():
+    op.drop_table("ssh_tunnel_credentials")