Skip to content

Commit

Permalink
add ability to backups be removed after a number of days
Browse files Browse the repository at this point in the history
  • Loading branch information
delgod committed May 15, 2024
1 parent 8b43bac commit a7ed5fe
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/charms/data_platform_libs/v0/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _on_credential_gone(self, event: CredentialsGoneEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 4
LIBPATCH = 5

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -481,6 +481,18 @@ def set_s3_api_version(self, relation_id: int, s3_api_version: str) -> None:
"""
self.update_connection_info(relation_id, {"s3-api-version": s3_api_version})

def set_delete_older_than_days(self, relation_id: int, days: int) -> None:
"""Sets the retention days for full backups in application databag.
This function writes in the application data bag, therefore,
only the leader unit can call it.
Args:
relation_id: the identifier for a particular relation.
days: the value.
"""
self.update_connection_info(relation_id, {"delete-older-than-days": str(days)})

def set_attributes(self, relation_id: int, attributes: List[str]) -> None:
"""Sets the connection attributes in application databag.
Expand Down Expand Up @@ -580,6 +592,17 @@ def s3_api_version(self) -> Optional[str]:

return self.relation.data[self.relation.app].get("s3-api-version")

@property
def delete_older_than_days(self) -> Optional[int]:
"""Returns the retention days for full backups."""
if (
not self.relation.app
or self.relation.data[self.relation.app].get("delete-older-than-days") is None
):
return None

return int(self.relation.data[self.relation.app].get("delete-older-than-days"))

@property
def attributes(self) -> Optional[List[str]]:
"""Returns the attributes."""
Expand Down

0 comments on commit a7ed5fe

Please sign in to comment.