You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/04/25 16:24:44 UTC

[GitHub] [incubator-openwhisk-devtools] mrutkows commented on a change in pull request #253: Fix Knative dedicated function request pre-processing logic

mrutkows commented on a change in pull request #253: Fix Knative dedicated function request pre-processing logic
URL: https://github.com/apache/incubator-openwhisk-devtools/pull/253#discussion_r278630771
 
 

 ##########
 File path: knative-build/runtimes/javascript/platform/knative.js
 ##########
 @@ -78,76 +78,97 @@ function removeInitData(body) {
     }
 }
 
+
 /**
- * Pre-process the incoming
+ * Create request init data from the process environment
+ */
+function createInitDataFromEnvironment(env) {
+    DEBUG.functionStart();
+    try {
+        var initdata = {};
+        initdata.main = (typeof env.__OW_ACTION_MAIN === 'undefined') ? "main" : env.__OW_ACTION_MAIN;
+        // TODO: Throw error if CODE is NOT defined!
+        initdata.code = (typeof env.__OW_ACTION_CODE === 'undefined') ? "" : env.__OW_ACTION_CODE;
+        initdata.binary = (typeof env.__OW_ACTION_BINARY === 'undefined') ? false : env.__OW_ACTION_BINARY.toLowerCase() === "true";
+        // TODO: default to empty?
+        initdata.actionName = (typeof env.__OW_ACTION_NAME === 'undefined') ? "" : env.__OW_ACTION_NAME;
+        initdata.raw = (typeof env.__OW_ACTION_RAW === 'undefined') ? false : env.__OW_ACTION_RAW.toLowerCase() === "true";
+
+        DEBUG.dumpObject(initdata, "initdata");
+        return initdata;
+
+    } catch(e){
+        console.error(e);
+        DEBUG.functionEndError(e.message);
+        throw("Unable to process Initialization data: " + e.message);
+    }
+    DEBUG.functionEnd();
+}
+
+
+/**
+ * Pre-process the init data from the request
  */
 function preProcessInitData(env, initdata, valuedata, activationdata) {
     DEBUG.functionStart();
     try {
         // Set defaults to use INIT data not provided on the request
         // Look first to the process (i.e., Container's) environment variables.
-        var main = (typeof env.__OW_ACTION_MAIN === 'undefined') ? "main" : env.__OW_ACTION_MAIN;
-        // TODO: Throw error if CODE is NOT defined!
-        var code = (typeof env.__OW_ACTION_CODE === 'undefined') ? "" : env.__OW_ACTION_CODE;
-        var binary = (typeof env.__OW_ACTION_BINARY === 'undefined') ? false : env.__OW_ACTION_BINARY.toLowerCase() === "true";
-        // TODO: default to empty?
-        var actionName = (typeof env.__OW_ACTION_NAME === 'undefined') ? "" : env.__OW_ACTION_NAME;
-        var raw = (typeof env.__OW_ACTION_RAW === 'undefined') ? false : env.__OW_ACTION_RAW.toLowerCase() === "true";
+        // var main = (typeof env.__OW_ACTION_MAIN === 'undefined') ? "main" : env.__OW_ACTION_MAIN;
+        // // TODO: Throw error if CODE is NOT defined!
+        // var code = (typeof env.__OW_ACTION_CODE === 'undefined') ? "" : env.__OW_ACTION_CODE;
+        // var binary = (typeof env.__OW_ACTION_BINARY === 'undefined') ? false : env.__OW_ACTION_BINARY.toLowerCase() === "true";
+        // // TODO: default to empty?
+        // var actionName = (typeof env.__OW_ACTION_NAME === 'undefined') ? "" : env.__OW_ACTION_NAME;
+        // var raw = (typeof env.__OW_ACTION_RAW === 'undefined') ? false : env.__OW_ACTION_RAW.toLowerCase() === "true";
+        //
+        // DEBUG.dumpObject(initdata, "initdata");
 
-        DEBUG.dumpObject(actionName, "Action name");
-        DEBUG.dumpObject(main, "Action main");
-        DEBUG.dumpObject(code, "Action code");
-        DEBUG.dumpObject(binary, "Action binary");
-        DEBUG.dumpObject(raw, "Action Raw");
+        // Move the init data to the request body under the "value" key.
+        // This will allow us to reuse the "openwhisk" /init route handler function
+        // valuedata.main = main;
+        // valuedata.code = code;
+        // valuedata.binary = binary;
+        // valuedata.raw = raw;
 
         // Look for init data within the request (i.e., "stem cell" runtime, where code is injected by request)
         if (typeof(initdata) !== "undefined") {
-            if (initdata.name && typeof initdata.name === 'string') {
-                actionName = initdata.name;
-            }
+
             if (initdata.main && typeof initdata.main === 'string') {
-                main = initdata.main;
+                valuedata.main = initdata.main;
             }
             if (initdata.code && typeof initdata.code === 'string') {
-                code = initdata.code;
+                valuedata.code = initdata.code;
             }
             if (initdata.binary) {
                 if (typeof initdata.binary === 'boolean') {
-                    binary = initdata.binary;
+                    valuedata.binary = initdata.binary;
                 } else {
                     throw ("Invalid Init. data; expected boolean for key 'binary'.");
                 }
             }
-            if (initdata.raw ) {
+            if (initdata.raw) {
                 if (typeof initdata.raw === 'boolean') {
-                    raw = initdata.raw;
+                    valuedata.raw = initdata.raw;
                 } else {
                     throw ("Invalid Init. data; expected boolean for key 'raw'.");
                 }
             }
-        }
 
-        // Move the init data to the request body under the "value" key.
-        // This will allow us to reuse the "openwhisk" /init route handler function
-        valuedata.main = main;
-        valuedata.code = code;
-        valuedata.binary = binary;
-        valuedata.raw = raw;
-
-        // Action name is a special case, as we have a key collision on "name" between init. data and request
-        // param. data (as they both appear within "body.value") so we must save it to its final location
-        // as the default Action name as part of the activation data
-        // NOTE: if action name is not present in the action data, we will set it regardless even if an empty string
-        if (typeof(activationdata) !== "undefined" ) {
-            if (typeof(activationdata.action_name) === "undefined" ||
-                (typeof(activationdata.action_name) === "string" && activationdata.action_name.length == 0)){
-                activationdata.action_name = actionName;
+            // Action name is a special case, as we have a key collision on "name" between init. data and request
+            // param. data (as they both appear within "body.value") so we must save it to its final location
+            // as the default Action name as part of the activation data
+            if (initdata.name && typeof initdata.name === 'string') {
+                if (typeof (activationdata) !== "undefined") {
+                    if (typeof (activationdata.action_name) === "undefined" ||
+                        (typeof (activationdata.action_name) === "string" &&
+                            activationdata.action_name.length == 0)) {
 
 Review comment:
   Please preserve this literal comparison change
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services