Skip to content

Commit 19a7bfc

Browse files
authored
Merge pull request #1592 from dbcli/RW/show-ssl-version-in-status
Add SSL/TLS version to `status` output
2 parents 13c03c3 + ffaa03b commit 19a7bfc

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features
55
---------
66
* Let the `--dsn` argument accept literal DSNs as well as aliases.
77
* Accept `--character-set` as an alias for `--charset` at the CLI.
8+
* Add SSL/TLS version to `status` output.
89

910

1011
Bug Fixes

mycli/packages/special/dbcommands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mycli import __version__
99
from mycli.packages.special import iocommands
1010
from mycli.packages.special.main import ArgType, special_command
11-
from mycli.packages.special.utils import format_uptime
11+
from mycli.packages.special.utils import format_uptime, get_ssl_version
1212
from mycli.packages.sqlresult import SQLResult
1313

1414
logger = logging.getLogger(__name__)
@@ -126,6 +126,7 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
126126

127127
output.append(("Server version:", f'{variables["version"]} {variables["version_comment"]}'))
128128
output.append(("Protocol version:", variables["protocol_version"]))
129+
output.append(('SSL/TLS version:', get_ssl_version(cur)))
129130

130131
if "unix" in cur.connection.host_info.lower():
131132
host_info = cur.connection.host_info

mycli/packages/special/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import logging
12
import os
23
import subprocess
34

5+
from pymysql.cursors import Cursor
6+
7+
logger = logging.getLogger(__name__)
8+
9+
CACHED_SSL_VERSION: dict[int, str | None] = {}
10+
411

512
def handle_cd_command(arg: str) -> tuple[bool, str | None]:
613
"""Handles a `cd` shell command by calling python's os.chdir."""
@@ -46,3 +53,21 @@ def format_uptime(uptime_in_seconds: str) -> str:
4653

4754
uptime = " ".join(uptime_values)
4855
return uptime
56+
57+
58+
def get_ssl_version(cur: Cursor) -> str | None:
59+
if cur.connection.thread_id() in CACHED_SSL_VERSION:
60+
return CACHED_SSL_VERSION[cur.connection.thread_id()] or None
61+
62+
query = 'SHOW STATUS LIKE "Ssl_version"'
63+
logger.debug(query)
64+
cur.execute(query)
65+
66+
ssl_version = None
67+
if one := cur.fetchone():
68+
CACHED_SSL_VERSION[cur.connection.thread_id()] = one[1]
69+
ssl_version = one[1] or None
70+
else:
71+
CACHED_SSL_VERSION[cur.connection.thread_id()] = ''
72+
73+
return ssl_version

0 commit comments

Comments
 (0)