mirror of
https://github.com/netinvent/npbackup.git
synced 2024-11-10 17:15:28 +08:00
Reformat files with black
This commit is contained in:
parent
8b150f051b
commit
7600fc70b3
4 changed files with 39 additions and 35 deletions
|
@ -33,26 +33,10 @@ except ImportError:
|
|||
logger = getLogger(__name__)
|
||||
|
||||
ENCRYPTED_OPTIONS = [
|
||||
{
|
||||
'section': 'repo',
|
||||
'name': 'repository',
|
||||
'type': str
|
||||
},
|
||||
{
|
||||
'section': 'repo',
|
||||
'name': 'password',
|
||||
'type': str
|
||||
},
|
||||
{
|
||||
'section': 'prometheus',
|
||||
'name': 'http_username',
|
||||
'type': str
|
||||
},
|
||||
{
|
||||
'section': 'prometheus',
|
||||
'name': 'http_password',
|
||||
'type': str
|
||||
},
|
||||
{"section": "repo", "name": "repository", "type": str},
|
||||
{"section": "repo", "name": "password", "type": str},
|
||||
{"section": "prometheus", "name": "http_username", "type": str},
|
||||
{"section": "prometheus", "name": "http_password", "type": str},
|
||||
]
|
||||
|
||||
empty_config_dict = {"backup": {}, "repo": {}, "prometheus": {}, "env": {}}
|
||||
|
@ -62,17 +46,26 @@ def decrypt_data(config_dict):
|
|||
try:
|
||||
for option in ENCRYPTED_OPTIONS:
|
||||
try:
|
||||
if config_dict[option['section']][option['name']]:
|
||||
print(config_dict[option['section']][option['name']], option)
|
||||
_, config_dict[option['section']][option['name']] = enc.decrypt_message_hf(
|
||||
config_dict[option['section']][option['name']], AES_KEY, ID_STRING, ID_STRING
|
||||
if config_dict[option["section"]][option["name"]]:
|
||||
print(config_dict[option["section"]][option["name"]], option)
|
||||
(
|
||||
_,
|
||||
config_dict[option["section"]][option["name"]],
|
||||
) = enc.decrypt_message_hf(
|
||||
config_dict[option["section"]][option["name"]],
|
||||
AES_KEY,
|
||||
ID_STRING,
|
||||
ID_STRING,
|
||||
)
|
||||
except KeyError:
|
||||
logger.error("No {}:{} available.".format(option['section'], option['name']))
|
||||
logger.error(
|
||||
"No {}:{} available.".format(option["section"], option["name"])
|
||||
)
|
||||
logger.debug("Trace", exc_info=True)
|
||||
except ValueError:
|
||||
logger.error(
|
||||
"Cannot decrypt this configuration file. Has the AES key changed ?", exc_info=True
|
||||
"Cannot decrypt this configuration file. Has the AES key changed ?",
|
||||
exc_info=True,
|
||||
)
|
||||
sys.exit(11)
|
||||
except TypeError:
|
||||
|
@ -86,12 +79,19 @@ def decrypt_data(config_dict):
|
|||
def encrypt_data(config_dict):
|
||||
for option in ENCRYPTED_OPTIONS:
|
||||
try:
|
||||
if config_dict[option['section']][option['name']] and not config_dict[option['section']][option['name']].startswith(ID_STRING):
|
||||
config_dict[option['section']][option['name']] = enc.encrypt_message_hf(
|
||||
config_dict[option['section']][option['name']], AES_KEY, ID_STRING, ID_STRING
|
||||
if config_dict[option["section"]][option["name"]] and not config_dict[
|
||||
option["section"]
|
||||
][option["name"]].startswith(ID_STRING):
|
||||
config_dict[option["section"]][option["name"]] = enc.encrypt_message_hf(
|
||||
config_dict[option["section"]][option["name"]],
|
||||
AES_KEY,
|
||||
ID_STRING,
|
||||
ID_STRING,
|
||||
).decode("utf-8")
|
||||
except KeyError:
|
||||
logger.error("No {}:{} available.".format(option['section'], option['name']))
|
||||
logger.error(
|
||||
"No {}:{} available.".format(option["section"], option["name"])
|
||||
)
|
||||
logger.debug("Trace", exc_info=True)
|
||||
return config_dict
|
||||
|
||||
|
@ -100,8 +100,11 @@ def is_encrypted(config_dict):
|
|||
try:
|
||||
is_enc = True
|
||||
for option in ENCRYPTED_OPTIONS:
|
||||
if (isinstance(config_dict[option['section']][option['name']], config_dict[option['section']][option['type']])
|
||||
and not config_dict[option['section']][option['name']].startswith(ID_STRING)
|
||||
if isinstance(
|
||||
config_dict[option["section"]][option["name"]],
|
||||
config_dict[option["section"]][option["type"]],
|
||||
) and not config_dict[option["section"]][option["name"]].startswith(
|
||||
ID_STRING
|
||||
):
|
||||
is_enc = False
|
||||
return is_enc
|
||||
|
|
|
@ -2,6 +2,7 @@ import os
|
|||
import glob
|
||||
|
||||
from npbackup.path_helper import BASEDIR
|
||||
|
||||
RESTIC_SOURCE_FILES_DIR = os.path.join(BASEDIR, os.pardir, "RESTIC_SOURCE_FILES")
|
||||
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ This is free software, and you are welcome to redistribute it under certain cond
|
|||
|
||||
if args.license:
|
||||
try:
|
||||
with open(LICENSE_FILE, "r", 'utf-8') as file_handle:
|
||||
with open(LICENSE_FILE, "r", "utf-8") as file_handle:
|
||||
print(file_handle.read())
|
||||
except OSError:
|
||||
print(LICENSE_TEXT)
|
||||
|
|
|
@ -248,7 +248,7 @@ def upload_metrics(destination, authentication, metrics):
|
|||
|
||||
|
||||
def write_metrics_file(metrics, filename):
|
||||
with open(filename, "w", encoding='utf-8') as file_handle:
|
||||
with open(filename, "w", encoding="utf-8") as file_handle:
|
||||
for metric in metrics:
|
||||
file_handle.write(metric + "\n")
|
||||
|
||||
|
@ -323,7 +323,7 @@ if __name__ == "__main__":
|
|||
labels += ",{}".format(labels)
|
||||
destination_file = os.path.join(destination_dir, output_filename)
|
||||
try:
|
||||
with open(log_file, "r", encoding='utf-8') as file_handle:
|
||||
with open(log_file, "r", encoding="utf-8") as file_handle:
|
||||
errors, metrics = restic_output_2_metrics(
|
||||
True, output=file_handle.readlines(), labels=labels
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue