You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ch...@apache.org on 2019/08/29 12:15:54 UTC
[openwhisk-runtime-nodejs] branch master updated: Export activation
arguments to environment during initialization. (#143)
This is an automated email from the ASF dual-hosted git repository.
chetanm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-nodejs.git
The following commit(s) were added to refs/heads/master by this push:
new b67f3d3 Export activation arguments to environment during initialization. (#143)
b67f3d3 is described below
commit b67f3d3f9d1e1c5b1cd27682f65c1ca341a8dc3b
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Thu Aug 29 08:15:49 2019 -0400
Export activation arguments to environment during initialization. (#143)
Export activation arguments to environment during initialization, before loading the code.
---
core/nodejsActionBase/app.js | 8 ++++----
core/nodejsActionBase/src/service.js | 11 +++++++++++
.../actionContainers/NodeJsActionContainerTests.scala | 15 +++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/core/nodejsActionBase/app.js b/core/nodejsActionBase/app.js
index d825dc3..c50647d 100644
--- a/core/nodejsActionBase/app.js
+++ b/core/nodejsActionBase/app.js
@@ -17,10 +17,10 @@
// __OW_ALLOW_CONCURRENT: see docs/concurrency.md
var config = {
- 'port': 8080,
- 'apiHost': process.env.__OW_API_HOST,
- 'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT,
- 'requestBodyLimit': "48mb"
+ 'port': 8080,
+ 'apiHost': process.env.__OW_API_HOST,
+ 'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT,
+ 'requestBodyLimit': "48mb"
};
var bodyParser = require('body-parser');
diff --git a/core/nodejsActionBase/src/service.js b/core/nodejsActionBase/src/service.js
index 4d994af..e781210 100644
--- a/core/nodejsActionBase/src/service.js
+++ b/core/nodejsActionBase/src/service.js
@@ -160,6 +160,17 @@ function NodeActionService(config) {
};
function doInit(message) {
+ if (message.env && typeof message.env == 'object') {
+ Object.keys(message.env).forEach(k => {
+ let val = message.env[k];
+ if (typeof val !== 'object' || val == null) {
+ process.env[k] = val ? val.toString() : "";
+ } else {
+ process.env[k] = JSON.stringify(val);
+ }
+ });
+ }
+
return initializeActionHandler(message)
.then(handler => {
userCodeRunner = new NodeActionRunner(handler);
diff --git a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
index 63f30fd..f96a94c 100644
--- a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
@@ -87,6 +87,21 @@ abstract class NodeJsActionContainerTests extends BasicActionRunnerTests with Ws
""".stripMargin.trim)
}
+ override val testEnvPartition = {
+ // the environment variables are ready at load time to ensure
+ // variables are already available in the runtime
+ TestConfig("""
+ |const envargs = {
+ | "SOME_VAR": process.env.SOME_VAR,
+ | "ANOTHER_VAR": process.env.ANOTHER_VAR
+ |}
+ |
+ |function main(args) {
+ | return envargs
+ |}
+ """.stripMargin.trim)
+ }
+
override val testInitCannotBeCalledMoreThanOnce = {
TestConfig("""
|function main(args) {