项目作者: filosganga

项目描述 :
AWS V4 authentication for Http4s
高级语言: Scala
项目地址: git://github.com/filosganga/http4s-aws.git
创建时间: 2020-03-07T13:36:13Z
项目社区:https://github.com/filosganga/http4s-aws

开源协议:Apache License 2.0

下载


AWS Signature V4 implementation for http4s

Provides an http4s client middleware that authenticates requests with AWS Auth Signature V4.

Getting started

To get started with sbt, simply add the following line to your build.sbt file.

  1. libraryDependencies += "com.github.fd4s" %% "http4s-aws" % "<version>"

Example of use with S3:

  1. import scala.concurrent.ExecutionContext.{global => ec}
  2. import cats.implicits._
  3. import cats.effect._
  4. import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
  5. import org.http4s.{Service => _, _}
  6. import org.http4s.Method._
  7. import org.http4s.client._
  8. import org.http4s.client.dsl.io._
  9. import org.http4s.client.blaze._
  10. import com.github.fd4s.http4s.aws._
  11. import com.github.fd4s.http4s.aws.model._
  12. implicit val cs: ContextShift[IO] = IO.contextShift(ec)
  13. BlazeClientBuilder[IO](ec)
  14. .resource
  15. .map { client =>
  16. AwsSigner(
  17. CredentialsProvider.fromAwsCredentialProvider[IO](
  18. new DefaultAWSCredentialsProviderChain()
  19. ),
  20. Region.`eu-west-1`,
  21. Service.s3
  22. )(client)
  23. }
  24. .use { client =>
  25. for {
  26. url <- IO.fromEither(Uri.fromString("hhttps://test.s3-eu-west-1.amazonaws.com/test.txt"))
  27. req <- GET(url)
  28. res <- client.expect[String](req)
  29. } yield res
  30. }
  31. .unsafeRunSync()

Happy coding!