AETHER-3616 Changes to work with basic auth

Change-Id: Id39dd7365a5e2cde09e9881216bf2d4ec796968e
diff --git a/VERSION b/VERSION
index 03b4352..d75a59c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.7.19
+0.7.20
diff --git a/edge-monitoring-server/edge_maintenance_agent.py b/edge-monitoring-server/edge_maintenance_agent.py
index 52eee93..082f75f 100755
--- a/edge-monitoring-server/edge_maintenance_agent.py
+++ b/edge-monitoring-server/edge_maintenance_agent.py
@@ -12,15 +12,20 @@
 import os
 import json
 import time
+import base64
+import logging
 import threading
 import urllib.request
 from flask import Flask, Response
 import prometheus_client as prom
 
 # URL of the Edge Monitoring Server where this edge's status can be fetched
-# I.e., put /<edge-name> at the end of the URL
 AETHER_EDGE_STATUS_URL = os.environ.get("AETHER_EDGE_STATUS_URL")
 
+# For basic auth
+AETHER_USERNAME = os.environ.get("AETHER_USERNAME")
+AETHER_PASSWORD = os.environ.get("AETHER_PASSWORD")
+
 # Seconds to sleep at end of loop
 SLEEP_INTERVAL = 60
 
@@ -30,18 +35,21 @@
 def pull_maintenance_events():
     while True:
         # Pull latest status 
-        print ("[INFO] Pulling edge status from %s" % AETHER_EDGE_STATUS_URL)
+        app.logger.info("Pulling edge status from %s" % (AETHER_EDGE_STATUS_URL))
         try:
-            response = urllib.request.urlopen(AETHER_EDGE_STATUS_URL)
+            request = urllib.request.Request(AETHER_EDGE_STATUS_URL)
+            base64string = base64.b64encode(bytes('%s:%s' % (AETHER_USERNAME, AETHER_PASSWORD),'ascii'))
+            request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
+            response = urllib.request.urlopen(request)
             data = json.load(response)
-            # print (" * Got: ", data)
+            app.logger.debug(" Response: %s" % data)
 
             # Export metric to Prometheus
             in_window = data['edge']['maintenance']['in_window']
-            print ("[INFO] In maintenance window: %s" % in_window)
+            app.logger.info("In maintenance window: %s" % in_window)
             maint_window.set(int(in_window))
-        except:
-            print("[WARN] Could not retrieve edge status, will keep trying")
+        except Exception as e:
+            app.logger.warning("Could not retrieve edge status, will keep trying (%s)" % e)
             pass
 
         time.sleep(SLEEP_INTERVAL)
@@ -57,11 +65,12 @@
     return {'message': 'healthy'}
 
 if __name__ == '__main__':
+    app.logger.setLevel(logging.INFO)
     if not (AETHER_EDGE_STATUS_URL):
-        print("[ERROR] AETHER_EDGE_STATUS_URL must be present in the local environment")
+        app.logger.error("AETHER_EDGE_STATUS_URL must be present in the local environment")
         exit(1)
-    print(" * Starting maintenance window polling thread")
-    print(" *   AETHER_EDGE_STATUS_URL: %s" % AETHER_EDGE_STATUS_URL)
+    app.logger.info("Starting maintenance window polling thread")
+    app.logger.info("[AETHER_EDGE_STATUS_URL: %s" % AETHER_EDGE_STATUS_URL)
     t = threading.Thread(target=pull_maintenance_events)
     t.start()
-    app.run(debug=True, host='0.0.0.0', port=8080)
+    app.run(debug=True, host='0.0.0.0', port=8080, use_reloader=False)