Skip to content

Commit

Permalink
Update helpers lib: add function for k8s charm
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ratushnyy committed Jan 18, 2024
1 parent f92c12f commit 44cd80a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/charms/mongodb/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import secrets
import string
import subprocess
from typing import List
from typing import List, Optional, Union

from charms.mongodb.v0.mongodb import MongoDBConfiguration, MongoDBConnection
from ops.model import (
Expand All @@ -29,7 +29,7 @@

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

# path to store mongodb ketFile
KEY_FILE = "keyFile"
Expand Down Expand Up @@ -260,6 +260,25 @@ def copy_licenses_to_unit():
)


_StrOrBytes = Union[str, bytes]


def process_pbm_error(error_string: Optional[_StrOrBytes]) -> str:
"""Parses pbm error string and returns a user friendly message."""
message = "couldn't configure s3 backup option"
if not error_string:
return message
if type(error_string) == bytes:
error_string = error_string.decode("utf-8")
if "status code: 403" in error_string: # type: ignore
message = "s3 credentials are incorrect."
elif "status code: 404" in error_string: # type: ignore
message = "s3 configurations are incompatible."
elif "status code: 301" in error_string: # type: ignore
message = "s3 configurations are incompatible."
return message


def current_pbm_op(pbm_status: str) -> str:
"""Parses pbm status for the operation that pbm is running."""
pbm_status = json.loads(pbm_status)
Expand Down

0 comments on commit 44cd80a

Please sign in to comment.