Skip to content

Commit 7d865bc

Browse files
committed
action option parse
1 parent c604187 commit 7d865bc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

actions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ get-inserted-data:
1616
get-session-ssl-cipher:
1717
description: Get ssl ciphers.
1818
params:
19-
use_ssl:
19+
use-ssl:
2020
type: string
2121
enum:
2222
- "enabled"

src/charm.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,25 @@ def _get_inserted_data(self, event: ActionEvent) -> None:
290290
event.set_results({"data": self.app_peer_data.get(RANDOM_VALUE_KEY, "empty")})
291291

292292
def _get_session_ssl_cipher(self, event: ActionEvent) -> None:
293-
"""Get the SSL cipher used by the session."""
293+
"""Get the SSL cipher used by the session.
294+
295+
This is useful to check that the connection is (un)encrypted.
296+
The action has a `use-ssl` parameter that can be used to disable SSL.
297+
"""
294298
if not self._database_config:
295-
return event.set_results({"cipher": "empty"})
299+
return event.set_results({"cipher": "noconfig"})
296300

297-
with MySQLConnector(self._database_config) as cursor:
298-
cursor.execute("SHOW SESSION STATUS LIKE 'Ssl_cipher'")
299-
cipher = cursor.fetchone()[1]
301+
config = self._database_config.copy()
302+
if event.params.get("use-ssl") == "disabled":
303+
config["ssl_disabled"] = True
304+
305+
try:
306+
with MySQLConnector(config) as cursor:
307+
cursor.execute("SHOW SESSION STATUS LIKE 'Ssl_cipher'")
308+
cipher = cursor.fetchone()[1]
309+
except Exception:
310+
logger.exception("Unable to get the SSL cipher")
311+
cipher = "error"
300312

301313
event.set_results({"cipher": cipher})
302314

0 commit comments

Comments
 (0)