You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2020/03/04 13:58:07 UTC

svn commit: r1874795 - /uima/uima-ducc/trunk/src/main/scripts/ducc_watcher

Author: degenaro
Date: Wed Mar  4 13:58:06 2020
New Revision: 1874795

URL: http://svn.apache.org/viewvc?rev=1874795&view=rev
Log:
UIMA-6197 ducc_watcher should optionally allow SSL certificate validation bypass

Modified:
    uima/uima-ducc/trunk/src/main/scripts/ducc_watcher

Modified: uima/uima-ducc/trunk/src/main/scripts/ducc_watcher
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/scripts/ducc_watcher?rev=1874795&r1=1874794&r2=1874795&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/scripts/ducc_watcher (original)
+++ uima/uima-ducc/trunk/src/main/scripts/ducc_watcher Wed Mar  4 13:58:06 2020
@@ -35,6 +35,7 @@ import logging.handlers
 import os
 import smtplib
 import socket
+import ssl
 import string
 import sys
 import time
@@ -79,6 +80,8 @@ state_file = None
 flag_agents = False
 flag_verbose = False
 
+flag_ssl_bypass = False
+
 mail_host = 'localhost'
 email_list = None
 
@@ -197,6 +200,12 @@ def validate_verbose(options):
     if(options.flag_verbose):
         flag_verbose = True
 
+# bypass ssl certification verfication
+def validate_ssl_bypass(options):
+    global flag_ssl_bypass
+    if(options.flag_ssl_bypass):
+        flag_ssl_bypass = True
+
 # ignore job driver allocation
 # unless --job-driver-allocation is specified
 def validate_job_driver_allocation(options):
@@ -304,6 +313,8 @@ def parse_cmdline():
                                help='mail host (default='+mail_host+')')                           
     parser.add_option('-p','--path', action='store', dest='path', default=None,
                                help='path to directory where log and state information are written, default is /tmp'+'/'+get_user())
+    parser.add_option('-s','--ssl-bypass', action='store_true', dest='flag_ssl_bypass', default=False,
+                               help='bypass SSL certificate verification (not recommended)')
     parser.add_option('-t','--target', action='store', dest='target', default=None,
                                help='[REQUIRED] <host> with default port of '+port+' or <host>:<port> or http://<host>:<port> or https://<host>:<port>')
     parser.add_option('-v','--verbose', action='store_true', dest='flag_verbose', default=False, 
@@ -330,6 +341,8 @@ def parse_cmdline():
     validate_agents(options)
     # -v
     validate_verbose(options)
+    # -s
+    validate_ssl_bypass(options)
     # -j
     validate_job_driver_allocation(options)
     
@@ -457,6 +470,16 @@ def elapsedMillis(dts):
     debug(text)
     return diff
 
+def open_url(url):
+    global url_timeout
+    global flag_ssl_bypass
+    if(flag_ssl_bypass and url.startswith('https')):
+		context = ssl._create_unverified_context()
+		response = urllib2.urlopen(url, timeout=url_timeout, context=context)
+    else:
+		response = urllib2.urlopen(url, timeout=url_timeout)
+    return response
+
 # fetch daemons state
 # col[0] = Status
 # col[1] = Daemon Name
@@ -469,14 +492,15 @@ def fetch_state_daemons():
     global ducc_url_servlet_system_daemons_data
     global webserver
     global webserver_lifetime_millis
-    global url_timeout
+    
     state_dict_current = {}
     daemons = {}
     try:
         opener = urllib2.build_opener()
+        urllib2.install_opener(opener)
         if(flag_agents):
             opener.addheaders.append(('Cookie', 'DUCCagents=show'))
-        response = opener.open(ducc_url_servlet_system_daemons_data, timeout=url_timeout)
+        response = open_url(ducc_url_servlet_system_daemons_data)
         data = response.read()
         jdata = json.loads(data)['aaData']
         for row in jdata:
@@ -529,8 +553,9 @@ def fetch_state_job_driver_allocation():
         if(job_driver_allocation != None):
             if(rm_up()):
                 opener = urllib2.build_opener()
+                urllib2.install_opener(opener)
                 debug(ducc_url_servlet_reservations_data)
-                response = opener.open(ducc_url_servlet_reservations_data, timeout=url_timeout)
+                response = open_url(ducc_url_servlet_reservations_data)
                 data = response.read()
                 debug(data)
                 json_data = json.loads(data)