openwhisk-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [openwhisk] rabbah commented on a change in pull request #4702: Fixed to check entityType when deserializing entity
Date Tue, 29 Oct 2019 15:54:48 GMT
rabbah commented on a change in pull request #4702: Fixed to check entityType when deserializing
entity
URL: https://github.com/apache/openwhisk/pull/4702#discussion_r340164022
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskEntity.scala
 ##########
 @@ -124,6 +125,16 @@ object WhiskDocumentReader extends DocumentReader {
       case x if x == classOf[WhiskRule]           => WhiskRule.serdes.read(value)
       case _                                      => throw DocumentUnreadable(Messages.corruptedEntity)
     }
+    value.asJsObject.fields.get("entityType") match {
+      case Some(JsString(entityType)) => {
+        if (doc.entityType != entityType) {
+          throw DocumentTypeMismatchException(
+            s"document type ${doc.entityType} did not match expected type ${entityType}.")
+        }
+      }
+      case _ =>
+    }
+    doc
 
 Review comment:
   Warning Scala Nit ahead. You can simplify this further:
   
   ```scala
   
       value.asJsObject.fields.get("entityType").foreach {
         case JsString(entityType) if (doc.entityType != entityType) =>
           throw DocumentTypeMismatchException(s"document type ${doc.entityType} did not match
expected type $entityType.")
   
         case _ =>
       }
   
   ```
   
   The first case match will only apply if the value of `entityType` is a string and it matches
the value in the `doc` type. Otherwise, `_` matches all others.

----------------------------------------------------------------
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

Mime
View raw message