This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 7bb04c5  Optionally fetch code when getting an action (#2908)
7bb04c5 is described below

commit 7bb04c554d5612ce5c7435e375bcdfe3262de039
Author: James Dubee <jwdu...@us.ibm.com>
AuthorDate: Sat Dec 9 17:40:08 2017 -0500

    Optionally fetch code when getting an action (#2908)
---
 .../src/main/scala/whisk/core/entity/Exec.scala    | 27 +---------------------
 .../src/main/resources/apiv1swagger.json           |  7 ++++++
 .../main/scala/whisk/core/controller/Actions.scala | 22 ++++++++++++++----
 .../core/controller/test/ActionsApiTests.scala     | 23 ++++++++++++++++++
 4 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/common/scala/src/main/scala/whisk/core/entity/Exec.scala 
b/common/scala/src/main/scala/whisk/core/entity/Exec.scala
index 3ea1ec5..268fdbe 100644
--- a/common/scala/src/main/scala/whisk/core/entity/Exec.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/Exec.scala
@@ -384,13 +384,7 @@ protected[core] object ExecMetaDataBase extends 
ArgNormalizer[ExecMetaDataBase]
               throw new DeserializationException(
                 s"'image' must be a string defined in 'exec' for 
'${Exec.BLACKBOX}' actions")
           }
-          val code: Option[String] = obj.fields.get("code") match {
-            case Some(JsString(i)) => if (i.trim.nonEmpty) Some(i) else None
-            case Some(_) =>
-              throw new DeserializationException(
-                s"if defined, 'code' must a string defined in 'exec' for 
'${Exec.BLACKBOX}' actions")
-            case None => None
-          }
+
           val native = execManifests.blackboxImages.contains(image)
           BlackBoxExecMetaData(native)
 
@@ -403,28 +397,9 @@ protected[core] object ExecMetaDataBase extends 
ArgNormalizer[ExecMetaDataBase]
 
           manifest.attached
             .map { a =>
-              val jar: Attachment[String] = {
-                // java actions once stored the attachment in "jar" instead of 
"code"
-                obj.fields.get("code").orElse(obj.fields.get("jar"))
-              } map {
-                attFmt[String].read(_)
-              } getOrElse {
-                throw new DeserializationException(
-                  s"'code' must be a valid base64 string in 'exec' for '$kind' 
actions")
-              }
-              val main = optMainField.orElse {
-                if (manifest.requireMain.exists(identity)) {
-                  throw new DeserializationException(s"'main' must be a string 
defined in 'exec' for '$kind' actions")
-                } else None
-              }
               CodeExecMetaDataAsAttachment(manifest)
             }
             .getOrElse {
-              val code: String = obj.fields.get("code") match {
-                case Some(JsString(c)) => c
-                case _ =>
-                  throw new DeserializationException(s"'code' must be a string 
defined in 'exec' for '$kind' actions")
-              }
               CodeExecMetaDataAsString(manifest)
             }
       }
diff --git a/core/controller/src/main/resources/apiv1swagger.json 
b/core/controller/src/main/resources/apiv1swagger.json
index 2d32b7a..86e9460 100644
--- a/core/controller/src/main/resources/apiv1swagger.json
+++ b/core/controller/src/main/resources/apiv1swagger.json
@@ -203,6 +203,13 @@
                         "description": "Name of action to fetch",
                         "required": true,
                         "type": "string"
+                    },
+                    {
+                        "name": "code",
+                        "in": "query",
+                        "description": "Include action code in the result",
+                        "required": false,
+                        "type": "boolean"
                     }
                 ],
                 "produces": [
diff --git a/core/controller/src/main/scala/whisk/core/controller/Actions.scala 
b/core/controller/src/main/scala/whisk/core/controller/Actions.scala
index fcdea99..97489bf 100644
--- a/core/controller/src/main/scala/whisk/core/controller/Actions.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/Actions.scala
@@ -294,10 +294,24 @@ trait WhiskActionsApi extends WhiskCollectionAPI with 
PostActionActivation with
    */
   override def fetch(user: Identity, entityName: FullyQualifiedEntityName, 
env: Option[Parameters])(
     implicit transid: TransactionId) = {
-    getEntity(WhiskAction, entityStore, entityName.toDocId, Some { action: 
WhiskAction =>
-      val mergedAction = env map { action inherit _ } getOrElse action
-      complete(OK, mergedAction)
-    })
+    parameter('code ? true) { code =>
+      code match {
+        case true =>
+          getEntity(WhiskAction, entityStore, entityName.toDocId, Some { 
action: WhiskAction =>
+            val mergedAction = env map {
+              action inherit _
+            } getOrElse action
+            complete(OK, mergedAction)
+          })
+        case false =>
+          getEntity(WhiskActionMetaData, entityStore, entityName.toDocId, Some 
{ action: WhiskActionMetaData =>
+            val mergedAction = env map {
+              action inherit _
+            } getOrElse action
+            complete(OK, mergedAction)
+          })
+      }
+    }
   }
 
   /**
diff --git 
a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala 
b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
index c841545..3696063 100644
--- a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala
@@ -159,6 +159,29 @@ class ActionsApiTests extends ControllerTestCommon with 
WhiskActionsApi {
     }
   }
 
+  it should "get action using code query parameter" in {
+    implicit val tid = transid()
+    val action = WhiskAction(namespace, aname(), jsDefault("??"), 
Parameters("x", "b"))
+
+    put(entityStore, action)
+
+    Get(s"$collectionPath/${action.name}?code=false") ~> 
Route.seal(routes(creds)) ~> check {
+      status should be(OK)
+      val response = responseAs[JsObject]
+      response.fields("exec").asJsObject.fields should not(contain key "code")
+      responseAs[WhiskActionMetaData] shouldBe a[WhiskActionMetaData]
+    }
+
+    Seq(s"$collectionPath/${action.name}", 
s"$collectionPath/${action.name}?code=true").foreach { path =>
+      Get(path) ~> Route.seal(routes(creds)) ~> check {
+        status should be(OK)
+        val response = responseAs[JsObject]
+        response.fields("exec").asJsObject.fields("code") should 
be("??".toJson)
+        responseAs[WhiskAction] shouldBe a[WhiskAction]
+      }
+    }
+  }
+
   it should "report NotFound for get non existent action" in {
     implicit val tid = transid()
     Get(s"$collectionPath/xyz") ~> Route.seal(routes(creds)) ~> check {

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Reply via email to