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

Function adhoc_connect_server

web/pgadmin/misc/workspaces/__init__.py:64–213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62)
63@pga_login_required
64def adhoc_connect_server():
65 required_args = ['server_name', 'did']
66
67 data = request.form if request.form else json.loads(
68 request.data
69 )
70
71 # Loop through data and if found any value is blank string then
72 # convert it to None as after porting into React, from frontend
73 # '' blank string is coming as a value instead of null.
74 for item in data:
75 if data[item] == '':
76 data[item] = None
77
78 # Some fields can be provided with service file so they are optional
79 if 'service' in data and not data['service']:
80 required_args.extend([
81 'host',
82 'port',
83 'user'
84 ])
85
86 for arg in required_args:
87 if arg not in data:
88 return make_json_response(
89 status=410,
90 success=0,
91 errormsg=gettext(
92 "Could not find the required parameter ({})."
93 ).format(arg)
94 )
95
96 # convert_connection_parameter() is bidirectional. For a save path we
97 # want the storage shape (dict). If the input is already a dict, keep
98 # it; otherwise assume frontend list shape and convert.
99 raw_params = data.get('connection_params', [])
100 if isinstance(raw_params, dict):
101 connection_params = raw_params
102 else:
103 connection_params = convert_connection_parameter(raw_params)
104
105 if connection_params is not None:
106 if 'hostaddr' in connection_params and \
107 not is_valid_ipaddress(connection_params['hostaddr']):
108 return make_json_response(
109 success=0,
110 status=400,
111 errormsg=gettext('Not a valid Host address')
112 )
113
114 # To check ssl configuration
115 _, connection_params = check_ssl_fields(connection_params)
116 # set the connection params again in the data
117 if 'connection_params' in data:
118 data['connection_params'] = connection_params
119
120 # Fetch all the new data in case of non-existing servers
121 new_host = data.get('host', None)

Callers

nothing calls this directly

Calls 15

cloneMethod · 0.95
make_json_responseFunction · 0.90
is_valid_ipaddressFunction · 0.90
check_ssl_fieldsFunction · 0.90
get_serverFunction · 0.90
bad_requestFunction · 0.90
ServerClass · 0.90
gettextFunction · 0.85
extendMethod · 0.80
get_node_viewMethod · 0.80
firstMethod · 0.65

Tested by

no test coverage detected