@@ -99,6 +99,7 @@ def wait_until_mysql_connection(self) -> None:
99
99
PEER ,
100
100
ROOT_PASSWORD_KEY ,
101
101
ROOT_USERNAME ,
102
+ SECRET_KEY_FALLBACKS ,
102
103
SERVER_CONFIG_PASSWORD_KEY ,
103
104
SERVER_CONFIG_USERNAME ,
104
105
)
@@ -114,7 +115,7 @@ def wait_until_mysql_connection(self) -> None:
114
115
115
116
# Increment this PATCH version before using `charmcraft publish-lib` or reset
116
117
# to 0 if you are raising the major API version
117
- LIBPATCH = 56
118
+ LIBPATCH = 57
118
119
119
120
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
120
121
UNIT_ADD_LOCKNAME = "unit-add"
@@ -411,8 +412,8 @@ def __init__(self, *args):
411
412
additional_secret_fields = [
412
413
"key" ,
413
414
"csr" ,
414
- "cert " ,
415
- "cauth " ,
415
+ "certificate " ,
416
+ "certificate-authority " ,
416
417
"chain" ,
417
418
],
418
419
secret_field_name = SECRET_INTERNAL_LABEL ,
@@ -580,6 +581,13 @@ def has_cos_relation(self) -> bool:
580
581
581
582
return len (active_cos_relations ) > 0
582
583
584
+ def peer_relation_data (self , scope : Scopes ) -> DataPeer :
585
+ """Returns the peer relation data per scope."""
586
+ if scope == APP_SCOPE :
587
+ return self .peer_relation_app
588
+ elif scope == UNIT_SCOPE :
589
+ return self .peer_relation_unit
590
+
583
591
def get_secret (
584
592
self ,
585
593
scope : Scopes ,
@@ -591,11 +599,15 @@ def get_secret(
591
599
Else retrieve from peer databag. This is to account for cases where secrets are stored in
592
600
peer databag but the charm is then refreshed to a newer revision.
593
601
"""
602
+ if scope not in get_args (Scopes ):
603
+ raise ValueError ("Unknown secret scope" )
604
+
594
605
peers = self .model .get_relation (PEER )
595
- if scope == APP_SCOPE :
596
- value = self .peer_relation_app .fetch_my_relation_field (peers .id , key )
597
- else :
598
- value = self .peer_relation_unit .fetch_my_relation_field (peers .id , key )
606
+ if not (value := self .peer_relation_data (scope ).fetch_my_relation_field (peers .id , key )):
607
+ if key in SECRET_KEY_FALLBACKS :
608
+ value = self .peer_relation_data (scope ).fetch_my_relation_field (
609
+ peers .id , SECRET_KEY_FALLBACKS [key ]
610
+ )
599
611
return value
600
612
601
613
def set_secret (self , scope : Scopes , key : str , value : Optional [str ]) -> None :
@@ -607,24 +619,30 @@ def set_secret(self, scope: Scopes, key: str, value: Optional[str]) -> None:
607
619
raise MySQLSecretError ("Can only set app secrets on the leader unit" )
608
620
609
621
if not value :
610
- return self .remove_secret (scope , key )
622
+ if key in SECRET_KEY_FALLBACKS :
623
+ self .remove_secret (scope , SECRET_KEY_FALLBACKS [key ])
624
+ self .remove_secret (scope , key )
625
+ return
611
626
612
627
peers = self .model .get_relation (PEER )
613
- if scope == APP_SCOPE :
614
- self .peer_relation_app .update_relation_data (peers .id , {key : value })
615
- elif scope == UNIT_SCOPE :
616
- self .peer_relation_unit .update_relation_data (peers .id , {key : value })
628
+
629
+ fallback_key_to_secret_key = {v : k for k , v in SECRET_KEY_FALLBACKS .items ()}
630
+ if key in fallback_key_to_secret_key :
631
+ if self .peer_relation_data (scope ).fetch_my_relation_field (peers .id , key ):
632
+ self .remove_secret (scope , key )
633
+ self .peer_relation_data (scope ).update_relation_data (
634
+ peers .id , {fallback_key_to_secret_key [key ]: value }
635
+ )
636
+ else :
637
+ self .peer_relation_data (scope ).update_relation_data (peers .id , {key : value })
617
638
618
639
def remove_secret (self , scope : Scopes , key : str ) -> None :
619
640
"""Removing a secret."""
620
641
if scope not in get_args (Scopes ):
621
642
raise RuntimeError ("Unknown secret scope." )
622
643
623
644
peers = self .model .get_relation (PEER )
624
- if scope == APP_SCOPE :
625
- self .peer_relation_app .delete_relation_data (peers .id , [key ])
626
- else :
627
- self .peer_relation_unit .delete_relation_data (peers .id , [key ])
645
+ self .peer_relation_data (scope ).delete_relation_data (peers .id , [key ])
628
646
629
647
630
648
class MySQLMemberState (str , enum .Enum ):
@@ -2617,3 +2635,8 @@ def _run_mysqlcli_script(
2617
2635
timeout: (optional) time before the query should timeout
2618
2636
"""
2619
2637
raise NotImplementedError
2638
+
2639
+ @abstractmethod
2640
+ def reset_data_dir (self ) -> None :
2641
+ """Reset the data directory."""
2642
+ raise NotImplementedError
0 commit comments