-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add SSL certificate validation for Druid #9396
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,20 @@ | |
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from typing import TYPE_CHECKING | ||
import json | ||
import logging | ||
from typing import Any, Dict, TYPE_CHECKING | ||
|
||
from superset.db_engine_specs.base import BaseEngineSpec | ||
from superset.utils import core as utils | ||
|
||
if TYPE_CHECKING: | ||
from superset.connectors.sqla.models import ( # pylint: disable=unused-import | ||
TableColumn, | ||
) | ||
from superset.models.core import Database # pylint: disable=unused-import | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
class DruidEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method | ||
|
@@ -47,3 +53,27 @@ class DruidEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method | |
def alter_new_orm_column(cls, orm_col: "TableColumn") -> None: | ||
if orm_col.column_name == "__time": | ||
orm_col.is_dttm = True | ||
|
||
@staticmethod | ||
def get_extra_params(database: "Database") -> Dict[str, Any]: | ||
""" | ||
For Druid, the path to a SSL certificate is placed in `connect_args`. | ||
|
||
:param database: database instance from which to extract extras | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it's nice to add a :raises: on the docstring when a method can raise an exception |
||
:raises CertificateException: If certificate is not valid/unparseable | ||
""" | ||
try: | ||
extra = json.loads(database.extra or "{}") | ||
except json.JSONDecodeError as e: | ||
logger.error(e) | ||
raise e | ||
|
||
if database.server_cert: | ||
engine_params = extra.get("engine_params", {}) | ||
connect_args = engine_params.get("connect_args", {}) | ||
connect_args["scheme"] = "https" | ||
path = utils.create_ssl_cert_file(database.server_cert) | ||
connect_args["ssl_verify_cert"] = path | ||
villebro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
engine_params["connect_args"] = connect_args | ||
extra["engine_params"] = engine_params | ||
return extra |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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. | ||
"""add certificate to dbs | ||
|
||
Revision ID: b5998378c225 | ||
Revises: 72428d1ea401 | ||
Create Date: 2020-03-25 10:49:10.883065 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b5998378c225" | ||
down_revision = "72428d1ea401" | ||
|
||
from typing import Dict | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql.base import PGDialect | ||
from sqlalchemy_utils import EncryptedType | ||
|
||
|
||
def upgrade(): | ||
kwargs: Dict[str, str] = {} | ||
bind = op.get_bind() | ||
op.add_column( | ||
"dbs", | ||
sa.Column("server_cert", EncryptedType(sa.Text()), nullable=True, **kwargs), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense, while we're at it, to create a client_cert field also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did but took it out, as |
||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column("dbs", "server_cert") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's nice to add a
:raises:
on the docstring when a method can raise an exception