Skip to content

Commit 42c82d3

Browse files
author
Dmitry Ratushnyy
committed
Restore function removed on llibrary update
1 parent f755459 commit 42c82d3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/charms/mongodb/v1/helpers.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import secrets
88
import string
99
import subprocess
10-
from typing import List
10+
from typing import List, Optional, Union
1111

1212
from charms.mongodb.v0.mongodb import MongoDBConfiguration, MongoDBConnection
1313
from ops.model import (
@@ -29,7 +29,7 @@
2929

3030
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3131
# to 0 if you are raising the major API version
32-
LIBPATCH = 0
32+
LIBPATCH = 1
3333

3434
# path to store mongodb ketFile
3535
KEY_FILE = "keyFile"
@@ -267,3 +267,22 @@ def process_pbm_status(pbm_status: str) -> StatusBase:
267267
return WaitingStatus("waiting to sync s3 configurations.")
268268

269269
return ActiveStatus()
270+
271+
272+
_StrOrBytes = Union[str, bytes]
273+
274+
275+
def process_pbm_error(error_string: Optional[_StrOrBytes]) -> str:
276+
"""Parses pbm error string and returns a user friendly message."""
277+
message = "couldn't configure s3 backup option"
278+
if not error_string:
279+
return message
280+
if type(error_string) == bytes:
281+
error_string = error_string.decode("utf-8")
282+
if "status code: 403" in error_string: # type: ignore
283+
message = "s3 credentials are incorrect."
284+
elif "status code: 404" in error_string: # type: ignore
285+
message = "s3 configurations are incompatible."
286+
elif "status code: 301" in error_string: # type: ignore
287+
message = "s3 configurations are incompatible."
288+
return message

0 commit comments

Comments
 (0)