Skip to content
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

Add HTTP Basic Auth for Druid (Issue #4776) #6795

Merged
merged 6 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ class DruidCluster(Model, AuditMixinNullable, ImportMixin):
broker_endpoint = Column(String(255), default='druid/v2')
metadata_last_refreshed = Column(DateTime)
cache_timeout = Column(Integer)
broker_user = Column(String(255))
broker_pass = Column(String(255))
donbowman marked this conversation as resolved.
Show resolved Hide resolved

export_fields = ('cluster_name', 'broker_host', 'broker_port',
'broker_endpoint', 'cache_timeout')
'broker_endpoint', 'cache_timeout', 'broker_user',
'broker_pass')
donbowman marked this conversation as resolved.
Show resolved Hide resolved
donbowman marked this conversation as resolved.
Show resolved Hide resolved
update_from_object_fields = export_fields
export_children = ['datasources']

Expand Down Expand Up @@ -139,16 +142,20 @@ def get_pydruid_client(self):
cli = PyDruid(
self.get_base_url(self.broker_host, self.broker_port),
self.broker_endpoint)
if self.broker_user and self.broker_pass:
cli.set_basic_auth_credentials(self.broker_user, self.broker_pass)
return cli

def get_datasources(self):
endpoint = self.get_base_broker_url() + '/datasources'
return json.loads(requests.get(endpoint).text)
auth = requests.auth.HTTPBasicAuth(self.broker_user, self.broker_pass)
return json.loads(requests.get(endpoint, auth=auth).text)

def get_druid_version(self):
endpoint = self.get_base_url(
self.broker_host, self.broker_port) + '/status'
return json.loads(requests.get(endpoint).text)['version']
auth = requests.auth.HTTPBasicAuth(self.broker_user, self.broker_pass)
return json.loads(requests.get(endpoint, auth=auth).text)['version']

@property
@utils.memoized
Expand Down
5 changes: 4 additions & 1 deletion superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class DruidClusterModelView(SupersetModelView, DeleteMixin, YamlExportMixin): #

add_columns = [
'verbose_name', 'broker_host', 'broker_port',
'broker_endpoint', 'cache_timeout', 'cluster_name',
'broker_user', 'broker_pass', 'broker_endpoint',
'cache_timeout', 'cluster_name',
]
edit_columns = add_columns
list_columns = ['cluster_name', 'metadata_last_refreshed']
Expand All @@ -176,6 +177,8 @@ class DruidClusterModelView(SupersetModelView, DeleteMixin, YamlExportMixin): #
'cluster_name': _('Cluster'),
'broker_host': _('Broker Host'),
'broker_port': _('Broker Port'),
'broker_user': _('Broker Username'),
donbowman marked this conversation as resolved.
Show resolved Hide resolved
'broker_pass': _('Broker Password'),
'broker_endpoint': _('Broker Endpoint'),
'verbose_name': _('Verbose Name'),
'cache_timeout': _('Cache Timeout'),
Expand Down
42 changes: 42 additions & 0 deletions superset/migrations/versions/b94b03d92795_add_druid_auth_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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_druid_auth.py

Revision ID: b94b03d92795
Revises: 18dc26817ad2
Create Date: 2019-01-31 15:09:54.944703

"""

# revision identifiers, used by Alembic.
revision = 'b94b03d92795'
down_revision = '18dc26817ad2'

from alembic import op
import sqlalchemy as sa


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('clusters', sa.Column('broker_pass', sa.String(length=255), nullable=True))
op.add_column('clusters', sa.Column('broker_user', sa.String(length=255), nullable=True))

def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('clusters', 'broker_user')
op.drop_column('clusters', 'broker_pass')
# ### end Alembic commands ###