Skip to content

Commit

Permalink
Merge pull request #45 from innFactory/feature/smithy4s-0-16-4
Browse files Browse the repository at this point in the history
add fallback for serviceAuthHints
  • Loading branch information
patsta32 authored Oct 18, 2022
2 parents f698065 + 5bb06db commit 9ae6c27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import play.api.mvc.{
Result,
Results
}
import smithy4s.{ ByteArray, Endpoint, Interpreter }
import smithy4s.{ ByteArray, Endpoint, Interpreter, Service }
import smithy4s.http.{ CaseInsensitive, CodecAPI, HttpEndpoint, Metadata, PathParams }
import smithy4s.schema.Schema
import cats.implicits._
Expand All @@ -21,19 +21,21 @@ import smithy.api.{ Auth, HttpBearerAuth }

import scala.concurrent.{ ExecutionContext, Future }

class SmithyPlayEndpoint[F[_] <: ContextRoute[_], Op[
class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[
_,
_,
_,
_,
_
], I, E, O, SI, SO](
service: Service[Alg, Op],
impl: Interpreter[Op, F],
endpoint: Endpoint[Op, I, E, O, SI, SO],
codecs: CodecAPI
)(implicit cc: ControllerComponents, ec: ExecutionContext)
extends AbstractController(cc) {

private val serviceHints = service.hints
private val httpEndpoint: Option[HttpEndpoint[I]] = HttpEndpoint.cast(endpoint)

private val inputSchema: Schema[I] = endpoint.input
Expand Down Expand Up @@ -77,8 +79,9 @@ class SmithyPlayEndpoint[F[_] <: ContextRoute[_], Op[
.getOrElse(Action(NotFound("404")))

private def validateAuthHints(metadata: Metadata) = {
val serviceAuthHints = serviceHints.get(HttpBearerAuth.tagInstance).map(_ => Auth(Set(HttpBearerAuth.id.show)))
for {
authSet <- endpoint.hints.get(Auth.tag)
authSet <- endpoint.hints.get(Auth.tag) orElse serviceAuthHints
_ <- authSet.value.find(_.value == HttpBearerAuth.id.show)
} yield metadata.headers.contains(CaseInsensitive("Authorization"))
}.getOrElse(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SmithyPlayRouter[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _], F[
zippedEndpoints <- endpoints.map(ep => HttpEndpoint.cast(ep).map((ep, _))).sequence
endpointAndHttpEndpoint <- zippedEndpoints.find(ep => checkIfRequestHeaderMatchesEndpoint(v1, ep._2))
} yield new SmithyPlayEndpoint(
service,
interpreter,
endpointAndHttpEndpoint._1,
smithy4s.http.json.codecs(smithy4s.api.SimpleRestJson.protocol.hintMask ++ HintMask(InputOutput))
Expand Down
2 changes: 0 additions & 2 deletions smithy4playTest/testSpecs/TestController.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ structure TestResponseBody {
}


@auth([httpBearerAuth])
@http(method: "GET", uri: "/auth", code: 200)
operation TestAuth {

}


0 comments on commit 9ae6c27

Please sign in to comment.