-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable POST /package/add to accept requests for Universe packages (#545)
- RequestValidators.selectedBody allows any endpoint to accept multiple Content-Types - Replace AddResult with OperationInProgress exception - Implement DefaultUniverseInstaller for the operation queue processor - LocalObjectStorage now writes objects atomically - Update ScalaCheck to latest version supported by ScalaTest (1.12.6)
- Loading branch information
Showing
51 changed files
with
1,183 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...os-finch/src/main/scala/com/mesosphere/cosmos/finch/DispatchingMediaTypedBodyParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.mesosphere.cosmos.finch | ||
|
||
import com.mesosphere.cosmos.http.MediaType | ||
import com.twitter.util.Throw | ||
import com.twitter.util.Try | ||
import io.finch.Error | ||
import io.finch.items | ||
import java.nio.charset.StandardCharsets | ||
|
||
/** Allows a [[com.mesosphere.cosmos.http.MediaType]] to select a request body parsing function. */ | ||
final class DispatchingMediaTypedBodyParser[A] private( | ||
private[this] val parsers: Map[MediaType, Array[Byte] => Try[A]] | ||
) extends (MediaType => Option[Array[Byte] => Try[A]]) { | ||
|
||
def apply(mediaType: MediaType): Option[Array[Byte] => Try[A]] = parsers.get(mediaType) | ||
|
||
def mediaTypes: Set[MediaType] = parsers.keySet | ||
|
||
} | ||
|
||
object DispatchingMediaTypedBodyParser { | ||
|
||
def apply[A]( | ||
parsers: (MediaType, Array[Byte] => Try[A])* | ||
): DispatchingMediaTypedBodyParser[A] = { | ||
new DispatchingMediaTypedBodyParser(parsers.toMap) | ||
} | ||
|
||
def parserFromDecoder[A](implicit | ||
accepts: MediaTypedRequestDecoder[A] | ||
): Array[Byte] => Try[A] = { bodyBytes => | ||
val bodyString = new String(bodyBytes, StandardCharsets.UTF_8) | ||
accepts.decoder(bodyString).rescue { case t => | ||
Throw(Error.NotParsed(items.BodyItem, accepts.classTag, t)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
cosmos-finch/src/main/scala/com/mesosphere/cosmos/finch/IncompatibleContentTypeHeader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mesosphere.cosmos.finch | ||
|
||
import com.mesosphere.cosmos.http.MediaType | ||
import com.twitter.finagle.http.Fields | ||
import com.twitter.finagle.http.Status | ||
import io.circe.JsonObject | ||
import io.circe.syntax._ | ||
|
||
case class IncompatibleContentTypeHeader(available: Set[MediaType], specified: MediaType) | ||
extends RequestError { | ||
val errType: String = "not_valid" | ||
val status: Status = Status.BadRequest | ||
|
||
val getData: Option[JsonObject] = Some(JsonObject.fromMap(Map( | ||
"invalidItem" -> JsonObject.fromMap(Map( | ||
"type" -> "header".asJson, | ||
"name" -> Fields.ContentType.asJson | ||
)).asJson, | ||
"specified" -> specified.show.asJson, | ||
"available" -> available.map(_.show).asJson | ||
))) | ||
|
||
val getHeaders: Map[String, String] = Map.empty | ||
|
||
override def getMessage: String = { | ||
val validChoices = available.map(_.show).mkString(", ") | ||
s"${Fields.ContentType} header was ${specified.show}, but should be one of: $validChoices" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.