Skip to content

Commit 8dce8c8

Browse files
commands: add cli option & env var to control config validation
Add a --validate-config cli option and SAMBACC_VALIDATE_CONFIG environment variable to enable/disable (or leave automatic) the json schmea based validation of the config. Because json schema is new and there are cases (primarily as a dev hacking on stuff) we give the ability to turn off the validation. Note - the validation is auto by default - if the library is not present the validation will be automatically skipped. Signed-off-by: John Mulligan <[email protected]>
1 parent 6caa92e commit 8dce8c8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

sambacc/commands/main.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def global_args(parser: Parser) -> None:
9999
action="append",
100100
help=("Perform no action if the specified path exists."),
101101
)
102+
parser.add_argument(
103+
"--validate-config",
104+
choices=("auto", "required", "true", "false"),
105+
help=("Perform schema based validation of configuration."),
106+
)
102107

103108

104109
def from_env(
@@ -147,6 +152,7 @@ def env_to_cli(cli: typing.Any) -> None:
147152
from_env(cli, "username", "JOIN_USERNAME")
148153
from_env(cli, "password", "INSECURE_JOIN_PASSWORD")
149154
from_env(cli, "samba_debug_level", "SAMBA_DEBUG_LEVEL")
155+
from_env(cli, "validate_config", "SAMBACC_VALIDATE_CONFIG")
150156

151157

152158
class CommandContext:
@@ -165,11 +171,19 @@ def cli(self) -> argparse.Namespace:
165171
def instance_config(self) -> config.InstanceConfig:
166172
if self._iconfig is None:
167173
cfgs = self.cli.config or []
168-
self._iconfig = config.read_config_files(cfgs).get(
169-
self.cli.identity
170-
)
174+
self._iconfig = config.read_config_files(
175+
cfgs, require_validation=self.require_validation
176+
).get(self.cli.identity)
171177
return self._iconfig
172178

179+
@property
180+
def require_validation(self) -> typing.Optional[bool]:
181+
if self.cli.validate_config in ("required", "true"):
182+
return True
183+
if self.cli.validate_config == "false":
184+
return False
185+
return None
186+
173187

174188
def pre_action(cli: typing.Any) -> None:
175189
"""Handle debugging/diagnostic related options before the target

0 commit comments

Comments
 (0)