Skip to content

Commit

Permalink
Merge pull request #1089 from disneystreaming/series-017-into-018-again
Browse files Browse the repository at this point in the history
Merge series/0.17 into series/0.18 again
  • Loading branch information
Baccata authored Jul 18, 2023
2 parents c1f0883 + 7eda66f commit bb56365
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object AwsCredentialsFile {
case head :: next =>
val parts = head.split("=")
val key = parts(0).trim().toLowerCase
val value = parts(1).trim().toLowerCase()
val value = parts(1).trim()
val updated = data + (key -> value)
inProfile(next, currentProfile, updated)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ object AwsCredentialsFileTest extends FunSuite {
}
}

test("be case sensitive") {
expectRight(
AwsCredentialsFile.processFileLines(
asLines(
"""|[default]
|aws_secret_access_key = DeF_SeC
|aws_access_key_id = dEf_KEy
|aws_session_token = dEF_TokEn""".stripMargin
)
)
) { res =>
expect.same(
Some(AwsCredentials.Default("dEf_KEy", "DeF_SeC", Some("dEF_TokEn"))),
res.default
)
}
}

test("parse comments") {
expectRight(
AwsCredentialsFile.processFileLines(
Expand Down
18 changes: 11 additions & 7 deletions modules/docs/markdown/06-guides/dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Then, there's the **runtime** part. Let's say you're building an HTTP client - i
```scala
SimpleRestJson(WeatherService)
.client(??? : org.http4s.client.Client[IO])
.use
.make
```

or more generically:
Expand Down Expand Up @@ -256,7 +256,7 @@ val service = dsi.getService(ShapeId("weather", "WeatherService")).get
val client =
SimpleRestJsonBuilder(service.service)
.client(Client.fromHttpApp(routes))
.use
.make
.toTry
.get
```
Expand All @@ -271,7 +271,7 @@ run(
service = service.service,
operationName = "GetWeather",
input = Document.obj("city" -> Document.fromString("London")),
alg = SimpleRestJsonBuilder(service.service).client(Client.fromHttpApp(routes)).use.toTry.get,
alg = client,
).unsafeRunSync().show
```

Expand All @@ -280,21 +280,25 @@ Enjoy the view! As an added bonus, because we happen to have this service at bui
```scala mdoc
import weather._

val clientInterpreter =
SimpleRestJsonBuilder(WeatherService).client(Client.fromHttpApp(routes)).use.toTry.get
val clientStatic =
SimpleRestJsonBuilder(WeatherService)
.client(Client.fromHttpApp(routes))
.make
.toTry
.get

run(
service = WeatherService,
operationName = "GetWeather",
input = Document.obj("city" -> Document.fromString("London")),
alg = clientInterpreter,
alg = clientStatic,
).unsafeRunSync().show
```

Again, this is equivalent to the following call in the static approach:

```scala mdoc
clientInterpreter.getWeather(city = "London").unsafeRunSync()
clientStatic.getWeather(city = "London").unsafeRunSync()
```

[^1]: That is, assuming they're written correctly to make no assumptions about the usecase.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
package smithy4s
package http4s

import cats.Monoid
import org.http4s.client.Client
import cats.kernel.Monoid

// format: off
trait ClientEndpointMiddleware[F[_]] {
trait ClientEndpointMiddleware[F[_]] {
self =>
def prepare[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
endpoint: Endpoint[service.Operation, _, _, _, _, _]
): Client[F] => Client[F]

def andThen(other: ClientEndpointMiddleware[F]): ClientEndpointMiddleware[F] =
def andThen(other: ClientEndpointMiddleware[F]): ClientEndpointMiddleware[F] =
new ClientEndpointMiddleware[F] {
def prepare[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
endpoint: Endpoint[service.Operation, _, _, _, _, _]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import cats.Monoid
import cats.MonadThrow
import cats.data.Kleisli
import org.http4s.Response
import cats.implicits._
import org.http4s.HttpApp
import cats.implicits._

// format: off
trait ServerEndpointMiddleware[F[_]] {
self =>
self =>
def prepare[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
endpoint: Endpoint[service.Operation, _, _, _, _, _]
): HttpApp[F] => HttpApp[F]

def andThen(other: ServerEndpointMiddleware[F]): ServerEndpointMiddleware[F] =
def andThen(other: ServerEndpointMiddleware[F]): ServerEndpointMiddleware[F] =
new ServerEndpointMiddleware[F] {
def prepare[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
endpoint: Endpoint[service.Operation, _, _, _, _, _]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ abstract class SimpleProtocolBuilder[P](
new ClientBuilder[Alg, F](this.client, this.service, this.uri, mid)

def resource: Resource[F, service.Impl[F]] =
use.leftWiden[Throwable].liftTo[Resource[F, *]]
make.leftWiden[Throwable].liftTo[Resource[F, *]]

def use: Either[UnsupportedProtocolError, service.Impl[F]] = {
def make: Either[UnsupportedProtocolError, service.Impl[F]] = {
checkProtocol(service, protocolTag)
// Making sure the router is evaluated lazily, so that all the compilation inside it
// doesn't happen in case of a missing protocol
Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class SimpleProtocolBuilder[P](
/**
* Applies the error transformation to the errors that are not in the smithy spec (has no effect on errors from spec).
* Transformed errors raised in endpoint implementation will be observable from [[middleware]].
* Errors raised in the [[middleware]] will be transformed too.
* Errors raised in the [[middleware]] will be transformed too.
*
* The following two are equivalent:
* {{{
Expand All @@ -149,7 +149,7 @@ abstract class SimpleProtocolBuilder[P](
/**
* Applies the error transformation to the errors that are not in the smithy spec (has no effect on errors from spec).
* Transformed errors raised in endpoint implementation will be observable from [[middleware]].
* Errors raised in the [[middleware]] will be transformed too.
* Errors raised in the [[middleware]] will be transformed too.
*
* The following two are equivalent:
* {{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DynamicHttpProxy(client: Client[IO]) {
.flatMap { dsi =>
SimpleRestJsonBuilder(dsi.service)
.client[IO](client)
.use
.make
.liftTo[IO]
.map { dynamicClient =>
JsonIOProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ProtocolBuilderSpec extends FunSuite {
) {
val result = SimpleRestJsonBuilder(WeatherGen)
.client(fakeClient)
.use
.make

assert(result.isLeft)
}
Expand All @@ -42,7 +42,7 @@ object ProtocolBuilderSpec extends FunSuite {
) {
val result = SimpleRestJsonBuilder(PizzaAdminServiceGen)
.client(fakeClient)
.use
.make

assert(result.isRight)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object RecursiveInputSpec extends FunSuite {
val result =
SimpleRestJsonBuilder(smithy4s.example.RecursiveInputService)
.client(Client.fromHttpApp(HttpApp.notFound[IO]))
.use
.make

expect(result.isRight)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ object ServerEndpointMiddlewareSpec extends SimpleIOSuite {
.middleware(
new TestClientMiddleware(shouldFail = shouldFailInMiddleware)
)
.use
.make
.toOption
.get
}
Expand Down

0 comments on commit bb56365

Please sign in to comment.