def wrapper(cls): t = ff.Timer(cron=cron, environment=environment, command=cls) try: cls.set_timer(t) except AttributeError: raise error.FrameworkError('@timer used on invalid target') return cls
def on_wrapper(cls): prefix = '' if inspect.isfunction(cls): parent = function_name.match(str(cls)).groups()[0] prefix = f'/{inflection.pluralize(inflection.dasherize(inflection.underscore(parent)))}/{{id}}' endpoint = HttpEndpoint( route=prefix + route, method=method, message=generates, gateway=gateway, query_params=query_params, service=cls, secured=secured, scopes=scopes or [], tags=tags or [] ) try: cls.add_endpoint(endpoint) except AttributeError: if inspect.isfunction(cls): ff.add_endpoint(cls, endpoint) else: raise error.FrameworkError('@rest used on invalid target') return cls
def _apply_event(cls, event: Union[str, type]): try: cls.add_event(event) except AttributeError: if inspect.isfunction(cls): ff.add_event(cls, event) else: raise error.FrameworkError('@on used on invalid target')
def query_wrapper(cls): try: cls.set_query(query) except AttributeError: if inspect.isfunction(cls): ff.set_query(cls, query) else: raise error.FrameworkError('@command_handler used on invalid target') return cls
def on_wrapper(cls): try: cls.add_event(event) except AttributeError: if inspect.isfunction(cls): ff.add_event(cls, event) else: raise error.FrameworkError('@on used on invalid target') return cls
def middleware_wrapper(cls): try: cls.set_middleware_config({ 'index': index, 'buses': buses, 'cb': cb, }) except AttributeError: raise error.FrameworkError( '@middleware used on invalid target') return cls
def command_wrapper(cls): try: cls.set_command( command or f'{os.environ.get("CONTEXT")}.{cls.__name__}') except AttributeError: if inspect.isfunction(cls): ff.set_command(cls, command) else: raise error.FrameworkError( '@command_handler used on invalid target') return cls
def cli_wrapper(cls): arguments = [] if inspect.isfunction(cls): args = ff.get_arguments(cls, none_type_unions=False) else: args = ff.get_arguments(cls.__call__, none_type_unions=False) for name, arg in args.items(): arguments.append( CliArgument( name=name, type=arg['type'], default=arg['default'] if arg['default'] is not inspect.Parameter.empty else None, required=arg['default'] is inspect.Parameter.empty, help=args_help[name] if isinstance(args_help, dict) and name in args_help else None, alias=alias[name] if isinstance(alias, dict) and name in alias else None)) endpoint = CliEndpoint( app=app if app is not None else command.split(' ')[0], command=command, description=description, message=target, alias=alias, help=help_, arguments=arguments, ) try: cls.add_endpoint(endpoint) except AttributeError: if inspect.isfunction(cls): ff.add_endpoint(cls, endpoint) else: raise error.FrameworkError('@cli used on invalid target') return cls
def agent_wrapper(cls): try: cls.set_agent(name) except AttributeError: raise error.FrameworkError('@agent used on invalid target') return cls
def agent_wrapper(cls): try: cls.set_agent_extension(for_, 'add_post_deployment_hook') except AttributeError: raise error.FrameworkError('@agent used on invalid target') return cls