diff options
author | Zach Smith <zach@driver.xyz> | 2017-05-01 17:37:45 -0700 |
---|---|---|
committer | Zach Smith <zach@driver.xyz> | 2017-05-01 17:37:45 -0700 |
commit | 066417ab2ca1cc2a8aab76c182115573ec7f5405 (patch) | |
tree | 8895f2695248167596384957898168735b983900 /src/main/scala/xyz | |
parent | de978cf0a1e44cf906b407ca27089a16537f05c7 (diff) | |
download | driver-core-0.12.3.tar.gz driver-core-0.12.3.tar.bz2 driver-core-0.12.3.zip |
Bump sbt-settings and fix errorsv0.12.3
Diffstat (limited to 'src/main/scala/xyz')
-rw-r--r-- | src/main/scala/xyz/driver/core/app.scala | 56 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/file.scala | 12 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/json.scala | 12 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/rest.scala | 70 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/swagger.scala | 2 |
5 files changed, 83 insertions, 69 deletions
diff --git a/src/main/scala/xyz/driver/core/app.scala b/src/main/scala/xyz/driver/core/app.scala index 9fab320..f7731e3 100644 --- a/src/main/scala/xyz/driver/core/app.scala +++ b/src/main/scala/xyz/driver/core/app.scala @@ -66,33 +66,37 @@ object app { val versionRt = versionRoute(version, gitHash, time.currentTime()) val _ = Future { - http.bindAndHandle(route2HandlerFlow(extractHost { origin => - extractClientIP { - ip => - { ctx => - val trackingId = rest.extractTrackingId(ctx.request) - MDC.put("trackingId", trackingId) - MDC.put("origin", origin) - MDC.put("ip", ip.toOption.map(_.getHostAddress).getOrElse("unknown")) - - def requestLogging: Future[Unit] = Future { - log.info( - s"""Received request {"method":"${ctx.request.method.value}","url": "${ctx.request.uri}"}""") - } + http.bindAndHandle( + route2HandlerFlow(extractHost { origin => + extractClientIP { + ip => + { ctx => + val trackingId = rest.extractTrackingId(ctx.request) + MDC.put("trackingId", trackingId) + MDC.put("origin", origin) + MDC.put("ip", ip.toOption.map(_.getHostAddress).getOrElse("unknown")) + + def requestLogging: Future[Unit] = Future { + log.info( + s"""Received request {"method":"${ctx.request.method.value}","url": "${ctx.request.uri}"}""") + } - val contextWithTrackingId = - ctx.withRequest(ctx.request.addHeader(RawHeader(ContextHeaders.TrackingIdHeader, trackingId))) + val contextWithTrackingId = + ctx.withRequest(ctx.request.addHeader(RawHeader(ContextHeaders.TrackingIdHeader, trackingId))) - handleExceptions(ExceptionHandler(exceptionHandler))({ c => - requestLogging.flatMap { _ => - respondWithHeaders(List(RawHeader(ContextHeaders.TrackingIdHeader, trackingId))) { - modules.map(_.route).foldLeft(versionRt ~ healthRoute ~ swaggerRoutes)(_ ~ _) - }(c) - } - })(contextWithTrackingId) - } - } - }), interface, port)(materializer) + handleExceptions(ExceptionHandler(exceptionHandler))({ c => + requestLogging.flatMap { _ => + respondWithHeaders(List(RawHeader(ContextHeaders.TrackingIdHeader, trackingId))) { + modules.map(_.route).foldLeft(versionRt ~ healthRoute ~ swaggerRoutes)(_ ~ _) + }(c) + } + })(contextWithTrackingId) + } + } + }), + interface, + port + )(materializer) } } @@ -249,7 +253,7 @@ object app { */ class CompositeModule(val name: String, modules: Seq[Module]) extends Module with RouteConcatenation { - def route: Route = modules.map(_.route).reduce(_ ~ _) + def route: Route = RouteConcatenation.concat(modules.map(_.route): _*) def routeTypes = modules.flatMap(_.routeTypes) override def activate() = modules.foreach(_.activate()) diff --git a/src/main/scala/xyz/driver/core/file.scala b/src/main/scala/xyz/driver/core/file.scala index 42dc6b2..dcc4b87 100644 --- a/src/main/scala/xyz/driver/core/file.scala +++ b/src/main/scala/xyz/driver/core/file.scala @@ -94,11 +94,13 @@ object file { result.isTruncated } flatMap { result => result.getObjectSummaries.asScala.toList.map { summary => - FileLink(Name[File](summary.getKey), - Paths.get(path.toString + "/" + summary.getKey), - Revision[File](summary.getETag), - Time(summary.getLastModified.getTime), - summary.getSize) + FileLink( + Name[File](summary.getKey), + Paths.get(path.toString + "/" + summary.getKey), + Revision[File](summary.getETag), + Time(summary.getLastModified.getTime), + summary.getSize + ) } filterNot isInSubFolder(path) } toList }) diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala index 457a087..21bcad5 100644 --- a/src/main/scala/xyz/driver/core/json.scala +++ b/src/main/scala/xyz/driver/core/json.scala @@ -121,11 +121,11 @@ object json { case JsString(value) => Email.parse(value).getOrElse { - deserializationError("Expected '@' symbol in email string as Email, but got " + json) + deserializationError("Expected '@' symbol in email string as Email, but got " + json.toString) } case _ => - deserializationError("Expected string as Email, but got " + json) + deserializationError("Expected string as Email, but got " + json.toString) } } @@ -146,7 +146,7 @@ object json { override def read(json: JsValue): T = json match { case JsString(name) => map.getOrElse(name, throw DeserializationException(s"Value $name is not found in the mapping $map")) - case _ => deserializationError("Expected string as enumeration value, but got " + json) + case _ => deserializationError("Expected string as enumeration value, but got " + json.toString) } } @@ -154,7 +154,7 @@ object json { def write(valueClass: T) = JsNumber(writeValue(valueClass)) def read(json: JsValue): T = json match { case JsNumber(value) => create(value) - case _ => deserializationError(s"Expected number as ${typeOf[T].getClass.getName}, but got " + json) + case _ => deserializationError(s"Expected number as ${typeOf[T].getClass.getName}, but got " + json.toString) } } @@ -166,7 +166,7 @@ object json { def write(value: T): JsValue = { val valueType = typeValue.applyOrElse(value, { v: T => - deserializationError(s"No Value type for this type of ${typeOf[T].getClass.getName}: " + v) + deserializationError(s"No Value type for this type of ${typeOf[T].getClass.getName}: " + v.toString) }) val valueFormat = @@ -193,7 +193,7 @@ object json { deserializationError(s"Unknown ${typeOf[T].getClass.getName} type ${fields(typeField)}") } case _ => - deserializationError(s"Expected Json Object as ${typeOf[T].getClass.getName}, but got " + json) + deserializationError(s"Expected Json Object as ${typeOf[T].getClass.getName}, but got " + json.toString) } } diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala index fbadd35..f1eab45 100644 --- a/src/main/scala/xyz/driver/core/rest.scala +++ b/src/main/scala/xyz/driver/core/rest.scala @@ -68,21 +68,21 @@ package rest { } } - val indices = dirtyIndices(0, Nil) - - indices.headOption.fold(byteString){head => - val builder = ByteString.newBuilder - builder ++= byteString.take(head) - - (indices :+ byteString.length).sliding(2).foreach { - case Seq(start, end) => - builder += ' ' - builder ++= byteString.slice(start, end) - case Seq(byteStringLength) => // Should not match; sliding on at least 2 elements - assert(indices.nonEmpty, s"Indices should have been nonEmpty: $indices") - } - builder.result - } + val indices = dirtyIndices(0, Nil) + + indices.headOption.fold(byteString) { head => + val builder = ByteString.newBuilder + builder ++= byteString.take(head) + + (indices :+ byteString.length).sliding(2).foreach { + case Seq(start, end) => + builder += ' ' + builder ++= byteString.slice(start, end) + case Seq(byteStringLength) => // Should not match; sliding on at least 2 elements + assert(indices.nonEmpty, s"Indices should have been nonEmpty: $indices") + } + builder.result + } } val sanitizeRequestEntity: Directive0 = { @@ -126,8 +126,8 @@ package rest { } } - abstract class AuthProvider[U <: User](val authorization: Authorization, - log: Logger)(implicit execution: ExecutionContext) { + abstract class AuthProvider[U <: User](val authorization: Authorization, log: Logger)( + implicit execution: ExecutionContext) { import akka.http.scaladsl.server._ import Directives._ @@ -155,7 +155,7 @@ package rest { onComplete(authenticatedUser(ctx).run flatMap { userOption => userOption.traverseM[Future, (U, Boolean)] { user => isSessionValid(user)(ctx).flatMap { sessionValid => - if(sessionValid) { + if (sessionValid) { permissions.toList .traverse[Future, Boolean](authorization.userHasPermission(user, _)(ctx)) .map(results => Option(user -> results.forall(identity))) @@ -175,7 +175,8 @@ package rest { } case Success(None) => - log.warn(s"Wasn't able to find authenticated user for the token provided to verify ${permissions.mkString(", ")}") + log.warn( + s"Wasn't able to find authenticated user for the token provided to verify ${permissions.mkString(", ")}") reject(ValidationRejection(s"Wasn't able to find authenticated user for the token provided")) case Failure(t) => @@ -293,7 +294,8 @@ package rest { if (response.status == StatusCodes.NotFound) { Unmarshal(HttpEntity.Empty: ResponseEntity) } else if (response.status.isFailure()) { - throw new Exception(s"Http status is failure ${response.status} for ${requestStub.method} ${requestStub.uri}") + throw new Exception( + s"Http status is failure ${response.status} for ${requestStub.method} ${requestStub.uri}") } else { Unmarshal(response.entity) } @@ -308,11 +310,12 @@ package rest { version: String, override val actorSystem: ActorSystem, override val apiTypes: Seq[Type], - val config: Config) extends SwaggerHttpService with HasActorSystem { + val config: Config) + extends SwaggerHttpService with HasActorSystem { val materializer = ActorMaterializer()(actorSystem) - override val basePath = config.getString("swagger.basePath") + override val basePath = config.getString("swagger.basePath") override val apiDocsPath = config.getString("swagger.docsPath") override val info = Info( @@ -320,16 +323,19 @@ package rest { version, config.getString("swagger.apiInfo.title"), config.getString("swagger.apiInfo.termsOfServiceUrl"), - contact = Some(Contact( - config.getString("swagger.apiInfo.contact.name"), - config.getString("swagger.apiInfo.contact.url"), - config.getString("swagger.apiInfo.contact.email") - )), - license = Some(License( - config.getString("swagger.apiInfo.license"), - config.getString("swagger.apiInfo.licenseUrl") - )), - vendorExtensions = Map.empty[String, AnyRef]) + contact = Some( + Contact( + config.getString("swagger.apiInfo.contact.name"), + config.getString("swagger.apiInfo.contact.url"), + config.getString("swagger.apiInfo.contact.email") + )), + license = Some( + License( + config.getString("swagger.apiInfo.license"), + config.getString("swagger.apiInfo.licenseUrl") + )), + vendorExtensions = Map.empty[String, AnyRef] + ) def swaggerUI = get { pathPrefix("") { diff --git a/src/main/scala/xyz/driver/core/swagger.scala b/src/main/scala/xyz/driver/core/swagger.scala index 3a6faff..36c52e0 100644 --- a/src/main/scala/xyz/driver/core/swagger.scala +++ b/src/main/scala/xyz/driver/core/swagger.scala @@ -46,6 +46,7 @@ object swagger { } } + @SuppressWarnings(Array("org.wartremover.warts.Null")) class CustomSwaggerJsonConverter(mapper: ObjectMapper, customProperties: Map[Class[_], Property], customObjects: Map[Class[_], JsValue]) @@ -78,6 +79,7 @@ object swagger { } orNull } + @SuppressWarnings(Array("org.wartremover.warts.Null")) override def resolve(`type`: Type, context: ModelConverterContext, chain: util.Iterator[ModelConverter]): Model = { val javaType = Json.mapper().constructType(`type`) |