eugenegujing commented on code in PR #9214:
URL: https://github.com/apache/texera/pull/9214#discussion_r4690426602


##########
amber/src/main/scala/org/apache/texera/web/resource/pythonvirtualenvironment/PveWebsocketResource.scala:
##########
@@ -19,18 +19,42 @@
 
 package org.apache.texera.web.resource.pythonvirtualenvironment
 
+import com.fasterxml.jackson.core.JsonProcessingException
+import com.fasterxml.jackson.core.`type`.TypeReference
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+
 import javax.websocket._
 import javax.websocket.server.ServerEndpoint
 import java.util.concurrent.LinkedBlockingQueue
 import scala.concurrent.Future
 import scala.concurrent.ExecutionContext.Implicits.global
+import scala.jdk.CollectionConverters._
 
 /**
   *  WebSocket endpoint for PVE creation and user package installation that 
streams
   *  pip installation logs  to the frontend in real time. The environment 
setup runs
   *  asynchronously, and output is pushed to the client until completion.
   */
 
+object PveWebsocketResource {

Review Comment:
   Fixed in 83f42183368e66f11a6e1ee05b15c8deeade375c



##########
amber/src/main/scala/org/apache/texera/web/resource/pythonvirtualenvironment/PveWebsocketResource.scala:
##########
@@ -19,18 +19,42 @@
 
 package org.apache.texera.web.resource.pythonvirtualenvironment
 
+import com.fasterxml.jackson.core.JsonProcessingException
+import com.fasterxml.jackson.core.`type`.TypeReference
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+
 import javax.websocket._
 import javax.websocket.server.ServerEndpoint
 import java.util.concurrent.LinkedBlockingQueue
 import scala.concurrent.Future
 import scala.concurrent.ExecutionContext.Implicits.global
+import scala.jdk.CollectionConverters._
 
 /**
   *  WebSocket endpoint for PVE creation and user package installation that 
streams
   *  pip installation logs  to the frontend in real time. The environment 
setup runs
   *  asynchronously, and output is pushed to the client until completion.
   */
 
+object PveWebsocketResource {
+
+  private val packagesType = new TypeReference[java.util.List[String]] {}
+
+  /**
+    * Decodes the `packages` query parameter, a JSON array of pip requirement 
strings, into a
+    * trimmed list without blank entries. Anything that is not a JSON array of 
strings is rejected.
+    */
+  private[pythonvirtualenvironment] def parsePackages(json: String): 
List[String] = {
+    val decoded =
+      try objectMapper.readValue(json, packagesType)
+      catch {
+        case e: JsonProcessingException =>
+          throw new IllegalArgumentException(s"Invalid packages parameter: 
$json", e)
+      }
+    decoded.asScala.toList.filter(_ != null).map(_.trim).filter(_.nonEmpty)

Review Comment:
   Fixed in 83f42183368e66f11a6e1ee05b15c8deeade375c



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to