Пример #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
Пример #2
0
    def _prepare(cls, context: Dict) -> Dict:
        """This is where you should alter the context to fit the action.

        Default behaviour will leave the context as it is.
        """
        if not context and cls.raise_empty_context:
            raise PolyaxonActionException(
                '{} received invalid payload context.'.format(cls.name))

        return context
Пример #3
0
    def _prepare(cls, context):
        context = super()._prepare(context)

        payload = {
            'username': context.get('username', 'Polyaxon'),
            'avatar_url': context.get('avatar_url'),
            'tts': context.get('tts', False)
        }
        content = context.get('content')
        if content and len(content) <= 2000:
            payload['content'] = content
        else:
            raise PolyaxonActionException(
                'Discord content must non null and 2000 or fewer characters.')

        proxy = context.get('proxy')
        if proxy:
            payload['https'] = proxy
        return payload