-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: configure protected topics via cli #1696
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,7 +11,8 @@ import | |||||||||||||||
libp2p/crypto/crypto, | ||||||||||||||||
libp2p/crypto/secp, | ||||||||||||||||
libp2p/multiaddress, | ||||||||||||||||
nimcrypto/utils | ||||||||||||||||
nimcrypto/utils, | ||||||||||||||||
secp256k1 | ||||||||||||||||
import | ||||||||||||||||
../../waku/common/confutils/envvar/defs as confEnvvarDefs, | ||||||||||||||||
../../waku/common/confutils/envvar/std/net as confEnvvarNet, | ||||||||||||||||
|
@@ -25,13 +26,22 @@ export | |||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
type ConfResult*[T] = Result[T, string] | ||||||||||||||||
type ProtectedTopic* = object | ||||||||||||||||
topic*: string | ||||||||||||||||
key*: secp256k1.SkPublicKey | ||||||||||||||||
|
||||||||||||||||
type | ||||||||||||||||
WakuNodeConf* = object | ||||||||||||||||
configFile* {. | ||||||||||||||||
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)" | ||||||||||||||||
name: "config-file" }: Option[InputFile] | ||||||||||||||||
|
||||||||||||||||
## Application-level configuration | ||||||||||||||||
protectedTopics* {. | ||||||||||||||||
desc: "Topics and its public key to be used for message validation, topic:pubkey. Argument may be repeated." | ||||||||||||||||
defaultValue: newSeq[ProtectedTopic](0) | ||||||||||||||||
name: "protected-topic" .}: seq[ProtectedTopic] | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
## Log configuration | ||||||||||||||||
logLevel* {. | ||||||||||||||||
|
@@ -457,6 +467,19 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T = | |||||||||||||||
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] = | ||||||||||||||||
return @[] | ||||||||||||||||
|
||||||||||||||||
proc parseCmdArg*(T: type ProtectedTopic, p: string): T = | ||||||||||||||||
let elements = p.split(":") | ||||||||||||||||
if elements.len != 2: | ||||||||||||||||
raise newException(ConfigurationError, "Invalid format for protected topic expected topic:publickey") | ||||||||||||||||
|
||||||||||||||||
let publicKey = secp256k1.SkPublicKey.fromHex(elements[1]) | ||||||||||||||||
if publicKey.isErr: | ||||||||||||||||
raise newException(ConfigurationError, "Invalid public key") | ||||||||||||||||
|
||||||||||||||||
return ProtectedTopic(topic: elements[0], key: publicKey.get()) | ||||||||||||||||
|
||||||||||||||||
proc completeCmdArg*(T: type ProtectedTopic, val: string): seq[string] = | ||||||||||||||||
return @[] | ||||||||||||||||
|
||||||||||||||||
proc parseCmdArg*(T: type ValidIpAddress, p: string): T = | ||||||||||||||||
try: | ||||||||||||||||
|
@@ -533,6 +556,17 @@ proc readValue*(r: var EnvvarReader, value: var crypto.PrivateKey) {.raises: [Se | |||||||||||||||
except CatchableError: | ||||||||||||||||
raise newException(SerializationError, getCurrentExceptionMsg()) | ||||||||||||||||
|
||||||||||||||||
proc readValue*(r: var TomlReader, value: var ProtectedTopic) {.raises: [SerializationError].} = | ||||||||||||||||
try: | ||||||||||||||||
value = parseCmdArg(ProtectedTopic, r.readValue(string)) | ||||||||||||||||
except CatchableError: | ||||||||||||||||
raise newException(SerializationError, getCurrentExceptionMsg()) | ||||||||||||||||
Comment on lines
+559
to
+563
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could reduce some code:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mm unsure how this works under the hood, so just mirroring what we currently have in other |
||||||||||||||||
|
||||||||||||||||
proc readValue*(r: var EnvvarReader, value: var ProtectedTopic) {.raises: [SerializationError].} = | ||||||||||||||||
try: | ||||||||||||||||
value = parseCmdArg(ProtectedTopic, r.readValue(string)) | ||||||||||||||||
except CatchableError: | ||||||||||||||||
raise newException(SerializationError, getCurrentExceptionMsg()) | ||||||||||||||||
|
||||||||||||||||
{.push warning[ProveInit]: off.} | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we append the
publicKey.error()
at this point?