Compare commits
5 commits
master
...
feature/ss
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e37e41d82 | ||
|
|
0effe7f3c8 | ||
|
|
02f412a42e | ||
|
|
9db02c154b | ||
|
|
c9f81f1c07 |
7 changed files with 37 additions and 15 deletions
10
CHANGELOG.MD
10
CHANGELOG.MD
|
|
@ -1,5 +1,15 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Users can now specify a password for the SSH key used in the SSH tunnel. This is done by entering the password in
|
||||||
|
the config file, under the entry `connection_details > ssh_tunneling > ssh_private_key_password`.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- The `ssh_tunneling` section of the config file is now optional and the application will work even if the config
|
||||||
|
file does not contain it.
|
||||||
|
|
||||||
## [0.2.0] - 2022-07-26
|
## [0.2.0] - 2022-07-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = "0.2.0"
|
__version__ = "latest"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@
|
||||||
"port": 3306,
|
"port": 3306,
|
||||||
"user": "your_user",
|
"user": "your_user",
|
||||||
"password": "your_password",
|
"password": "your_password",
|
||||||
"schema": "comprea",
|
"schema": "comprea"
|
||||||
"ssh_tunneling": {
|
|
||||||
"use_tunnel": false
|
|
||||||
},
|
},
|
||||||
"queries_to_measure": [
|
"queries_to_measure": [
|
||||||
{
|
{
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
"ssh_host": "the_ssh_tunnel_host",
|
"ssh_host": "the_ssh_tunnel_host",
|
||||||
"ssh_username": "the_ssh_tunnel_user",
|
"ssh_username": "the_ssh_tunnel_user",
|
||||||
"ssh_port": 22,
|
"ssh_port": 22,
|
||||||
"path_to_key": "G:\\path\\to\\ssh\\key.pem"
|
"path_to_key": "G:\\path\\to\\ssh\\key.pem",
|
||||||
|
"ssh_private_key_password": "my_keys_password"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"queries_to_measure": [
|
"queries_to_measure": [
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@
|
||||||
"password": "your_password",
|
"password": "your_password",
|
||||||
"http_scheme": "https",
|
"http_scheme": "https",
|
||||||
"catalog": "app_lm_mysql",
|
"catalog": "app_lm_mysql",
|
||||||
"schema": "comprea",
|
"schema": "comprea"
|
||||||
"ssh_tunneling": {
|
|
||||||
"use_tunnel": false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"queries_to_measure": [
|
"queries_to_measure": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,22 @@ def singleton(class_):
|
||||||
@singleton
|
@singleton
|
||||||
class MySSHTunnel:
|
class MySSHTunnel:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, ssh_host, ssh_port, ssh_username, ssh_pkey, remote_host, remote_port
|
self,
|
||||||
|
ssh_host,
|
||||||
|
ssh_port,
|
||||||
|
ssh_username,
|
||||||
|
ssh_pkey,
|
||||||
|
remote_host,
|
||||||
|
remote_port,
|
||||||
|
ssh_private_key_password=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
self.tunnel = SSHTunnelForwarder(
|
self.tunnel = SSHTunnelForwarder(
|
||||||
ssh_host=(ssh_host, ssh_port),
|
ssh_host=(ssh_host, ssh_port),
|
||||||
ssh_username=ssh_username,
|
ssh_username=ssh_username,
|
||||||
ssh_pkey=ssh_pkey,
|
ssh_pkey=ssh_pkey,
|
||||||
remote_bind_address=(remote_host, remote_port),
|
remote_bind_address=(remote_host, remote_port),
|
||||||
local_bind_address=("127.0.0.1", remote_port),
|
local_bind_address=("127.0.0.1", remote_port),
|
||||||
|
ssh_private_key_password=ssh_private_key_password,
|
||||||
)
|
)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
@ -115,12 +122,13 @@ def get_connection_to_mysql(
|
||||||
:param connection_config: specifies host, port, etc.
|
:param connection_config: specifies host, port, etc.
|
||||||
:return: the connection object
|
:return: the connection object
|
||||||
"""
|
"""
|
||||||
if connection_config["ssh_tunneling"]["use_tunnel"]:
|
mysql_connection_host = connection_config["host"]
|
||||||
|
|
||||||
|
if connection_config.get("ssh_tunneling", {}).get("use_tunnel", None):
|
||||||
open_ssh_tunnel(connection_config)
|
open_ssh_tunnel(connection_config)
|
||||||
mysql_connection_host = "127.0.0.1"
|
mysql_connection_host = "127.0.0.1"
|
||||||
|
# If we open an SSH tunnel, we reference the local bind instead of the
|
||||||
if not connection_config["ssh_tunneling"]["use_tunnel"]:
|
# actual host
|
||||||
mysql_connection_host = connection_config["host"]
|
|
||||||
|
|
||||||
connection = mysql.connector.connect(
|
connection = mysql.connector.connect(
|
||||||
host=mysql_connection_host,
|
host=mysql_connection_host,
|
||||||
|
|
@ -162,6 +170,10 @@ def open_ssh_tunnel(connection_config: dict) -> None:
|
||||||
ssh_pkey=connection_config["ssh_tunneling"]["path_to_key"],
|
ssh_pkey=connection_config["ssh_tunneling"]["path_to_key"],
|
||||||
remote_host=connection_config["host"],
|
remote_host=connection_config["host"],
|
||||||
remote_port=connection_config["port"],
|
remote_port=connection_config["port"],
|
||||||
|
ssh_private_key_password=connection_config["ssh_tunneling"].get(
|
||||||
|
"ssh_private_key_password",
|
||||||
|
None, # Since password is optional, we need a safe default
|
||||||
|
),
|
||||||
).start()
|
).start()
|
||||||
print("SSH tunnel is now open.")
|
print("SSH tunnel is now open.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ A few notes:
|
||||||
- I advice you to make the first query a silly, fast query such as `SELECT 1` to validate your connection and
|
- I advice you to make the first query a silly, fast query such as `SELECT 1` to validate your connection and
|
||||||
quickly confirm that everything is set up properly.
|
quickly confirm that everything is set up properly.
|
||||||
|
|
||||||
|
## Other features
|
||||||
|
- The connection to the database can be made through an SSH tunnel. See the examples in `config_examples` to
|
||||||
|
understand how to configure it.
|
||||||
|
|
||||||
## A few more details
|
## A few more details
|
||||||
|
|
||||||
- Queries are run sequentially, as in the second query will only start after the first query is finished.
|
- Queries are run sequentially, as in the second query will only start after the first query is finished.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue