MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / validate_json_data

Function validate_json_data

web/pgadmin/utils/__init__.py:589–649  ·  view source on GitHub ↗

Used internally by load_servers to validate servers data. :param data: servers data :param is_admin: :return: error message if any

(data, is_admin)

Source from the content-addressed store, hash-verified

587
588
589def validate_json_data(data, is_admin):
590 """
591 Used internally by load_servers to validate servers data.
592 :param data: servers data
593 :param is_admin:
594 :return: error message if any
595 """
596 skip_servers = []
597 # Loop through the servers...
598 if "Servers" not in data:
599 return gettext("'Servers' attribute not found in the specified file.")
600
601 for server in data["Servers"]:
602 obj = data["Servers"][server]
603
604 # Check if server is shared.Won't import if user is non-admin
605 if obj.get('Shared', None) and not is_admin:
606 print("Won't import the server '%s' as it is shared " %
607 obj["Name"])
608 skip_servers.append(server)
609 continue
610
611 def check_attrib(attrib):
612 if attrib not in obj:
613 return gettext("'%s' attribute not found for server '%s'" %
614 (attrib, server))
615 return None
616
617 def check_is_integer(value):
618 if not isinstance(value, int):
619 return gettext("Port must be integer for server '%s'" % server)
620 return None
621
622 for attrib in ("Group", "Name"):
623 errmsg = check_attrib(attrib)
624 if errmsg:
625 return errmsg
626
627 is_service_attrib_available = obj.get("Service", None) is not None
628
629 if not is_service_attrib_available:
630 for attrib in ("Port", "Username"):
631 errmsg = check_attrib(attrib)
632 if errmsg:
633 return errmsg
634 if attrib == 'Port':
635 errmsg = check_is_integer(obj[attrib])
636 if errmsg:
637 return errmsg
638
639 errmsg = check_attrib("MaintenanceDB")
640 if errmsg:
641 return errmsg
642
643 if "Host" not in obj and not is_service_attrib_available:
644 return gettext("'Host' or 'Service' attribute not "
645 "found for server '%s'" % server)
646

Callers 2

load_serversFunction · 0.90
load_database_serversFunction · 0.85

Calls 5

gettextFunction · 0.85
check_attribFunction · 0.85
check_is_integerFunction · 0.85
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected