Esempio n. 1
0
import abc
import enum
from abc import abstractmethod
from typing import Any

from osiris.base import logutils
from osiris.base.environments import Environment

log = logutils.get_logger(__name__)


class JobRunStatus(enum.Enum):
    """
    Generic exit status return by connector to indicate the success or failure state
    """
    SUCCESS = 0
    TIMEOUT = 5
    ERROR = 6


def load_job_settings(env: Environment, name: str) -> dict:
    return env.get_section(name)


class BaseJob(abc.ABC):
    def __init__(self, name: str, env: Environment, **kwargs):
        self.name = name
        self.env = env
        self.settings = load_job_settings(env, name)

    def get_setting(self, key: str, fallback: Any) -> Any:
import base64
import json
from json import JSONDecodeError
from typing import Union

from botocore.exceptions import ClientError, NoCredentialsError

from osiris.aws import new_service_client
from osiris.base.logutils import get_logger
from osiris.exceptions import IllegalStateException, IllegalArgumentException
from osiris.vault import SecretVault

_log = get_logger(__name__)


def _try_parse_as_json(text: str) -> dict:
    try:
        return json.loads(text)
    except JSONDecodeError:
        return None


class AwsSecretManagerVault(SecretVault):
    """
    AwsSecretManagerVault - Secret Vault Manager Implementation based on below example:
    https://docs.aws.amazon.com/code-samples/latest/catalog/python-secretsmanager-secrets_manager.py.html
    """

    def __init__(self, region_name: str):
        self.client = new_service_client(service_name="secretsmanager", region_name=region_name)
import moto  # noqa

from osiris.base.logutils import get_logger

get_logger(__name__).info(
    f"Activating boto - {moto.__version__} -"
    f" A library that allows you to easily mock out tests based on AWS infrastructure."
)