-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 configuration file wasn't detecting changes properly (#244)
When the configuration file was the only change, it wasn't triggering any file changes detection Refs: #238
- Loading branch information
1 parent
9d4e694
commit 17abb1b
Showing
12 changed files
with
325 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
providers/git/src/main/scala/tech/unisonui/providers/git/git/data/Configuration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package tech.unisonui.providers.git.git.data | ||
|
||
import io.circe.generic.auto._ | ||
import io.circe.{Decoder, HCursor} | ||
import tech.unisonui.models.Service | ||
|
||
final case class Configuration(name: Option[String], | ||
openapi: Option[OpenApiSetting], | ||
grpc: Option[GrpcSetting]) | ||
|
||
final case class OpenApiSetting(specifications: List[OpenApi], | ||
useProxy: Boolean) | ||
|
||
final case class GrpcSetting(servers: Map[String, Service.Grpc.Server], | ||
protobufFiles: Map[String, ProtobufSetting]) | ||
|
||
final case class ProtobufSetting(maybeName: Option[String], | ||
servers: Map[String, Service.Grpc.Server]) | ||
object Configuration { | ||
implicit val decoder: Decoder[Configuration] = (cursor: HCursor) => | ||
for { | ||
name <- cursor.get[Option[String]]("name") | ||
openapi <- cursor.get[Option[OpenApiSetting]]("openapi") | ||
specifications <- cursor.get[Option[List[OpenApi]]]("specifications") | ||
grpc <- cursor.get[Option[GrpcSetting]]("grpc") | ||
useProxy <- cursor.getOrElse[Boolean]("useProxy")(false) | ||
openapiSettings = openapi | ||
.orElse(specifications.map { | ||
OpenApiSetting(_, useProxy) | ||
}) | ||
} yield Configuration(name, openapiSettings, grpc) | ||
} | ||
|
||
object OpenApiSetting { | ||
implicit val decoder: Decoder[OpenApiSetting] = (cursor: HCursor) => | ||
for { | ||
specifications <- cursor.get[List[OpenApi]]("specifications") | ||
useProxy <- cursor.getOrElse[Boolean]("useProxy")(false) | ||
} yield OpenApiSetting(specifications, useProxy) | ||
} | ||
|
||
object GrpcSetting { | ||
import ProtobufSetting.serverDecoder | ||
implicit val decoder: Decoder[GrpcSetting] = (cursor: HCursor) => | ||
for { | ||
servers <- cursor | ||
.getOrElse[List[(String, Service.Grpc.Server)]]("servers")(Nil) | ||
protobufFiles <- cursor.getOrElse[Map[String, ProtobufSetting]]( | ||
"protobufs")(Map.empty) | ||
} yield GrpcSetting(servers.toMap, protobufFiles) | ||
} | ||
|
||
object ProtobufSetting { | ||
implicit val decoder: Decoder[ProtobufSetting] = (cursor: HCursor) => | ||
for { | ||
maybeName <- cursor.get[Option[String]]("name") | ||
servers <- cursor | ||
.getOrElse[List[(String, Service.Grpc.Server)]]("servers")(Nil) | ||
} yield ProtobufSetting(maybeName, servers.toMap) | ||
|
||
implicit val serverDecoder: Decoder[(String, Service.Grpc.Server)] = | ||
(cursor: HCursor) => | ||
for { | ||
address <- cursor.get[String]("address") | ||
port <- cursor.get[Int]("port") | ||
useTls <- cursor.getOrElse[Boolean]("useTls")(false) | ||
name <- cursor.getOrElse[String]("name")(s"$address:$port") | ||
} yield name -> Service.Grpc.Server(address, port, useTls) | ||
} |
49 changes: 49 additions & 0 deletions
49
providers/git/src/main/scala/tech/unisonui/providers/git/git/data/Specification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tech.unisonui.providers.git.git.data | ||
import cats.syntax.functor._ | ||
import cats.syntax.option._ | ||
import io.circe.{Decoder, HCursor} | ||
import tech.unisonui.models.Service | ||
|
||
sealed trait Specification extends Product with Serializable { | ||
val serviceName: Option[String] | ||
val path: String | ||
} | ||
|
||
sealed trait OpenApi extends Product with Serializable with Specification { | ||
val useProxy: Option[Boolean] | ||
} | ||
|
||
final case class UnnamedOpenApi(path: String, useProxy: Option[Boolean] = None) | ||
extends OpenApi { | ||
val serviceName: Option[String] = None | ||
} | ||
|
||
final case class NamedOpenApi(name: String, | ||
path: String, | ||
useProxy: Option[Boolean]) | ||
extends OpenApi { val serviceName: Option[String] = name.some } | ||
|
||
final case class Grpc(serviceName: Option[String], | ||
path: String, | ||
servers: Map[String, Service.Grpc.Server]) | ||
extends Specification | ||
|
||
object OpenApi { | ||
implicit val decoder: Decoder[OpenApi] = | ||
List[Decoder[OpenApi]](Decoder[UnnamedOpenApi].widen, | ||
Decoder[NamedOpenApi].widen).reduceLeft(_ or _) | ||
} | ||
|
||
object UnnamedOpenApi { | ||
implicit val decoder: Decoder[UnnamedOpenApi] = (cursor: HCursor) => | ||
cursor.as[String].map(UnnamedOpenApi(_)) | ||
} | ||
|
||
object NamedOpenApi { | ||
implicit val decoder: Decoder[NamedOpenApi] = (cursor: HCursor) => | ||
for { | ||
name <- cursor.get[String]("name") | ||
path <- cursor.get[String]("path") | ||
useProxy <- cursor.get[Option[Boolean]]("useProxy") | ||
} yield NamedOpenApi(name, path, useProxy) | ||
} |
Oops, something went wrong.