2016-08-29 01:22:50 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2024-01-01 02:43:48 -06:00
|
|
|
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2016-08-29 01:22:50 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
from werkzeug.exceptions import HTTPException
|
|
|
|
from werkzeug.http import HTTP_STATUS_CODES
|
2021-11-24 05:52:57 -06:00
|
|
|
from flask_babel import gettext as _
|
2016-08-29 01:22:50 -05:00
|
|
|
from flask import request
|
|
|
|
|
2020-08-05 02:11:28 -05:00
|
|
|
from pgadmin.utils.ajax import service_unavailable, gone, internal_server_error
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2020-09-29 04:38:14 -05:00
|
|
|
SERVICE_UNAVAILABLE = 'Service Unavailable'
|
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
|
|
|
|
class ConnectionLost(HTTPException):
|
|
|
|
"""
|
|
|
|
Exception
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, _server_id, _database_name, _conn_id):
|
|
|
|
self.sid = _server_id
|
|
|
|
self.db = _database_name
|
|
|
|
self.conn_id = _conn_id
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-09-29 04:38:14 -05:00
|
|
|
return HTTP_STATUS_CODES.get(503, SERVICE_UNAVAILABLE)
|
2016-08-29 01:22:50 -05:00
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return service_unavailable(
|
2017-11-01 10:18:07 -05:00
|
|
|
_("Connection to the server has been lost."),
|
2016-08-29 01:22:50 -05:00
|
|
|
info="CONNECTION_LOST",
|
|
|
|
data={
|
|
|
|
'sid': self.sid,
|
|
|
|
'database': self.db,
|
|
|
|
'conn_id': self.conn_id
|
|
|
|
}
|
|
|
|
)
|
2017-07-07 01:25:55 -05:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Connection (id #{2}) lost for the server (#{0}) on " \
|
|
|
|
"database ({1})".format(self.sid, self.db, self.conn_id)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Connection (id #{2}) lost for the server (#{0}) on " \
|
|
|
|
"database ({1})".format(self.sid, self.db, self.conn_id)
|
2018-05-04 05:27:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
class SSHTunnelConnectionLost(HTTPException):
|
|
|
|
"""
|
|
|
|
Exception when connection to SSH tunnel is lost
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, _tunnel_host):
|
|
|
|
self.tunnel_host = _tunnel_host
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-09-29 04:38:14 -05:00
|
|
|
return HTTP_STATUS_CODES.get(503, SERVICE_UNAVAILABLE)
|
2018-05-04 05:27:27 -05:00
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return service_unavailable(
|
|
|
|
_("Connection to the SSH Tunnel for host '{0}' has been lost. "
|
|
|
|
"Reconnect to the database server.").format(self.tunnel_host),
|
|
|
|
info="SSH_TUNNEL_CONNECTION_LOST",
|
|
|
|
data={
|
|
|
|
'tunnel_host': self.tunnel_host
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Connection to the SSH Tunnel for host '{0}' has been lost. " \
|
|
|
|
"Reconnect to the database server".format(self.tunnel_host)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Connection to the SSH Tunnel for host '{0}' has been lost. " \
|
|
|
|
"Reconnect to the database server".format(self.tunnel_host)
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
class CryptKeyMissing(HTTPException):
|
|
|
|
"""
|
|
|
|
Exception
|
|
|
|
"""
|
2020-09-29 04:38:14 -05:00
|
|
|
CRYPT_KEY_MISSING = "Crypt key is missing."
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-09-29 04:38:14 -05:00
|
|
|
return HTTP_STATUS_CODES.get(503, SERVICE_UNAVAILABLE)
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return service_unavailable(
|
2020-09-29 04:38:14 -05:00
|
|
|
_(self.CRYPT_KEY_MISSING),
|
2019-05-28 01:30:18 -05:00
|
|
|
info="CRYPTKEY_MISSING",
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-09-29 04:38:14 -05:00
|
|
|
return self.CRYPT_KEY_MISSING
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
def __repr__(self):
|
2020-09-29 04:38:14 -05:00
|
|
|
return self.CRYPT_KEY_MISSING
|
2019-11-15 03:15:55 -06:00
|
|
|
|
|
|
|
|
|
|
|
class ObjectGone(HTTPException):
|
|
|
|
"""
|
|
|
|
Exception
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, error_msg):
|
|
|
|
self.error_msg = error_msg
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return HTTP_STATUS_CODES.get(410, 'Gone')
|
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return gone(self.error_msg)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.error_msg
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return self.error_msg
|
2020-08-05 02:11:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ExecuteError(HTTPException):
|
|
|
|
"""
|
|
|
|
ExecuteError
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, error_msg):
|
|
|
|
self.error_msg = error_msg
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return HTTP_STATUS_CODES.get(500, 'Internal server error')
|
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return internal_server_error(self.error_msg)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.error_msg
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return self.error_msg
|