浏览代码

[slack] Move credentials in [[slack]] ini properties

Harshg999 4 年之前
父节点
当前提交
fde2a5fb5e

+ 8 - 3
desktop/conf.dist/hue.ini

@@ -820,9 +820,14 @@
   # Configuration options for Slack
   # ------------------------------------------------------------------------
   [[slack]]
-
-   # Turns on Slack application API endpoints
-   ## is_enabled=false
+    # Slack credentials
+    ## slack_client_id=
+    ## slack_client_secret=
+    ## slack_verification_token=
+    ## slack_bot_user_token=
+    
+    # Enables Slack application API endpoints
+    ## is_enabled=true
 
 
   # Configuration options for the request Tracing

+ 8 - 3
desktop/conf/pseudo-distributed.ini.tmpl

@@ -822,9 +822,14 @@
   # Configuration options for Slack
   # ------------------------------------------------------------------------
   [[slack]]
-
-   # Turns on Slack application API endpoints
-   ## is_enabled=false
+    # Slack credentials
+    ## slack_client_id=
+    ## slack_client_secret=
+    ## slack_verification_token=
+    ## slack_bot_user_token=
+    
+    # Enables Slack application API endpoints
+    ## is_enabled=true
 
 
   # Configuration options for the request Tracing

+ 40 - 2
desktop/core/src/desktop/conf.py

@@ -130,6 +130,19 @@ def is_https_enabled():
   """Hue is configured for HTTPS."""
   return bool(SSL_CERTIFICATE.get() and SSL_PRIVATE_KEY.get())
 
+def get_slack_client_id():
+  return os.environ.get('SLACK_CLIENT_ID')
+
+def get_slack_client_secret():
+  return os.environ.get('SLACK_CLIENT_SECRET')
+
+def get_slack_verification_token():
+  return os.environ.get('SLACK_VERIFICATION_TOKEN')
+
+def get_slack_bot_user_token():
+  return os.environ.get('SLACK_BOT_USER_TOKEN')
+
+
 USE_CHERRYPY_SERVER = Config(
   key="use_cherrypy_server",
   help=_("If set to true, CherryPy will be used. Otherwise, Gunicorn will be used as the webserver."),
@@ -717,9 +730,34 @@ SLACK = ConfigSection(
   members=dict(
     IS_ENABLED=Config(
       key='is_enabled',
-      help=_('Turns on Slack application API endpoints'),
+      help=_('Enables Slack application API endpoints'),
+      type=coerce_bool,
       default=False,
-      type=coerce_bool),
+      ),
+    SLACK_CLIENT_ID=Config(
+        key='slack_client_id',
+        type=str,
+        private=True,
+        dynamic_default=get_slack_client_id,
+      ),
+    SLACK_CLIENT_SECRET=Config(
+        key='slack_client_secret',
+        type=str,
+        private=True,
+        dynamic_default=get_slack_client_secret,
+      ),
+    SLACK_VERIFICATION_TOKEN=Config(
+        key='slack_verification_token',
+        type=str,
+        private=True,
+        dynamic_default=get_slack_verification_token,
+      ),
+    SLACK_BOT_USER_TOKEN=Config(
+        key='slack_bot_user_token',
+        type=str,
+        private=True,
+        dynamic_default=get_slack_bot_user_token,
+      ),
   )
 )
 

+ 4 - 6
desktop/core/src/desktop/settings.py

@@ -823,10 +823,8 @@ except ValueError:
 ################################################################
 # SLACK API Configurations
 ################################################################
-# Warning: Do not save your secrets here, instead export them as environment variables and read here
 
-# use your keys 
-SLACK_CLIENT_ID = ''
-SLACK_CLIENT_SECRET = ''
-SLACK_VERIFICATION_TOKEN = os.environ.get('SLACK_VERIFICATION_TOKEN')
-SLACK_BOT_USER_TOKEN = os.environ.get('SLACK_BOT_USER_TOKEN')
+SLACK_CLIENT_ID = desktop.conf.SLACK.SLACK_CLIENT_ID.get()
+SLACK_CLIENT_SECRET = desktop.conf.SLACK.SLACK_CLIENT_SECRET.get()
+SLACK_VERIFICATION_TOKEN = desktop.conf.SLACK.SLACK_VERIFICATION_TOKEN.get()
+SLACK_BOT_USER_TOKEN = desktop.conf.SLACK.SLACK_BOT_USER_TOKEN.get()