mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-06 16:03:08 +00:00
Split `WakuNodeConfig` object for better separation of concerns and to introduce a tree-like structure to configuration. * fix: ensure twn cluster conf is still applied when clusterId=1 * test: remove usage of `WakuNodeConf` * Remove macro, split builder files, remove wakunodeconf from tests * rm network_conf_builder module as it is not used --------- Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Co-authored-by: Ivan Folgueira Bande <ivansete@status.im>
65 lines
1.9 KiB
Nim
65 lines
1.9 KiB
Nim
import chronicles, std/[net, options, sequtils], results
|
|
import ../waku_conf
|
|
|
|
logScope:
|
|
topics = "waku conf builder rest server"
|
|
|
|
################################
|
|
## REST Server Config Builder ##
|
|
################################
|
|
type RestServerConfBuilder* = object
|
|
enabled*: Option[bool]
|
|
|
|
allowOrigin*: seq[string]
|
|
listenAddress*: Option[IpAddress]
|
|
port*: Option[Port]
|
|
admin*: Option[bool]
|
|
relayCacheCapacity*: Option[uint32]
|
|
|
|
proc init*(T: type RestServerConfBuilder): RestServerConfBuilder =
|
|
RestServerConfBuilder()
|
|
|
|
proc withEnabled*(b: var RestServerConfBuilder, enabled: bool) =
|
|
b.enabled = some(enabled)
|
|
|
|
proc withAllowOrigin*(b: var RestServerConfBuilder, allowOrigin: seq[string]) =
|
|
b.allowOrigin = concat(b.allowOrigin, allowOrigin)
|
|
|
|
proc withListenAddress*(b: var RestServerConfBuilder, listenAddress: IpAddress) =
|
|
b.listenAddress = some(listenAddress)
|
|
|
|
proc withPort*(b: var RestServerConfBuilder, port: Port) =
|
|
b.port = some(port)
|
|
|
|
proc withPort*(b: var RestServerConfBuilder, port: uint16) =
|
|
b.port = some(Port(port))
|
|
|
|
proc withAdmin*(b: var RestServerConfBuilder, admin: bool) =
|
|
b.admin = some(admin)
|
|
|
|
proc withRelayCacheCapacity*(b: var RestServerConfBuilder, relayCacheCapacity: uint32) =
|
|
b.relayCacheCapacity = some(relayCacheCapacity)
|
|
|
|
proc build*(b: RestServerConfBuilder): Result[Option[RestServerConf], string] =
|
|
if not b.enabled.get(false):
|
|
return ok(none(RestServerConf))
|
|
|
|
if b.listenAddress.isNone():
|
|
return err("restServer.listenAddress is not specified")
|
|
if b.port.isNone():
|
|
return err("restServer.port is not specified")
|
|
if b.relayCacheCapacity.isNone():
|
|
return err("restServer.relayCacheCapacity is not specified")
|
|
|
|
return ok(
|
|
some(
|
|
RestServerConf(
|
|
allowOrigin: b.allowOrigin,
|
|
listenAddress: b.listenAddress.get(),
|
|
port: b.port.get(),
|
|
admin: b.admin.get(false),
|
|
relayCacheCapacity: b.relayCacheCapacity.get(),
|
|
)
|
|
)
|
|
)
|