elif node in props:
node_schema = props[node]
+ if "anyOf" in node_schema:
+ for item in node_schema["anyOf"]:
+ print(item)
+
+ elif "type" not in node_schema:
+ pass
+
+ elif node_schema["type"] == "array":
+ if ln > 2:
+ # skip index for item in array
+ return _path_comp_words(nodes[i + 2], nodes, node_schema["items"]["properties"])
+ if "enum" in node_schema["items"]:
+ print(node_schema["items"]["enum"])
+ return {"0": "first array item", "-": "last array item"}
+ elif node_schema["type"] == "object":
+ if "additionalProperties" in node_schema:
+ print(node_schema)
+ return _path_comp_words(nodes[i + 1], nodes, node_schema["properties"])
+ return {}
+
# arrays/lists must be handled sparately
if node_schema["type"] == "array":
if ln > 2:
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- config = subparser.add_parser("config", help="change configuration of a running resolver")
+ config = subparser.add_parser("config", help="Performs operations on the running resolver's configuration.")
config.add_argument(
"path",
type=str,
- help="path to the specify part of the configuration to work with",
+ help="Path (JSON pointer, RFC6901) to the configuration resources to work with.",
)
- config.add_argument("--stdin", help="read new config value on stdin", action="store_true", default=False)
+ config.add_argument("--stdin", help="Read config values from stdin.", action="store_true", default=False)
config.add_argument(
"value_or_file",
type=str,
nargs="?",
- help="optional, new configuration values, path to the file with new values or path to the file to export data",
+ help="Optional, new configuration value, path to file with new configuraion or path to file where to save exported configuration data."
+ "If not specified, the configuration is printed.",
default=None,
)
operations.add_argument(
"-s",
"--set",
- help="set new configuration",
+ help="Set new configuration for the resolver.",
action="store_const",
dest=op_dest,
const=Operations.SET,
operations.add_argument(
"-d",
"--delete",
- help="delete configuration",
+ help="Delete given configuration property or list item at the given index.",
action="store_const",
dest=op_dest,
const=Operations.DELETE,
)
operations.add_argument(
- "-g", "--get", help="get configuration", action="store_const", dest=op_dest, const=Operations.GET
+ "-g",
+ "--get",
+ help="Get current configuration from the resolver.",
+ action="store_const",
+ dest=op_dest,
+ const=Operations.GET,
)
fm_dest = "format"
formats = config.add_mutually_exclusive_group()
formats.add_argument(
"--json",
- help="JSON configuration format",
+ help="JSON format for input configuration or required format for exported configuration.",
action="store_const",
dest=fm_dest,
const=Formats.JSON,
default=Formats.JSON,
)
formats.add_argument(
- "--yaml", help="YAML configuration format", action="store_const", dest=fm_dest, const=Formats.YAML
+ "--yaml",
+ help="YAML format for input configuration or required format for exported configuration.",
+ action="store_const",
+ dest=fm_dest,
+ const=Formats.YAML,
)
return config, ConfigCommand
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- convert = subparser.add_parser("convert", help="convert JSON/YAML configuration to Lua script")
+ convert = subparser.add_parser("convert", help="Converts JSON or YAML configuration to Lua script.")
convert.add_argument(
"input_file",
type=str,
- help="JSON/YAML configuration input file",
+ help="File with configuration in YAML or JSON format.",
)
- convert.add_argument("--stdin", help="read new config value on stdin", action="store_true", default=False)
+ convert.add_argument("--stdin", help="Read config values from stdin.", action="store_true", default=False)
convert.add_argument(
"output_file",
type=str,
nargs="?",
- help="optional, output Lua script file",
+ help="Optional, output file for converted configuration in Lua script. If not specified, converted configuration is printed.",
default=None,
)
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
metrics = subparser.add_parser("metrics", help="get prometheus metrics data")
- metrics.add_argument("file", help="optional, file to export metrics to", nargs="?", default=None)
+ metrics.add_argument(
+ "file",
+ help="Optional, file where to export Prometheus metrics. If not specified, the metrics are printed.",
+ nargs="?",
+ default=None,
+ )
return metrics, MetricsCommand
@staticmethod
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- reload = subparser.add_parser("reload", help="reload configuration file")
+ reload = subparser.add_parser(
+ "reload",
+ help="Tells the resolver to reload YAML configuration file."
+ " Old processes are replaced by new ones (with updated configuration) using rolling restarts."
+ " So there will be no DNS service unavailability during reload operation.",
+ )
return reload, ReloadCommand
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- schema = subparser.add_parser("schema", help="get JSON schema representation of the configuration")
- schema.add_argument("file", help="optional, file to export JSON schema to", nargs="?", default=None)
+ schema = subparser.add_parser(
+ "schema", help="Reads JSON-schema repersentation of the configuration directly from the running resolver."
+ )
+ schema.add_argument("file", help="Optional, file where to export JSON-schema.", nargs="?", default=None)
return schema, SchemaCommand
@staticmethod
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- stop = subparser.add_parser("stop", help="shutdown everything")
+ stop = subparser.add_parser(
+ "stop", help="Tells the resolver to shutdown everthing. No process will run after this command."
+ )
return stop, StopCommand
def register_args_subparser(
subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
- validate = subparser.add_parser("validate", help="validate JSON/YAML configuration")
+ validate = subparser.add_parser("validate", help="Validates configuration in JSON or YAML format.")
validate.add_argument(
"input_file",
type=str,
nargs="?",
- help="JSON/YAML configuration input file",
+ help="File with configuration in YAML or JSON format.",
default=None,
)
def create_main_argument_parser() -> argparse.ArgumentParser:
- parser = argparse.ArgumentParser("kresctl", description="Command-line interface for controlling Knot Resolver")
- parser.add_argument(
- "-i",
- "--interactive",
- action="store_true",
- help="Interactive mode of kresctl utility",
- default=False,
- required=False,
+ parser = argparse.ArgumentParser(
+ "kresctl",
+ description="Command-line utility that helps communicate with Knot Resolver's management API."
+ "It also provides tooling to work with declarative configuration (validate, convert).",
)
+ # parser.add_argument(
+ # "-i",
+ # "--interactive",
+ # action="store_true",
+ # help="Interactive mode of kresctl utility",
+ # default=False,
+ # required=False,
+ # )
parser.add_argument(
"-s",
"--socket",
action="store",
type=str,
- help="Path to the Unix domain socket of the configuration API",
+ help="Optional, path to Unix-domain socket or network interface of the management API.",
default=["http+unix://%2Fvar%2Frun%2Fknot-resolver%2Fmanager.sock"], # FIXME
nargs=1,
required=False,
autoimport_commands()
parser = create_main_argument_parser()
install_commands_parsers(parser)
+
namespace = parser.parse_args()
kresctl = Kresctl(namespace, parser)
+ kresctl.execute()
- if namespace.interactive or len(vars(namespace)) == 2:
- kresctl.interactive()
- else:
- kresctl.execute()
+ # if namespace.interactive or len(vars(namespace)) == 2:
+ # kresctl.interactive()
+ # else:
+ # kresctl.execute()