@@ -286,6 +286,13 @@ def app_units(self) -> set[Unit]:
286
286
287
287
return {self .unit , * self ._peers .units }
288
288
289
+ def scoped_peer_data (self , scope : Scopes ) -> dict | None :
290
+ """Returns peer data based on scope."""
291
+ if scope == APP_SCOPE :
292
+ return self .app_peer_data
293
+ elif scope == UNIT_SCOPE :
294
+ return self .unit_peer_data
295
+
289
296
@property
290
297
def app_peer_data (self ) -> dict :
291
298
"""Application peer relation data object."""
@@ -361,7 +368,7 @@ def set_secret(self, scope: Scopes, key: str, value: str | None) -> str | None:
361
368
362
369
secret_key = self ._translate_field_to_secret_key (key )
363
370
# Old translation in databag is to be deleted
364
- self .peer_relation_data (scope ).delete_relation_data ( peers . id , [ key ] )
371
+ self .scoped_peer_data (scope ).pop ( key , None )
365
372
self .peer_relation_data (scope ).set_secret (peers .id , secret_key , value )
366
373
367
374
def remove_secret (self , scope : Scopes , key : str ) -> None :
@@ -373,10 +380,8 @@ def remove_secret(self, scope: Scopes, key: str) -> None:
373
380
return None
374
381
375
382
secret_key = self ._translate_field_to_secret_key (key )
376
- if scope == APP_SCOPE :
377
- self .peer_relation_app .delete_relation_data (peers .id , [secret_key ])
378
- else :
379
- self .peer_relation_unit .delete_relation_data (peers .id , [secret_key ])
383
+
384
+ self .peer_relation_data (scope ).delete_relation_data (peers .id , [secret_key ])
380
385
381
386
@property
382
387
def is_cluster_initialised (self ) -> bool :
0 commit comments