Human readable backup errors

This commit is contained in:
amcmanu3 2024-08-06 18:11:35 -04:00
parent ddfc13d9fd
commit 693cda4239
3 changed files with 187 additions and 39 deletions

View File

@ -14,7 +14,12 @@ logger = logging.getLogger(__name__)
BACKUP_SCHEMA = {
"type": "object",
"properties": {
"filename": {"type": "string", "minLength": 5},
"filename": {
"type": "string",
"minLength": 5,
"error": "typeString",
"fill": True,
},
},
"additionalProperties": False,
"minProperties": 1,
@ -22,14 +27,47 @@ BACKUP_SCHEMA = {
BACKUP_PATCH_SCHEMA = {
"type": "object",
"properties": {
"backup_name": {"type": "string", "minLength": 3},
"backup_location": {"type": "string", "minLength": 1},
"max_backups": {"type": "integer"},
"compress": {"type": "boolean"},
"shutdown": {"type": "boolean"},
"before": {"type": "string"},
"after": {"type": "string"},
"excluded_dirs": {"type": "array"},
"backup_name": {
"type": "string",
"minLength": 3,
"error": "backupName",
},
"backup_location": {
"type": "string",
"minLength": 1,
"error": "typeString",
"fill": True,
},
"max_backups": {
"type": "integer",
"error": "typeInteger",
"fill": True,
},
"compress": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"shutdown": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"before": {
"type": "string",
"error": "typeString",
"fill": True,
},
"after": {
"type": "string",
"error": "typeString",
"fill": True,
},
"excluded_dirs": {
"type": "array",
"error": "typeList",
"fill": True,
},
},
"additionalProperties": False,
"minProperties": 1,
@ -38,13 +76,37 @@ BACKUP_PATCH_SCHEMA = {
BASIC_BACKUP_PATCH_SCHEMA = {
"type": "object",
"properties": {
"backup_name": {"type": "string", "minLength": 3},
"max_backups": {"type": "integer"},
"compress": {"type": "boolean"},
"shutdown": {"type": "boolean"},
"before": {"type": "string"},
"after": {"type": "string"},
"excluded_dirs": {"type": "array"},
"backup_name": {"type": "string", "minLength": 3, "error": "backupName"},
"max_backups": {
"type": "integer",
"error": "typeInteger",
"fill": True,
},
"compress": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"shutdown": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"before": {
"type": "string",
"error": "typeString",
"fill": True,
},
"after": {
"type": "string",
"error": "typeString",
"fill": True,
},
"excluded_dirs": {
"type": "array",
"error": "typeList",
"fill": True,
},
},
"additionalProperties": False,
"minProperties": 1,
@ -179,13 +241,21 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
)
try:
validate(data, BACKUP_SCHEMA)
except ValidationError as e:
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)
@ -314,13 +384,21 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
validate(data, BACKUP_PATCH_SCHEMA)
else:
validate(data, BASIC_BACKUP_PATCH_SCHEMA)
except ValidationError as e:
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)
backup_conf = self.controller.management.get_backup_config(backup_id)
@ -405,13 +483,21 @@ class ApiServersServerBackupsBackupFilesIndexHandler(BaseApiHandler):
)
try:
validate(data, BACKUP_SCHEMA)
except ValidationError as e:
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)
self.helper.validate_traversal(

View File

@ -11,14 +11,43 @@ logger = logging.getLogger(__name__)
backup_patch_schema = {
"type": "object",
"properties": {
"backup_name": {"type": "string", "minLength": 3},
"backup_location": {"type": "string", "minLength": 1},
"max_backups": {"type": "integer"},
"compress": {"type": "boolean"},
"shutdown": {"type": "boolean"},
"before": {"type": "string"},
"after": {"type": "string"},
"excluded_dirs": {"type": "array"},
"backup_name": {"type": "string", "minLength": 3, "error": "backupName"},
"backup_location": {
"type": "string",
"minLength": 1,
"error": "typeString",
"fill": True,
},
"max_backups": {
"type": "integer",
"error": "typeInteger",
"fill": True,
},
"compress": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"shutdown": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"before": {
"type": "string",
"error": "typeString",
"fill": True,
},
"after": {
"type": "string",
"error": "typeString",
"fill": True,
},
"excluded_dirs": {
"type": "array",
"error": "typeList",
"fill": True,
},
},
"additionalProperties": False,
"minProperties": 1,
@ -27,13 +56,37 @@ backup_patch_schema = {
basic_backup_patch_schema = {
"type": "object",
"properties": {
"backup_name": {"type": "string", "minLength": 3},
"max_backups": {"type": "integer"},
"compress": {"type": "boolean"},
"shutdown": {"type": "boolean"},
"before": {"type": "string"},
"after": {"type": "string"},
"excluded_dirs": {"type": "array"},
"backup_name": {"type": "string", "minLength": 3, "error": "backupName"},
"max_backups": {
"type": "integer",
"error": "typeInt",
"fill": True,
},
"compress": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"shutdown": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"before": {
"type": "string",
"error": "typeString",
"fill": True,
},
"after": {
"type": "string",
"error": "typeString",
"fill": True,
},
"excluded_dirs": {
"type": "array",
"error": "typeList",
"fill": True,
},
},
"additionalProperties": False,
"minProperties": 1,
@ -76,13 +129,21 @@ class ApiServersServerBackupsIndexHandler(BaseApiHandler):
validate(data, backup_patch_schema)
else:
validate(data, basic_backup_patch_schema)
except ValidationError as e:
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)
if server_id not in [str(x["server_id"]) for x in auth_data[0]]:

View File

@ -668,6 +668,7 @@
"uses": "Number of uses allowed (-1==No Limit)"
},
"validators": {
"backupName": "Backup name must be a string and a minimum length of 3.",
"enumErr": "failed validating. Acceptable data includes: ",
"filesPageLen": "length must be greater than 1 for property",
"passLength": "Password Too Short. Minimum Length: 8",