Ejemplo n.º 1
0
    def from_info(info):
        try:
            api = API(info["name"], info["description"], [])
        except KeyError:
            raise BadArguments("Invalid API info object.")

        api.args = [ArgParameter.from_info(x) for x in info.get("args", [])]
        api.kwargs = [KeywordParameter.from_info(x) for x in
                      info.get("kwargs", {}).values()]

        return api
Ejemplo n.º 2
0
    def validate_call(self, *args, **kwargs):
        obj = {"command": self.name, "id": "invocation-" + str(uuid4())}
        if args:
            obj["args"] = list(args)
        if kwargs:
            obj["kwargs"] = kwargs

        try:
            validate(obj, self.schema)
        except ValidationError:
            raise BadArguments("Bad parameters for function call.")

        return obj
Ejemplo n.º 3
0
def from_type(pytype):
    types = {
        bool: "boolean",
        int: "number",
        float: "number",
        str: "string",
        dict: "object",
        list: "array",
    }

    if pytype not in types:
        raise BadArguments("Unsupported type.")

    return types[pytype]
Ejemplo n.º 4
0
    def __init__(self,
                 name,
                 description,
                 apis,
                 service,
                 allowed_requestors=None):
        if not isinstance(service, MessagingEnabled):
            raise BadArguments("Service is not messaging enabled.")

        super(RPCServer, self).__init__(name, description, apis)
        self.service = service
        self.executor = ThreadPoolExecutor(self.MAX_RPC_WORKERS)
        self.sender = None
        self.receiver = None
        self.receiver_thread = None
        self.cookie = None
        self.appmgr_client = None
        self.allowed_requestors = allowed_requestors or []
Ejemplo n.º 5
0
 def __init__(self,
              queue_name,
              owner_app,
              request_schema,
              response_schema,
              queue_type,
              authorizers=None):
     super().__init__(queue_name,
                      owner_app,
                      request_schema,
                      response_schema,
                      authorizers=authorizers)
     channel_map = {
         "fifo": RoundRobinQueue,
         "sessionized": SessionizedQueue,
         "multicast": Multicast
     }
     self.queue_cls = channel_map.get(queue_type)
     if not self.queue_cls:
         raise BadArguments(queue_type)
Ejemplo n.º 6
0
def get_required_argument(obj, key):
    try:
        return obj[key]
    except KeyError:
        raise BadArguments(key)
Ejemplo n.º 7
0
 def get_absolute_path(self, rel_path, filename):
     full_path = os.path.join(self.base_dir, rel_path)
     norm_path = os.path.normpath(full_path)
     if norm_path.startswith(self.base_dir):
         return norm_path
     raise BadArguments(filename)
Ejemplo n.º 8
0
 def __init__(self, pytype):
     if pytype not in (bool, int, float, str):
         raise BadArguments("Unsupported type.")
     self.json_type = from_type(pytype)
Ejemplo n.º 9
0
 def from_info(info):
     try:
         return KeywordParameter(info["name"], info["description"],
                                 info["schema"])
     except KeyError:
         raise BadArguments("Invalid KeywordParameter info object.")