openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgr...@apache.org
Subject [incubator-openwhisk-runtime-docker] 02/02: Do not allow re-init of the action exec.
Date Thu, 05 Jul 2018 20:31:15 GMT
This is an automated email from the ASF dual-hosted git repository.

dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-docker.git

commit 891896f25c39bc336ef6dda53f80f466ac4ca3c8
Author: Rodric Rabbah <rodric@gmail.com>
AuthorDate: Thu Jul 5 15:19:21 2018 -0400

    Do not allow re-init of the action exec.
    
    Disables re-initialization of the executable unless explicitly permitted
    via an environment variable PROXY_ALLOW_REINIT == "1", which is generally
    useful for local testing and development.
---
 core/actionProxy/actionproxy.py                             | 13 ++++++++++++-
 .../actionContainers/ActionProxyContainerTests.scala        |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/core/actionProxy/actionproxy.py b/core/actionProxy/actionproxy.py
index bbe9902..0bca409 100644
--- a/core/actionProxy/actionproxy.py
+++ b/core/actionProxy/actionproxy.py
@@ -203,9 +203,12 @@ class ActionRunner:
 
 proxy = flask.Flask(__name__)
 proxy.debug = False
+# disable re-initialization of the executable unless explicitly allowed via an environment
+# variable PROXY_ALLOW_REINIT == "1" (this is generally useful for local testing and development)
+proxy.rejectReinit = 'PROXY_ALLOW_REINIT' not in os.environ or os.environ['PROXY_ALLOW_REINIT']
!= "1"
+proxy.initialized = False
 runner = None
 
-
 def setRunner(r):
     global runner
     runner = r
@@ -213,6 +216,13 @@ def setRunner(r):
 
 @proxy.route('/init', methods=['POST'])
 def init():
+    if proxy.rejectReinit is True and proxy.initialized is True:
+        msg = 'Cannot initialize the action more than once.'
+        sys.stderr.write(msg + '\n')
+        response = flask.jsonify({'error': msg})
+        response.status_code = 403
+        return complete(response)
+
     message = flask.request.get_json(force=True, silent=True)
     if message and not isinstance(message, dict):
         flask.abort(404)
@@ -228,6 +238,7 @@ def init():
         status = False
 
     if status is True:
+        proxy.initialized = True
         return ('OK', 200)
     else:
         response = flask.jsonify({'error': 'The action failed to generate or locate a binary.
See logs for details.'})
diff --git a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
index 20a9ee5..52022ee 100644
--- a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
@@ -245,4 +245,5 @@ class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSyst
   testUnicode(stdUnicodeSamples)
   testEnv(stdEnvSamples)
   testLargeInput(stdLargeInputSamples)
+  testInitCannotBeCalledMoreThanOnce(codeNotReturningJson) // any code sample will do
 }


Mime
View raw message