Эх сурвалжийг харах

HUE-8758 [connectors] Offer to white/black list available connector types

Romain 6 жил өмнө
parent
commit
9e7b4e255e

+ 15 - 1
desktop/core/src/desktop/conf.py

@@ -1907,9 +1907,23 @@ ENABLE_CONNECTORS = Config(
   help=_('Turn on the Connector configuration and usage.')
 )
 
+CONNECTORS_BLACKLIST = Config(
+  key='connectors_blacklist',
+  default='',
+  type=coerce_csv,
+  help=_('Comma separated list of connector types to hide.')
+)
+
+CONNECTORS_WHITELIST = Config(
+  key='connectors_whitelist',
+  default='',
+  type=coerce_csv,
+  help=_('If not empty, comma separated list of connector types to keep.')
+)
+
 CONNECTORS = UnspecifiedConfigSection(
   key='connectors',
-  help=_("""Configuration options for connectors to external services"""),
+  help=_("""Configuration options for connectors instances to external services"""),
   each=ConfigSection(
     help=_("Id of the connector."),
     members=dict(

+ 32 - 18
desktop/core/src/desktop/lib/connectors/api.py

@@ -20,34 +20,42 @@ import logging
 
 from django.utils.translation import ugettext as _
 
-from desktop.conf import has_connectors, CONNECTORS
+from desktop.conf import has_connectors, CONNECTORS, CONNECTORS_BLACKLIST, CONNECTORS_WHITELIST
 from desktop.lib.django_util import JsonResponse, render
-from desktop.lib.connectors.lib.impala import Impala
-from desktop.lib.connectors.lib.hive import Hive
 from desktop.lib.exceptions_renderable import PopupException
 
 
 LOG = logging.getLogger(__name__)
 
 
-# TODO: automatically load modules from lib module
-# TODO: offer to white/black list available connector types
-CONNECTOR_TYPES = [{
-    'nice_name': connector.NAME,
-    'dialect': connector.TYPE,
-    'interface': connector.INTERFACE, # interfaces = ['int1', 'int2'...]
-    'settings': connector.PROPERTIES,
+CONNECTOR_TYPES = [
+  {
+    'nice_name': "Hive",
+    'dialect': 'hive',
+    'interface': 'hiveserver2',
+    'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},],
     'category': 'editor',
     'description': '',
     'properties': {'is_sql': True}
-  }
-  for connector in [
-    Impala(), Hive()
-  ]
-]
-
-CONNECTOR_TYPES += [
-  {'nice_name': "Hive Tez", 'dialect': 'hive-tez', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'category': 'editor', 'description': '', 'properties': {'is_sql': True}},
+  },
+  {
+    'nice_name': "Impala",
+    'dialect': 'impala',
+    'interface': 'hiveserver2',
+    'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},],
+    'category': 'editor',
+    'description': '',
+    'properties': {'is_sql': True}
+  },
+  {
+    'nice_name': "Hive Tez",
+    'dialect': 'hive-tez',
+    'interface': 'hiveserver2',
+    'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},],
+    'category': 'editor',
+    'description': '',
+    'properties': {'is_sql': True}
+  },
   {'nice_name': "Hive LLAP", 'dialect': 'hive-llap', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'category': 'editor', 'description': '', 'properties': {'is_sql': True}},
   {'nice_name': "Druid", 'dialect': 'sql-druid', 'interface': 'sqlalchemy', 'settings': [{'name': 'url', 'value': 'druid://druid-host.com:8082/druid/v2/sql/'}], 'category': 'editor', 'description': '', 'properties': {'is_sql': True}},
   {'nice_name': "Kafka SQL", 'dialect': 'ksql', 'interface': 'ksql', 'settings': [], 'category': 'editor', 'description': '', 'properties': {'is_sql': True}},
@@ -93,6 +101,12 @@ CONNECTOR_TYPES += [
   {'nice_name': "Celery", 'dialect': 'celery', 'settings': [], 'category': 'schedulers', 'description': '', 'properties': {}},
 ]
 
+CONNECTOR_TYPES = [connector for connector in CONNECTOR_TYPES if connector['dialect'] not in CONNECTORS_BLACKLIST.get()]
+
+if CONNECTORS_WHITELIST.get():
+  CONNECTOR_TYPES = [connector for connector in CONNECTOR_TYPES if connector['dialect'] in CONNECTORS_WHITELIST.get()]
+
+
 CATEGORIES = [
   {"name": "Editor", 'type': 'editor', 'description': ''},
   {"name": "Browsers", 'type': 'browsers', 'description': ''},

+ 0 - 15
desktop/core/src/desktop/lib/connectors/lib/__init__.py

@@ -1,15 +0,0 @@
-# Licensed to Cloudera, Inc. under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  Cloudera, Inc. 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.

+ 0 - 30
desktop/core/src/desktop/lib/connectors/lib/hive.py

@@ -1,30 +0,0 @@
-#!/usr/bin/python
-# Licensed to Cloudera, Inc. under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  Cloudera, Inc. 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.
-
-from builtins import object
-
-class Hive(object):
-  NAME = 'Hive'
-  TYPE = 'hive'
-
-  VERSION = 1
-  APP = 'notebook'
-  INTERFACE = 'hiveserver2'
-  PROPERTIES = [
-    {'name': 'server_host', 'value': ''},
-    {'name': 'server_port', 'value': ''},
-  ]

+ 0 - 30
desktop/core/src/desktop/lib/connectors/lib/impala.py

@@ -1,30 +0,0 @@
-#!/usr/bin/python
-# Licensed to Cloudera, Inc. under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  Cloudera, Inc. 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.
-
-from builtins import object
-
-class Impala(object):
-  NAME = 'Impala'
-  TYPE = 'impala'
-
-  VERSION = 1
-  APP = 'notebook'
-  INTERFACE = 'hiveserver2'
-  PROPERTIES = [
-    {'name': 'server_host', 'value': ''},
-    {'name': 'server_port', 'value': ''},
-  ]