Ejemplo 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
Ejemplo 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)
Ejemplo n.º 3
0
    def _execute(cls, data: Dict, config: Dict) -> None:
        if not all([conf.get(EMAIL_HOST_USER), conf.get(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)