Skip to content

Commit

Permalink
pretty code that doesnt seem to do anything useful
Browse files Browse the repository at this point in the history
  • Loading branch information
mcovarr committed Jun 15, 2017
1 parent bf3202d commit e46a945
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import cromwell.filesystems.gcs.auth.GoogleAuthMode

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._
import scala.language.postfixOps
import scala.util.Try

object GcsPathBuilder {
Expand All @@ -37,8 +38,36 @@ object GcsPathBuilder {
checkNotNull(uri.getHost, s"%s does not have a host", uri)
}

def isValidGcsUrl(str: String): Boolean = {
Try(checkValid(getUri(str))).isSuccess
sealed trait GcsPathValidation
case object ValidFullGcsPath extends GcsPathValidation
case object PossiblyValidRelativeGcsPath extends GcsPathValidation
sealed trait InvalidGcsPath extends GcsPathValidation {
def pathString: String
def errorMessage: String
}
final case class InvalidFullGcsPath(pathString: String) extends InvalidGcsPath {
override def errorMessage = {
val prefix = List(
s"The bucket name in GCS path '$pathString' does not parse as a URI host.",
"This is a requirement for Cromwell's GCS filesystem support."
)
val underscoreWarning = if (pathString.contains("_")) "This bucket name contains underscores which are not valid characters in a URI host." else ""
(prefix :+ underscoreWarning).mkString("\n")
}
}
final case class UnparseableGcsPath(pathString: String, throwable: Throwable) extends InvalidGcsPath {
override def errorMessage: String =
List(s"The specified GCS path '$pathString' does not parse as a URI.", throwable.getMessage).mkString("\n")
}

def validateGcsPath(string: String): GcsPathValidation = {
Try {
val uri = getUri(string)
if (uri.getScheme == null) PossiblyValidRelativeGcsPath
else if (uri.getScheme == "gs") {
if (uri.getHost == null) InvalidFullGcsPath(string) else ValidFullGcsPath
} else InvalidFullGcsPath(string)
} recover { case t => UnparseableGcsPath(string, t) } get
}

def isGcsPath(nioPath: NioPath): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package cromwell.backend.impl.jes

import cromwell.backend.standard.{StandardExpressionFunctions, StandardExpressionFunctionsParams}
import cromwell.filesystems.gcs.GcsPathBuilder
import cromwell.filesystems.gcs.GcsPathBuilder.{InvalidGcsPath, PossiblyValidRelativeGcsPath, ValidFullGcsPath}

class JesExpressionFunctions(standardParams: StandardExpressionFunctionsParams)
extends StandardExpressionFunctions(standardParams) {

override def preMapping(str: String) =
if (!GcsPathBuilder.isValidGcsUrl(str)) {
callContext.root.resolve(str.stripPrefix("/")).pathAsString
} else {
str
override def preMapping(str: String) = {
GcsPathBuilder.validateGcsPath(str) match {
case ValidFullGcsPath => str
case PossiblyValidRelativeGcsPath => callContext.root.resolve(str.stripPrefix("/")).pathAsString
case invalid: InvalidGcsPath => throw new IllegalArgumentException(invalid.errorMessage)
}
}
}

0 comments on commit e46a945

Please sign in to comment.