Skip to content

Commit

Permalink
Implement Flipt OpenFeature Provider boolean evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Sep 6, 2024
1 parent 59fdea9 commit d8ed74c
Show file tree
Hide file tree
Showing 32 changed files with 1,053 additions and 597 deletions.
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-J-Xmx4G
-J-Xss2M
35 changes: 0 additions & 35 deletions .scalafix-base.conf

This file was deleted.

28 changes: 14 additions & 14 deletions .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ rules = [
NoValInForComprehension
# ProcedureSyntax
RedundantSyntax
# OrganizeImports
# RemoveUnused
OrganizeImports
RemoveUnused
]

# run on compile (not explicitly)
Expand All @@ -20,16 +20,16 @@ triggered.rules = [
]

# clashes with OrganizeImports
# RemoveUnused.imports = false
RemoveUnused.imports = false

# OrganizeImports {
# blankLines = Auto
# groups = [
# "re:javax?\\."
# "re:scala\\."
# "re:^(?!(io.cardell)).*$" # anything except mine
# "*"
# ]
# expandRelative = true
# removeUnused = true
# }
OrganizeImports {
blankLines = Auto
groups = [
"re:javax?\\."
"re:scala\\."
"re:^(?!(io.cardell)).*$" # anything except mine
"*"
]
expandRelative = true
removeUnused = true
}
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
version = 3.7.1
include ".scalafmt-base.conf"

runner.dialect = scala3
178 changes: 104 additions & 74 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.0" // your current series x.y

ThisBuild / organization := "io.cardell"
ThisBuild / organization := "io.cardell"
ThisBuild / organizationName := "Alex Cardell"
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)

ThisBuild / developers := List(
// your GitHub handle and name
tlGitHubDev("alexcardell", "Alex Cardell")
Expand All @@ -15,99 +16,128 @@ ThisBuild / tlSonatypeUseLegacyHost := false

// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")
ThisBuild / tlSiteKeepFiles := false
ThisBuild / tlSiteKeepFiles := false

val Scala213 = "2.13.12"
val Scala33 = "3.3.3"
val Scala33 = "3.3.4-RC1"
ThisBuild / crossScalaVersions := Seq(Scala213, Scala33)
ThisBuild / scalaVersion := Scala213 // the default Scala
ThisBuild / scalaVersion := Scala213 // the default Scala

// hack until integration tests can run in parallel
// ThisBuild / Test / parallelExecution := false
Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)

lazy val projects = Seq(
`flipt-sdk-server`,
`flipt-sdk-server-it`,
`open-feature-sdk`,
`open-feature-provider-flipt`
`open-feature-provider-flipt`,
`open-feature-provider-flipt-it`
)

lazy val commonDependencies = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"org.scalameta" %%% "munit" % "1.0.0-RC1" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M5" % Test
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"org.scalameta" %%% "munit" % "1.0.0-RC1" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M5" % Test
)
)

lazy val root = tlCrossRootProject.aggregate(projects: _*)

lazy val `flipt-sdk-server` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("flipt/sdk-server"))
.settings(commonDependencies)
.settings(
name := "ff4s-flipt-sdk-server",
libraryDependencies ++= Seq(
"org.http4s" %%% "http4s-client" % "0.23.26",
"org.http4s" %%% "http4s-ember-client" % "0.23.26",
"org.http4s" %%% "http4s-circe" % "0.23.26",
"io.circe" %%% "circe-core" % "0.14.7",
"io.circe" %%% "circe-parser" % "0.14.7",
"io.circe" %%% "circe-generic" % "0.14.7"
)
lazy val `flipt-sdk-server` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Full)
.in(file("flipt/sdk-server"))
.settings(commonDependencies)
.settings(
name := "ff4s-flipt-sdk-server",
libraryDependencies ++= Seq(
"org.http4s" %%% "http4s-client" % "0.23.26",
"org.http4s" %%% "http4s-ember-client" % "0.23.26",
"org.http4s" %%% "http4s-circe" % "0.23.26",
"io.circe" %%% "circe-core" % "0.14.7",
"io.circe" %%% "circe-parser" % "0.14.7",
"io.circe" %%% "circe-generic" % "0.14.7"
)
)

lazy val `flipt-sdk-server-it` =
crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("flipt/sdk-server-it"))
.dependsOn(`flipt-sdk-server`)
.settings(commonDependencies)
.settings(
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
lazy val `flipt-sdk-server-it` = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("flipt/sdk-server-it"))
.settings(commonDependencies)
.settings(
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
)
.dependsOn(`flipt-sdk-server`)

lazy val `open-feature-sdk` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("open-feature/sdk"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-sdk",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-generic" % "0.14.7"
)
lazy val `open-feature-sdk` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Pure)
.in(file("open-feature/sdk"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-sdk",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-generic" % "0.14.7"
)
)

lazy val `open-feature-provider-flipt` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("open-feature/provider-flipt"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-provider-flipt"
)
.dependsOn(
`open-feature-sdk`,
`flipt-sdk-server`
)
lazy val `open-feature-provider-flipt` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Pure)
.in(file("open-feature/provider-flipt"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-provider-flipt"
)
.dependsOn(
`open-feature-sdk`,
`flipt-sdk-server`
)

lazy val docs =
project
.in(file("site"))
.enablePlugins(TypelevelSitePlugin)
.settings(
tlSiteHelium := {
import laika.helium.config.IconLink
import laika.helium.config.HeliumIcon
import laika.ast.Path.Root
tlSiteHelium.value.site.topNavigationBar(
homeLink = IconLink.internal(Root / "index.md", HeliumIcon.home)
)
}
lazy val `open-feature-provider-flipt-it` = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("open-feature/provider-flipt-it"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-provider-flipt-it",
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
.dependsOn(`flipt-sdk-server`.jvm)
)
.dependsOn(
`open-feature-provider-flipt`
)

lazy val docs = project
.in(file("site"))
.enablePlugins(TypelevelSitePlugin)
.settings(
tlSiteHelium := {
import laika.helium.config.IconLink
import laika.helium.config.HeliumIcon
import laika.ast.Path.Root
tlSiteHelium.value.site.topNavigationBar(
homeLink = IconLink.internal(Root / "index.md", HeliumIcon.home)
)
}
)
.dependsOn(`flipt-sdk-server`.jvm)

addCommandAlias("fix", "scalafixAll;scalafmtAll;scalafmtSbt")
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import com.dimafeng.testcontainers.ContainerDef
import com.dimafeng.testcontainers.DockerComposeContainer
import com.dimafeng.testcontainers.ExposedService
import com.dimafeng.testcontainers.munit.TestContainerForAll
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
import java.io.File
import munit.CatsEffectSuite
import org.http4s.Uri
import org.http4s.ember.client.EmberClientBuilder
import org.testcontainers.containers.wait.strategy.Wait

import java.io.File
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy

class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {

Expand All @@ -43,10 +43,11 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
)

def api(containers: Containers): Resource[IO, FliptApi[IO]] = {
val flipt = containers
.asInstanceOf[DockerComposeContainer]
.getContainerByServiceName("flipt")
.get
val flipt =
containers
.asInstanceOf[DockerComposeContainer]
.getContainerByServiceName("flipt")
.get

val url = Uri
.fromString(
Expand Down Expand Up @@ -119,6 +120,7 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
}

case class TestVariant(field: String, intField: Int)

object TestVariant {
implicit val decoder: Decoder[TestVariant] = deriveDecoder
}
Expand Down Expand Up @@ -166,4 +168,5 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package io.cardell.ff4s.flipt

import cats.effect.Concurrent
import io.circe.Decoder
import org.http4s.Uri
import org.http4s.client.Client

import io.cardell.ff4s.flipt.auth.AuthMiddleware
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy
import io.cardell.ff4s.flipt.model.AttachmentDecodingError
Expand All @@ -25,14 +29,13 @@ import io.cardell.ff4s.flipt.model.BatchEvaluationResponse
import io.cardell.ff4s.flipt.model.BooleanEvaluationResponse
import io.cardell.ff4s.flipt.model.StructuredVariantEvaluationResponse
import io.cardell.ff4s.flipt.model.VariantEvaluationResponse
import io.circe.Decoder
import org.http4s.Uri
import org.http4s.client.Client

trait FliptApi[F[_]] {

def evaluateBoolean(
request: EvaluationRequest
): F[BooleanEvaluationResponse]

def evaluateVariant(
request: EvaluationRequest
): F[VariantEvaluationResponse]
Expand All @@ -45,16 +48,19 @@ trait FliptApi[F[_]] {
def evaluateStructuredVariant[A: Decoder](
request: EvaluationRequest
): F[Either[AttachmentDecodingError, StructuredVariantEvaluationResponse[A]]]

def evaluateBatch(
request: BatchEvaluationRequest
): F[BatchEvaluationResponse]

}

object FliptApi {

def apply[F[_]: Concurrent](
client: Client[F],
uri: Uri,
strategy: AuthenticationStrategy
): FliptApi[F] =
new FliptApiImpl[F](AuthMiddleware(client, strategy), uri)
): FliptApi[F] = new FliptApiImpl[F](AuthMiddleware(client, strategy), uri)

}
Loading

0 comments on commit d8ed74c

Please sign in to comment.