Example #1
0
    def register_plugin(self, name, url):
        caller_app = get_rpc_caller()
        if caller_app["app_type"] != "system":
            raise AuthenticationFailed(
                "Only system apps can register plugins.")

        return self.app_registry.register_plugin(name, url)
Example #2
0
    def register_synonym(self, synonym, target):
        caller_app = get_rpc_caller()
        channel = self.channel_registry.get_channel(target)

        if caller_app["app_url"] != channel.channel_info.owner_app.url:
            raise Unauthorized("Only creator can perform this operation.")

        return self.synonym_registry.register(synonym, target)
Example #3
0
 def unregister(self, filename):
     app_info = get_rpc_caller()
     app_id = self.url_to_app_id(app_info["app_url"])
     pseudo_id = self.get_pseudo_app_id(app_id)
     rel_path = os.path.join("apps", pseudo_id, filename.lstrip('/'))
     full_path = self.get_absolute_path(rel_path, filename)
     if os.path.isdir(full_path):
         shutil.rmtree(full_path)
     elif os.path.isfile(full_path):
         os.unlink(full_path)
Example #4
0
    def register(self, filename, content):
        decoded = base64.b64decode(content)
        app_info = get_rpc_caller()
        app_id = self.url_to_app_id(app_info["app_url"])

        pseudo_id = self.get_pseudo_app_id(app_id)
        rel_path = os.path.join("apps", pseudo_id, filename.lstrip('/'))
        full_path = self.get_absolute_path(rel_path, filename)
        self.write_file(full_path, decoded)
        return rel_path
Example #5
0
    def unregister_rpc(self, name):
        caller_app = get_rpc_caller()
        app_url = caller_app["app_url"]
        rpc_info = self.rpc_registry.pop((app_url, name))

        base_queue = rpc_info.base_queue
        self.channel_registry.remove_channel(get_rpc_request_queue(base_queue))
        self.channel_registry.remove_channel(
            get_rpc_response_queue(base_queue))
        logger.info("Unregistered RPC: %s(%s)", name, app_url)
        return True
Example #6
0
 def update_rpc(self, name, apis):
     caller_app = get_rpc_caller()
     app_url = caller_app["app_url"]
     rpc_info = self.find_rpc(app_url, name)
     request_queue = get_rpc_request_queue(rpc_info.base_queue)
     response_queue = get_rpc_response_queue(rpc_info.base_queue)
     request_schema = self.get_request_schema_from_apis(apis)
     response_schema = {}
     self.channel_registry.update_channel_schema(request_queue,
                                                 request_schema, {})
     self.channel_registry.update_channel_schema(response_queue,
                                                 response_schema, {})
     return True
Example #7
0
    def unregister_plugin(self, url):
        caller_app = get_rpc_caller()

        if caller_app.get("app_type") != "system":
            raise AuthenticationFailed("Only system apps can stop plugins.")

        self.app_registry.unregister_plugin(url)

        # Unregister all the RPC Queues.
        keys_to_remove = []
        for (app_url, name), rpc_info in self.rpc_registry.items():
            if app_url == url:
                keys_to_remove.append((app_url, name))
                self.channel_registry.remove_channel(rpc_info.request_queue)
                self.channel_registry.remove_channel(rpc_info.response_queue)

        for key in keys_to_remove:
            self.rpc_registry.pop(key)

        return True
Example #8
0
    def register_rpc(self, name, description, apis, allowed_requestors):
        caller_app = get_rpc_caller()
        app_url = caller_app["app_url"]
        base_queue = get_rpc_base_queue(app_url, name)
        request_schema = self.get_request_schema_from_apis(apis)
        response_schema = {}
        owner_app = self.app_registry.get_app_by_url(app_url)

        if (app_url, name) in self.rpc_registry:
            raise ObjectAlreadyExists(name)

        res = create_rpc_queues(base_queue, owner_app, request_schema,
                                response_schema, self.channel_registry,
                                app_url, allowed_requestors)

        rpc_info = RPCInfo(app_url, name, description, apis, base_queue,
                           request_schema, response_schema)

        # Thread safe because MAX_RPC_WORKERS == 1.
        self.rpc_registry[(app_url, name)] = rpc_info
        logger.info("Registered RPC: %s(%s)", name, app_url)
        return res
Example #9
0
    def register_queue(self,
                       queue_name,
                       queue_type,
                       schema,
                       push_whitelist,
                       pop_whitelist,
                       prefix="/channels"):
        caller_app = get_rpc_caller()
        app_url = caller_app["app_url"]
        owner_app = self.app_registry.get_app_by_url(app_url)
        channel = os.path.join(prefix, app_url, queue_name.lstrip('/'))
        channel = channel.rstrip('/')

        auth = {
            "push": get_authorizer(push_whitelist),
            "pop": get_authorizer(pop_whitelist)
        }
        self.channel_registry.create_queue(channel,
                                           owner_app,
                                           schema, {},
                                           queue_type,
                                           authorizers=auth)
        return channel
Example #10
0
 def execute_api_internal():
     return get_rpc_caller()