Skip to content

GPC common types that can be used on any Scala services or libraries

License

Notifications You must be signed in to change notification settings

permutive-engineering/common-types-gcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

common-types-gcp

GPC common types that can be used on any Scala services or libraries.

The list of common types are:


Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp" % "1.1.0"

Usage

Every type includes implicit instances for cats' Eq, Show, Order, Hash.

In addition, types like ProjectId also contain smart constructors:

Obtaining the current ProjectId from Google's metadata service:

import cats.Eval

val projectId: Eval[ProjectId] = ProjectId.unsafeFromGCP()

πŸ‘†πŸΌ This method will only return a valid project ID if run inside a workload.

Creating a random value:

val projectId: ProjectId = ProjectId.random()

πŸ‘†πŸΌ It will raise a warning if used outside Test or IntegrationTest configurations

Creating a value from a string (returning Either):

val projectId: Either[String, ProjectId]=
  ProjectId.fromString("test-project")

Effectful alternative:

val projectId: IO[ProjectId]=
  ProjectId.fromStringF[IO]("test-project")

Creating a value from a literal string:

val projectId: ProjectId = ProjectId("test-project")

πŸ‘†πŸΌ It will fail at compile time if not a project ID or not using a literal.

Integrations

common-types-gcp-circe

Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp-circe" % "1.1.0"

Usage

Just add the following import:

import com.permutive.common.types.gcp.circe._

It will bring Encoder, Decoder, KeyEncoder & KeyDecoder instances for the available types into scope.

common-types-gcp-http4s

Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp-http4s" % "1.1.0"

Usage

Just add the following import:

import com.permutive.common.types.gcp.http4s._

It will bring SegmentEncoder, QueryParamEncoder & QueryParamDecoder instances for the available types into scope.

common-types-gcp-pureconfig

Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp-pureconfig" % "1.1.0"

Usage

Just add the following import:

import com.permutive.common.types.gcp.pureconfig._

It will bring ConfigReader & ConfigWriter instances for the available types into scope.

For the case of ProjectId you can use the special value gcp on your application.conf when running inside a workload and it will retrieve the current ProjectId from Google's metadata service.

common-types-gcp-tapir

Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp-tapir" % "1.1.0"

Usage

Just add the following import:

import com.permutive.common.types.gcp.tapir._

It will bring Codec/Schema instances for the available types, as well as adding a new extension method (example) to common types' companion objects that can be used to add an example value to tapir endpoints:

import com.permutive.common.types.gcp.ProjectId
import com.permutive.common.types.gcp.tapir._

import sttp.tapir._

endpoint.get
  .in("projects")
  .in(path[ProjectId]("project_id").example(ProjectId.example))
// res12: Endpoint[Unit, typelevel.LowPriorityTupleConcat0.<refinement>.this.type.Out, Unit, Unit, Any] = Endpoint(
//   securityInput = Empty(
//     codec = sttp.tapir.Codec$$anon$4@7cc62914,
//     info = Info(
//       description = None,
//       examples = List(),
//       deprecated = false,
//       attributes = AttributeMap(storage = Map())
//     )
//   ),
//   input = Pair(
//     left = Pair(
//       left = Pair(
//         left = Empty(
//           codec = sttp.tapir.Codec$$anon$4@7cc62914,
//           info = Info(
//             description = None,
//             examples = List(),
//             deprecated = false,
//             attributes = AttributeMap(storage = Map())
//           )
//         ),
//         right = FixedMethod(
//           m = Method(method = "GET"),
//           codec = sttp.tapir.Codec$$anon$4@24e399bf,
//           info = Info(
//             description = None,
//             examples = List(),
//             deprecated = false,
//             attributes = AttributeMap(storage = Map())
//           )
//         ),
//         combine = sttp.tapir.internal.package$$$Lambda$14987/0x00007f4b5697e6e0@6836a99b,
//         split = sttp.tapir.internal.package$$$Lambda$14988/0x00007f4b5697ec88@45bf623a
//       ),
//       right = FixedPath(
//         s = "projects",
//         codec = sttp.tapir.Codec$$anon$4@4a282bc6,
//         info = Info(
//           description = None,
//           examples = List(),
//           deprecated = false,
//           attributes = AttributeMap(storage = Map())
//         )
//       ),
//       combine = sttp.tapir.internal.package$$$Lambda$14989/0x00007f4b5697f7c8@72be7d5d,
// ...

common-types-gcp-scalacheck

Installation

Add the following dependency to your project:

"com.permutive" %% "common-types-gcp-scalacheck" % "1.1.0"

Usage

Just add the following import:

import com.permutive.common.types.gcp.scalacheck._

It will bring Arbitrary instances for the available types into scope.

Contributors to this project

alejandrohdezma
alejandrohdezma