Merge "NOTICKET: Refactor with sessions. Now holds auth on server" into projects
[osm/UI.git] / skyquake / framework / core / api_utils / utils.js
index 163769a..68775f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,7 +95,7 @@ var validateResponse = function(callerName, error, response, body, resolve, reje
 
 var checkAuthorizationHeader = function(req) {
        return new Promise(function(resolve, reject) {
-               if (req.get('Authorization') == null) {
+               if (req.session && req.session.authorization == null) {
                        reject();
                } else {
                        resolve();
@@ -200,7 +200,7 @@ var passThroughConstructor = function(app) {
                                uri: uri,
                                method: 'GET',
                                headers: _.extend({}, CONSTANTS.HTTP_HEADERS.accept[type], {
-                                       'Authorization': req.get('Authorization'),
+                                       'Authorization': req.session && req.session.authorization,
                                        forever: CONSTANTS.FOREVER_ON,
                                        rejectUnauthorized: false,
                                })
@@ -217,6 +217,15 @@ var passThroughConstructor = function(app) {
        });
 }
 
+var getPortForProtocol = function(protocol) {
+  switch (protocol) {
+    case 'http':
+      return 8000;
+    case 'https':
+      return 8443;
+  }
+}
+
 module.exports = {
        /**
         * Ensure confd port is on api_server variable.
@@ -233,5 +242,7 @@ module.exports = {
 
        sendSuccessResponse: sendSuccessResponse,
 
-       passThroughConstructor: passThroughConstructor
+    passThroughConstructor: passThroughConstructor,
+
+    getPortForProtocol: getPortForProtocol
 };