def from_dict(conf: Dict, type: ReplicationType, run_env: RunEnv, namespace: str = None, user: str = None) -> List["ReplicationConfig"]: """ Dict must be of format - Key (source) -> Value (destination) Args: conf: Key (repl source) -> Value (repl dest) dictionary type: required - Type of replication config (merge / app) run_env: RunEnvironment, optional namespace: Dest App Namespace, optional user: User who is creating this REPL Conf, also optional Returns: List[ReplicationConfig] - List of hydrated replication config objects based on the parameters. """ cfgs = [] for key in conf: if namespace is None: namespace = Utils.parse_namespace(conf[key]) if user is None: user = getpass.getuser() cfgs.append( ReplicationConfig(destination=conf[key], source=key, type=type, run_env=run_env, namespace=namespace, user=user)) return cfgs
import requests_unixsocket from lib.utils.utils import Utils from .errors import NoSuchContainerError, ServerErrorError u = Utils() # https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/ class Stats: def __init__(self, container_id, stream="0"): self.container_id = container_id self.stream = stream self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock" self.url = "/containers/%s/stats?stream=%s" % (self.container_id, self.stream) self.session = requests_unixsocket.Session() self.interface = None try: self.resp = self.session.get(self.base + self.url) except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) print(message) def _get_respj(self): resp = self.resp url = self.url
from lib.data.dynamo.replication_dao import ReplicationDao from lib.data.ssm.ssm import SsmDao from lib.models.replication_config import ReplicationConfig from lib.svcs.replication import ReplicationService from lib.svcs.slack import SlackService from lib.models.slack import SlackColor, FigReplicationMessage, SimpleSlackMessage from lib.config.constants import FIGGY_WEBHOOK_URL_PATH from lib.utils.utils import Utils repl_dao: ReplicationDao = ReplicationDao(boto3.resource('dynamodb')) ssm: SsmDao = SsmDao(boto3.client('ssm')) repl_svc: ReplicationService = ReplicationService(repl_dao, ssm) webhook_url = ssm.get_parameter_value(FIGGY_WEBHOOK_URL_PATH) slack: SlackService = SlackService(webhook_url=webhook_url) log = Utils.get_logger(__name__, logging.INFO) def notify_slack(config: ReplicationConfig): message = FigReplicationMessage(replication_cfg=config) slack.send_message(message) def handle(event, context): try: repl_configs: List[ReplicationConfig] = repl_dao.get_all() for config in repl_configs: time.sleep( .15 ) # This is to throttle PS API Calls to prevent overloading the API. updated = repl_svc.sync_config(config)