Ejemplo n.º 1
0
    def get(self, key, **kwargs):
        if not isinstance(key, str):
            raise TypeError

        j.clients.zrobot.get(key, **kwargs)

        return ZeroRobotManager(key)
Ejemplo n.º 2
0
 def robots(self):
     """
     list all the ZeroRobot accessible
     return a dictionary with
     key = instance name of the 0-robot
     value: ZeroRobotManager object
     """
     robots = {}
     for instance in self._config_mgr.list():
         robots[instance] = ZeroRobotManager(instance)
     return robots
Ejemplo n.º 3
0
 def __enter__(self):
     j.clients.zrobot.get('test', {'url': 'http://localhost:6600'})
     self.cl = ZeroRobotManager('test')
     self.robot = Robot()
     self.robot.set_data_repo(j.sal.fs.getTmpDirPath())
     self.robot.add_template_repo('http://github.com/zero-os/0-robot', directory='tests/fixtures/templates')
     if os.path.exists(config.data_repo.path):
         shutil.rmtree(config.data_repo.path)
     # make sure we don't have any service loaded
     scol.drop_all()
     self.robot.start(listen='127.0.0.1:6600', block=False, testing=True, god=self.god)
     return self.cl
Ejemplo n.º 4
0
    def test_list_services_god_enable_no_token(self):
        with RobotContext(god=True) as cl:
            proxy, service = self.create_proxy(cl)

            # creates a new instance of the client without the token
            j.clients.zrobot.get('test2', {'url': 'http://localhost:6600'})
            cl2 = ZeroRobotManager('test2')

            assert len(
                cl2.services.guids
            ) == 0, "trying to list all the services without god token should not return all the existing services"
            j.clients.zrobot.delete('test2')
Ejemplo n.º 5
0
    def test_list_services_god_disable_token_valid(self):
        god_token = god_jwt.create()
        with RobotContext(god=False) as cl:
            cl._client.god_token_set(god_token)
            proxy, service = self.create_proxy(cl)

            # creates a new instance of the client with the god token
            j.clients.zrobot.get('test2', {'url': 'http://localhost:6600'})
            cl2 = ZeroRobotManager('test2')
            cl2._client.god_token_set(god_token)

            assert len(
                cl2.services.guids
            ) == 0, "trying to list all the services with god mode disabled and valid god token should not return all the existing services"
            j.clients.zrobot.delete('test2')
Ejemplo n.º 6
0
    def test_list_services_god_enable_token_valid(self):
        god_token = god_jwt.create()
        with RobotContext(god=True) as cl:
            cl._client.god_token_set(god_token)
            proxy, service = self.create_proxy(cl)

            # creates a new instance of the client with the god token
            j.clients.zrobot.get('test2', {'url': 'http://localhost:6600'})
            cl2 = ZeroRobotManager('test2')
            cl2._client.god_token_set(god_token)

            assert len(
                cl2.services.guids
            ) == 1, "trying to list all the services without god mode enabled and god token should not return all the existing services"
            service = cl2.services.find()[0]
            assert service.data is not None, "with god mode and god token any the client should be able to read the data of any service"

            j.clients.zrobot.delete('test2')
Ejemplo n.º 7
0
    def robots(self):
        """
        list all the ZeroRobot accessible
        return a dictionary with
        key = instance name of the 0-robot
        value: ZeroRobotManager object

        ZeroRobotManager is a high level client for 0-robot that present the 0-robot API with an easy interface
        see https://zero-os.github.io/0-robot/api/zerorobot/dsl/ZeroRobotManager.m.html for full API documentation
        """
        if ZeroRobotManager is None:
            raise RuntimeError(
                "zerorobot library is not installed, see 'https://github.com/zero-os/0-robot' to know how to install it"
            )
        robots = {}
        for instance in j.tools.configmanager.list(self.__jslocation__):
            robots[instance] = ZeroRobotManager(instance)
        return robots
Ejemplo n.º 8
0
def get_client():
    instance, _ = get_instance()
    return ZeroRobotManager(instance)