Skip to content

Commit c604187

Browse files
committed
add get cipher to test ssl
1 parent 71ba7ab commit c604187

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

actions.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ stop-continuous-writes:
1111
description: Stop continuous writes.
1212

1313
get-inserted-data:
14-
description: Get the randomly inserted data in the database by the charm
14+
description: Get the randomly inserted data in the database by the charm.
15+
16+
get-session-ssl-cipher:
17+
description: Get ssl ciphers.
18+
params:
19+
use_ssl:
20+
type: string
21+
enum:
22+
- "enabled"
23+
- "disabled"
24+
description: Use ssl for connection
25+
default: enabled

src/charm.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,34 @@ def __init__(self, *args):
4343
self.framework.observe(self.on.start, self._on_start)
4444

4545
self.framework.observe(
46-
self.on.clear_continuous_writes_action, self._on_clear_continuous_writes_action
46+
getattr(self.on, "clear_continuous_writes_action"),
47+
self._on_clear_continuous_writes_action,
4748
)
4849
self.framework.observe(
49-
self.on.start_continuous_writes_action, self._on_start_continuous_writes_action
50+
getattr(self.on, "start_continuous_writes_action"),
51+
self._on_start_continuous_writes_action,
5052
)
5153
self.framework.observe(
52-
self.on.stop_continuous_writes_action, self._on_stop_continuous_writes_action
54+
getattr(self.on, "stop_continuous_writes_action"),
55+
self._on_stop_continuous_writes_action,
5356
)
5457

55-
self.framework.observe(self.on.get_inserted_data_action, self._get_inserted_data)
58+
self.framework.observe(
59+
getattr(self.on, "get_inserted_data_action"), self._get_inserted_data
60+
)
61+
62+
self.framework.observe(
63+
getattr(self.on, "get_session_ssl_cipher_action"), self._get_session_ssl_cipher
64+
)
5665

5766
# Database related events
5867
self.database = DatabaseRequires(self, "database", DATABASE_NAME)
59-
self.framework.observe(self.database.on.database_created, self._on_database_created)
60-
self.framework.observe(self.database.on.endpoints_changed, self._on_endpoints_changed)
68+
self.framework.observe(
69+
getattr(self.database.on, "database_created"), self._on_database_created
70+
)
71+
self.framework.observe(
72+
getattr(self.database.on, "endpoints_changed"), self._on_endpoints_changed
73+
)
6174
self.framework.observe(
6275
self.on[DATABASE_RELATION].relation_broken, self._on_relation_broken
6376
)
@@ -276,6 +289,17 @@ def _get_inserted_data(self, event: ActionEvent) -> None:
276289
"""Get random value inserted into the database."""
277290
event.set_results({"data": self.app_peer_data.get(RANDOM_VALUE_KEY, "empty")})
278291

292+
def _get_session_ssl_cipher(self, event: ActionEvent) -> None:
293+
"""Get the SSL cipher used by the session."""
294+
if not self._database_config:
295+
return event.set_results({"cipher": "empty"})
296+
297+
with MySQLConnector(self._database_config) as cursor:
298+
cursor.execute("SHOW SESSION STATUS LIKE 'Ssl_cipher'")
299+
cipher = cursor.fetchone()[1]
300+
301+
event.set_results({"cipher": cipher})
302+
279303

280304
if __name__ == "__main__":
281305
main(MySQLTestApplication)

0 commit comments

Comments
 (0)