mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-10 05:55:08 +00:00
Bumping vendor/nim-confutils and vendor/nim-serialization (#2056)
This commit is contained in:
parent
5f9896448d
commit
1c4533a27a
@ -273,7 +273,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
|
|||||||
# XXX: Here at the moment
|
# XXX: Here at the moment
|
||||||
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raise newException(ConfigurationError, "Invalid private key")
|
raise newException(ValueError, "Invalid private key")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -282,7 +282,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = ValidIpAddress.init(p)
|
result = ValidIpAddress.init(p)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raise newException(ConfigurationError, "Invalid IP address")
|
raise newException(ValueError, "Invalid IP address")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -291,7 +291,7 @@ proc parseCmdArg*(T: type Port, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = Port(parseInt(p))
|
result = Port(parseInt(p))
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raise newException(ConfigurationError, "Invalid Port number")
|
raise newException(ValueError, "Invalid Port number")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -300,7 +300,7 @@ proc parseCmdArg*(T: type Option[uint], p: string): T =
|
|||||||
try:
|
try:
|
||||||
some(parseUint(p))
|
some(parseUint(p))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid unsigned integer")
|
raise newException(ValueError, "Invalid unsigned integer")
|
||||||
|
|
||||||
func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
|
func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
|
||||||
# TODO: How should we select between IPv4 and IPv6
|
# TODO: How should we select between IPv4 and IPv6
|
||||||
|
@ -134,7 +134,7 @@ proc parseCmdArg*(T: type keys.KeyPair, p: string): T =
|
|||||||
let privkey = keys.PrivateKey.fromHex(string(p)).tryGet()
|
let privkey = keys.PrivateKey.fromHex(string(p)).tryGet()
|
||||||
result = privkey.toKeyPair()
|
result = privkey.toKeyPair()
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid private key")
|
raise newException(ValueError, "Invalid private key")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type keys.KeyPair, val: string): seq[string] =
|
proc completeCmdArg*(T: type keys.KeyPair, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -144,7 +144,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
|
|||||||
if key.isOk():
|
if key.isOk():
|
||||||
crypto.PrivateKey(scheme: Secp256k1, skkey: key.get())
|
crypto.PrivateKey(scheme: Secp256k1, skkey: key.get())
|
||||||
else:
|
else:
|
||||||
raise newException(ConfigurationError, "Invalid private key")
|
raise newException(ValueError, "Invalid private key")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -153,7 +153,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = ValidIpAddress.init(p)
|
result = ValidIpAddress.init(p)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid IP address")
|
raise newException(ValueError, "Invalid IP address")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
@ -69,7 +69,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = ValidIpAddress.init(p)
|
result = ValidIpAddress.init(p)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raise newException(ConfigurationError, "Invalid IP address")
|
raise newException(ValueError, "Invalid IP address")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -78,7 +78,7 @@ proc parseCmdArg*(T: type chronos.Duration, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = chronos.seconds(parseInt(p))
|
result = chronos.seconds(parseInt(p))
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raise newException(ConfigurationError, "Invalid duration value")
|
raise newException(ValueError, "Invalid duration value")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
@ -72,7 +72,7 @@ proc parseCmdArg*(T: type chronos.Duration, p: string): T =
|
|||||||
try:
|
try:
|
||||||
result = chronos.seconds(parseInt(p))
|
result = chronos.seconds(parseInt(p))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid timeout value")
|
raise newException(ValueError, "Invalid timeout value")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
@ -25,7 +25,6 @@ export
|
|||||||
confEnvvarDefs,
|
confEnvvarDefs,
|
||||||
confEnvvarNet
|
confEnvvarNet
|
||||||
|
|
||||||
|
|
||||||
type ConfResult*[T] = Result[T, string]
|
type ConfResult*[T] = Result[T, string]
|
||||||
type ProtectedTopic* = object
|
type ProtectedTopic* = object
|
||||||
topic*: string
|
topic*: string
|
||||||
@ -456,7 +455,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
|
|||||||
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
|
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
|
||||||
crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid private key")
|
raise newException(ValueError, "Invalid private key")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -464,11 +463,11 @@ proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
|||||||
proc parseCmdArg*(T: type ProtectedTopic, p: string): T =
|
proc parseCmdArg*(T: type ProtectedTopic, p: string): T =
|
||||||
let elements = p.split(":")
|
let elements = p.split(":")
|
||||||
if elements.len != 2:
|
if elements.len != 2:
|
||||||
raise newException(ConfigurationError, "Invalid format for protected topic expected topic:publickey")
|
raise newException(ValueError, "Invalid format for protected topic expected topic:publickey")
|
||||||
|
|
||||||
let publicKey = secp256k1.SkPublicKey.fromHex(elements[1])
|
let publicKey = secp256k1.SkPublicKey.fromHex(elements[1])
|
||||||
if publicKey.isErr:
|
if publicKey.isErr:
|
||||||
raise newException(ConfigurationError, "Invalid public key")
|
raise newException(ValueError, "Invalid public key")
|
||||||
|
|
||||||
return ProtectedTopic(topic: elements[0], key: publicKey.get())
|
return ProtectedTopic(topic: elements[0], key: publicKey.get())
|
||||||
|
|
||||||
@ -479,7 +478,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
|||||||
try:
|
try:
|
||||||
ValidIpAddress.init(p)
|
ValidIpAddress.init(p)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid IP address")
|
raise newException(ValueError, "Invalid IP address")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -489,12 +488,11 @@ proc defaultListenAddress*(): ValidIpAddress =
|
|||||||
# Maybe there should be a config option for this.
|
# Maybe there should be a config option for this.
|
||||||
(static ValidIpAddress.init("0.0.0.0"))
|
(static ValidIpAddress.init("0.0.0.0"))
|
||||||
|
|
||||||
|
|
||||||
proc parseCmdArg*(T: type Port, p: string): T =
|
proc parseCmdArg*(T: type Port, p: string): T =
|
||||||
try:
|
try:
|
||||||
Port(parseInt(p))
|
Port(parseInt(p))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid Port number")
|
raise newException(ValueError, "Invalid Port number")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
@ -503,13 +501,13 @@ proc parseCmdArg*(T: type Option[int], p: string): T =
|
|||||||
try:
|
try:
|
||||||
some(parseInt(p))
|
some(parseInt(p))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid number")
|
raise newException(ValueError, "Invalid number")
|
||||||
|
|
||||||
proc parseCmdArg*(T: type Option[uint], p: string): T =
|
proc parseCmdArg*(T: type Option[uint], p: string): T =
|
||||||
try:
|
try:
|
||||||
some(parseUint(p))
|
some(parseUint(p))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid unsigned integer")
|
raise newException(ValueError, "Invalid unsigned integer")
|
||||||
|
|
||||||
## Configuration validation
|
## Configuration validation
|
||||||
|
|
||||||
@ -531,7 +529,6 @@ proc readValue*(r: var TomlReader, value: var crypto.PrivateKey) {.raises: [Seri
|
|||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(SerializationError, getCurrentExceptionMsg())
|
raise newException(SerializationError, getCurrentExceptionMsg())
|
||||||
|
|
||||||
|
|
||||||
proc readValue*(r: var EnvvarReader, value: var crypto.PrivateKey) {.raises: [SerializationError].} =
|
proc readValue*(r: var EnvvarReader, value: var crypto.PrivateKey) {.raises: [SerializationError].} =
|
||||||
try:
|
try:
|
||||||
value = parseCmdArg(crypto.PrivateKey, r.readValue(string))
|
value = parseCmdArg(crypto.PrivateKey, r.readValue(string))
|
||||||
@ -556,7 +553,8 @@ proc load*(T: type WakuNodeConf, version=""): ConfResult[T] =
|
|||||||
try:
|
try:
|
||||||
let conf = WakuNodeConf.load(
|
let conf = WakuNodeConf.load(
|
||||||
version=version,
|
version=version,
|
||||||
secondarySources = proc (conf: WakuNodeConf, sources: auto) =
|
secondarySources = proc (conf: WakuNodeConf, sources: auto)
|
||||||
|
{.gcsafe, raises: [ConfigurationError].} =
|
||||||
sources.addConfigFile(Envvar, InputFile("wakunode2"))
|
sources.addConfigFile(Envvar, InputFile("wakunode2"))
|
||||||
|
|
||||||
if conf.configFile.isSome():
|
if conf.configFile.isSome():
|
||||||
|
@ -12,7 +12,6 @@ import
|
|||||||
../../waku/common/confutils/envvar/defs as confEnvvarDefs,
|
../../waku/common/confutils/envvar/defs as confEnvvarDefs,
|
||||||
../../waku/common/confutils/envvar/std/net as confEnvvarNet
|
../../waku/common/confutils/envvar/std/net as confEnvvarNet
|
||||||
|
|
||||||
|
|
||||||
type ConfResult[T] = Result[T, string]
|
type ConfResult[T] = Result[T, string]
|
||||||
|
|
||||||
type TestConf = object
|
type TestConf = object
|
||||||
@ -34,13 +33,13 @@ type TestConf = object
|
|||||||
defaultValue: 60000,
|
defaultValue: 60000,
|
||||||
name: "tcp-port" }: Port
|
name: "tcp-port" }: Port
|
||||||
|
|
||||||
|
|
||||||
{.push warning[ProveInit]: off.}
|
{.push warning[ProveInit]: off.}
|
||||||
|
|
||||||
proc load*(T: type TestConf, prefix: string): ConfResult[T] =
|
proc load*(T: type TestConf, prefix: string): ConfResult[T] =
|
||||||
try:
|
try:
|
||||||
let conf = TestConf.load(
|
let conf = TestConf.load(
|
||||||
secondarySources = proc (conf: TestConf, sources: auto) =
|
secondarySources = proc (conf: TestConf, sources: auto)
|
||||||
|
{.gcsafe, raises: [ConfigurationError].} =
|
||||||
sources.addConfigFile(Envvar, InputFile(prefix))
|
sources.addConfigFile(Envvar, InputFile(prefix))
|
||||||
)
|
)
|
||||||
ok(conf)
|
ok(conf)
|
||||||
@ -49,7 +48,6 @@ proc load*(T: type TestConf, prefix: string): ConfResult[T] =
|
|||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
||||||
suite "nim-confutils - envvar":
|
suite "nim-confutils - envvar":
|
||||||
test "load configuration from environment variables":
|
test "load configuration from environment variables":
|
||||||
## Given
|
## Given
|
||||||
|
2
vendor/nim-confutils
vendored
2
vendor/nim-confutils
vendored
@ -1 +1 @@
|
|||||||
Subproject commit c8063eb8142aeb6489ded24f3da908bc7f921b7b
|
Subproject commit 674c9e4c8e0cad2b7193cc9a59c12d39a397750f
|
2
vendor/nim-serialization
vendored
2
vendor/nim-serialization
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 5b7cea55efeb074daa8abd8146a03a34adb4521a
|
Subproject commit 4bdbc29e54fe54049950e352bb969aab97173b35
|
@ -3,7 +3,6 @@ when (NimMajor, NimMinor) < (1, 4):
|
|||||||
else:
|
else:
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
|
|
||||||
import
|
import
|
||||||
std/strutils,
|
std/strutils,
|
||||||
stew/shims/net
|
stew/shims/net
|
||||||
@ -14,15 +13,14 @@ export
|
|||||||
net,
|
net,
|
||||||
envvar_serialization
|
envvar_serialization
|
||||||
|
|
||||||
|
|
||||||
proc readValue*(r: var EnvvarReader, value: var ValidIpAddress) {.raises: [SerializationError].} =
|
proc readValue*(r: var EnvvarReader, value: var ValidIpAddress) {.raises: [SerializationError].} =
|
||||||
try:
|
try:
|
||||||
value = ValidIpAddress.init(r.readValue(string))
|
value = ValidIpAddress.init(r.readValue(string))
|
||||||
except ValueError:
|
except ValueError, IOError:
|
||||||
raise newException(EnvvarError, "Invalid IP address")
|
raise newException(SerializationError, "Invalid IP address: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
proc readValue*(r: var EnvvarReader, value: var Port) {.raises: [SerializationError, ValueError].} =
|
proc readValue*(r: var EnvvarReader, value: var Port) {.raises: [SerializationError].} =
|
||||||
try:
|
try:
|
||||||
value = parseUInt(r.readValue(string)).Port
|
value = parseUInt(r.readValue(string)).Port
|
||||||
except ValueError:
|
except ValueError, IOError:
|
||||||
raise newException(EnvvarError, "Invalid Port")
|
raise newException(SerializationError, "Invalid Port: " & getCurrentExceptionMsg())
|
||||||
|
@ -39,7 +39,7 @@ proc handleReadException*(r: EnvvarReader,
|
|||||||
proc init*(T: type EnvvarReader, prefix: string): T =
|
proc init*(T: type EnvvarReader, prefix: string): T =
|
||||||
result.prefix = prefix
|
result.prefix = prefix
|
||||||
|
|
||||||
proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, SerializationError].} =
|
proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [SerializationError].} =
|
||||||
mixin readValue
|
mixin readValue
|
||||||
|
|
||||||
when T is string:
|
when T is string:
|
||||||
@ -48,7 +48,11 @@ proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, Ser
|
|||||||
|
|
||||||
elif T is (SomePrimitives or range):
|
elif T is (SomePrimitives or range):
|
||||||
let key = constructKey(r.prefix, r.key)
|
let key = constructKey(r.prefix, r.key)
|
||||||
|
try:
|
||||||
getValue(key, value)
|
getValue(key, value)
|
||||||
|
except ValueError:
|
||||||
|
raise newException(SerializationError,
|
||||||
|
"Couldn't getValue SomePrimitives: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
elif T is Option:
|
elif T is Option:
|
||||||
template getUnderlyingType[T](_: Option[T]): untyped = T
|
template getUnderlyingType[T](_: Option[T]): untyped = T
|
||||||
@ -58,7 +62,11 @@ proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, Ser
|
|||||||
when uType is string:
|
when uType is string:
|
||||||
value = some(os.getEnv(key))
|
value = some(os.getEnv(key))
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
value = some(r.readValue(uType))
|
value = some(r.readValue(uType))
|
||||||
|
except ValueError, IOError:
|
||||||
|
raise newException(SerializationError,
|
||||||
|
"Couldn't read Option value: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
elif T is (seq or array):
|
elif T is (seq or array):
|
||||||
when uTypeIsPrimitives(T):
|
when uTypeIsPrimitives(T):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user