Exemplo n.º 1
0
    def _get_valid_config(cls, config, *fields) -> ConfigType:
        config = to_list(config)
        web_hooks = []
        for web_hook in config:
            if not web_hook.get('url'):
                logger.warning("Settings contains a non compatible web hook: `%s`", web_hook)
                continue

            url = web_hook['url']
            if not validate_url(url):
                raise PolyaxonActionException('{} received invalid URL `{}`.'.format(cls.name, url))

            method = web_hook.get('method', 'POST')
            if not isinstance(method, str):
                raise PolyaxonActionException(
                    '{} received invalid method `{}`.'.format(cls.name, method))

            _method = method.upper()
            if _method not in ['GET', 'POST']:
                raise PolyaxonActionException(
                    '{} received non compatible method `{}`.'.format(cls.name, method))

            result_web_hook = {'url': url, 'method': _method}
            for field in fields:
                if field in web_hook:
                    result_web_hook[field] = web_hook[field]
            web_hooks.append(result_web_hook)

        return web_hooks
Exemplo n.º 2
0
 def _execute(cls, data: Dict, config: List[Dict]) -> None:
     for web_hook in config:
         data = cls._pre_execute_web_hook(data=data, config=web_hook)
         try:
             if web_hook['method'] == 'POST':
                 safe_request(url=web_hook['url'], method=web_hook['method'], json=data)
             else:
                 safe_request(url=web_hook['url'], method=web_hook['method'], params=data)
         except RequestException:
             logger.warning("Could not send web hook, execption.", exc_info=True)
Exemplo n.º 3
0
    def _execute(cls, data, config):
        recipients = config.get('recipients')

        if not recipients:
            logger.warning("No emails given, skipping send.")
            return

        subject_template = data['subject_template']
        body_template = data['body_template']
        context = data['context']

        send_mass_template_mail(subject_template, body_template, recipients, context=context)
Exemplo n.º 4
0
    def _execute(self, data, config):
        recipients = [
            email for email in config.get('addresses', '').split(',') if email
        ]

        if not recipients:
            logger.warning("No emails given. Skipping send.")

        subject_template = ''
        body_template = ''

        send_template_mail(subject_template, body_template, {}, recipients)
Exemplo n.º 5
0
    def _execute(cls, data, config):
        if not all([settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD]):
            logger.debug("Email was not setup, skipping send.")
            return

        recipients = config.get('recipients')

        if not recipients:
            logger.warning("No emails given, skipping send.")
            return

        subject_template = data['subject_template']
        body_template = data['body_template']
        context = data['context']

        send_mass_template_mail(subject_template, body_template, recipients, context=context)
Exemplo n.º 6
0
    def _get_from_settings(self, settings_env_var, *fields):
        web_hooks = []
        for web_hook in settings_env_var:
            if not web_hook.get('url'):
                logger.warning(
                    "Settings contains a non compatible web hook: `%s`",
                    web_hook)
                continue

            method = web_hook.get('method', 'POST')
            if not isinstance(method, str):
                logger.warning(
                    "Settings contains a non compatible web hook method: `%s`",
                    method)
                continue

            _method = method.upper()
            if _method not in ['GET', 'POST']:
                logger.warning(
                    "Settings contains a non compatible web hook method: `%s`",
                    _method)
                continue

            result_web_hook = {'url': web_hook['url'], 'method': _method}
            for field in fields:
                result_web_hook[field] = web_hook.get(field)
            web_hooks.append(result_web_hook)

        return web_hooks