
io.k8s.api.networking.v1.IngressRule.scala Maven / Gradle / Ivy
package io.k8s.api.networking.v1
import dev.hnaderi.k8s.utils._
/** IngressRule represents the rules mapping the paths under a specified host to the related backend services. Incoming requests are first evaluated for a host match, then routed to the backend associated with the matching IngressRuleValue. */
final case class IngressRule(
host : Option[String] = None,
http : Option[io.k8s.api.networking.v1.HTTPIngressRuleValue] = None
) {
/** Returns a new data with host set to new value */
def withHost(value: String) : IngressRule = copy(host = Some(value))
/** if host has a value, transforms to the result of function*/
def mapHost(f: String => String) : IngressRule = copy(host = host.map(f))
/** Returns a new data with http set to new value */
def withHttp(value: io.k8s.api.networking.v1.HTTPIngressRuleValue) : IngressRule = copy(http = Some(value))
/** if http has a value, transforms to the result of function*/
def mapHttp(f: io.k8s.api.networking.v1.HTTPIngressRuleValue => io.k8s.api.networking.v1.HTTPIngressRuleValue) : IngressRule = copy(http = http.map(f))
}
object IngressRule {
implicit val encoder : Encoder[io.k8s.api.networking.v1.IngressRule] = new Encoder[io.k8s.api.networking.v1.IngressRule] {
def apply[T : Builder](o: io.k8s.api.networking.v1.IngressRule) : T = {
val obj = ObjectWriter[T]()
obj
.write("host", o.host)
.write("http", o.http)
.build
}
}
implicit val decoder: Decoder[IngressRule] = new Decoder[IngressRule] {
def apply[T : Reader](t: T): Either[String, IngressRule] = for {
obj <- ObjectReader(t)
host <- obj.readOpt[String]("host")
http <- obj.readOpt[io.k8s.api.networking.v1.HTTPIngressRuleValue]("http")
} yield IngressRule (
host = host,
http = http
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy