mirror of
https://github.com/netinvent/npbackup.git
synced 2025-02-23 22:15:43 +08:00
CLI: Add --show-config parameter
This commit is contained in:
parent
38c0287fd4
commit
fb4905aa03
3 changed files with 36 additions and 3 deletions
|
@ -16,7 +16,6 @@
|
|||
## 3.0.0
|
||||
!- Multi repository support (everything except repo URI can be inherited from groups)
|
||||
- Major config file rewrite, now repo can inherit common settings from repo groups
|
||||
! - New option --show-final-config to show inheritance in cli mode (gui mode has visual indicators)
|
||||
!- Group settings for repositories
|
||||
!- New operation planifier for backups / cleaning / checking repos
|
||||
- Current backup state now shows more precise backup state, including last backup date when relevant
|
||||
|
@ -57,7 +56,7 @@
|
|||
- Added minimum backup size upon which we declare that backup has failed
|
||||
- All bytes units now have automatic conversion of units (K/M/G/T/P bits/bytes or IEC bytes)
|
||||
- Refactored GUI and overall UX of configuration
|
||||
|
||||
- New option --show-config to show inheritance in CLI mode (GUI has visual indicators)
|
||||
## Fixes
|
||||
- Default exit code is now worst log level called
|
||||
- Show anonymized repo uri in GUI
|
||||
|
|
|
@ -224,6 +224,11 @@ This is free software, and you are welcome to redistribute it under certain cond
|
|||
required=False,
|
||||
help="Optional path for logfile",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--show-config",
|
||||
action="store_true",
|
||||
help="Show full inherited configuration for current repo"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.log_file:
|
||||
|
@ -290,6 +295,11 @@ This is free software, and you are welcome to redistribute it under certain cond
|
|||
msg = "Cannot find repo config"
|
||||
json_error_logging(False, msg, "critical")
|
||||
sys.exit(72)
|
||||
|
||||
if args.show_config:
|
||||
repo_config = npbackup.configuration.get_anonymous_repo_config(repo_config)
|
||||
print(json.dumps(repo_config, indent=4))
|
||||
sys.exit(0)
|
||||
|
||||
# Prepare program run
|
||||
cli_args = {
|
||||
|
|
|
@ -244,7 +244,7 @@ def get_default_config() -> dict:
|
|||
return convert_to(full_config)
|
||||
|
||||
|
||||
def key_should_be_encrypted(key, encrypted_options: List[str]):
|
||||
def key_should_be_encrypted(key: str, encrypted_options: List[str]):
|
||||
"""
|
||||
Checks whether key should be encrypted
|
||||
"""
|
||||
|
@ -783,3 +783,27 @@ def get_repos_by_group(full_config: dict, group: str) -> List[str]:
|
|||
):
|
||||
repo_list.append(repo)
|
||||
return repo_list
|
||||
|
||||
|
||||
def get_anonymous_repo_config(repo_config: dict) -> dict:
|
||||
"""
|
||||
Replace each encrypted value with
|
||||
"""
|
||||
def _get_anonymous_repo_config(key: str, value: Any) -> Any:
|
||||
if key_should_be_encrypted(key, ENCRYPTED_OPTIONS):
|
||||
if isinstance(value, list):
|
||||
for i, _ in enumerate(value):
|
||||
value[i] = "__(o_O)__"
|
||||
else:
|
||||
value = "__(o_O)__"
|
||||
return value
|
||||
|
||||
# NPF-SEC-00008: Don't show manager password / sensible data with --show-config
|
||||
repo_config.pop("manager_password", None)
|
||||
repo_config.pop("__current_manager_password", None)
|
||||
return replace_in_iterable(
|
||||
repo_config,
|
||||
_get_anonymous_repo_config,
|
||||
callable_wants_key=True,
|
||||
callable_wants_root_key=True,
|
||||
)
|
Loading…
Reference in a new issue