From 628bcce87cefe86e29199b0791b018b061e7332e Mon Sep 17 00:00:00 2001 From: Dmitry Ratushnyy Date: Fri, 29 Sep 2023 07:08:55 +0000 Subject: [PATCH] Updated lint settins to ignore libs in test files. This is a temporary change and will be removed once we will switch to different linter --- lib/charms/mongodb/v1/helpers.py | 21 ++++++++++++++++++++- pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/charms/mongodb/v1/helpers.py b/lib/charms/mongodb/v1/helpers.py index d34d5fc7f..029ae05ed 100644 --- a/lib/charms/mongodb/v1/helpers.py +++ b/lib/charms/mongodb/v1/helpers.py @@ -1,13 +1,14 @@ """Simple functions, which can be used in both K8s and VM charms.""" # Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. +from ctypes import Union import json import logging import os import secrets import string import subprocess -from typing import List +from typing import List, Optional from charms.mongodb.v0.mongodb import MongoDBConfiguration, MongoDBConnection from ops.model import ( @@ -242,6 +243,24 @@ 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) is 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) diff --git a/pyproject.toml b/pyproject.toml index ca571c914..6ac6d2d93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ profile = "black" max-line-length = 99 max-doc-length = 99 max-complexity = 10 -exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"] +exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv", "tests/integration/relation_tests/new_relations/application-charm/lib"] select = ["E", "W", "F", "C", "N", "R", "D", "H"] # Ignore W503, E501 because using black creates errors with this # Ignore D107 Missing docstring in __init__