Exemplo n.º 1
0
 def export(self, resources_id: list, database: str or None,
            resource_name: str):
     where = json.dumps({'_id': {'$in': resources_id}})
     embedded = json.dumps(self.embedded)
     url = '{}/{}{}'.format(database, resource_name,
                            '?where={}&embedded={}'.format(where, embedded))
     resources = execute_get(url, self.token)['_items']
     return self.translator.translate(resources)
Exemplo n.º 2
0
 def submit(self, resource_id: str, database: str or None, resource_name: str='events'):
     """
     Submits the resource to the configured agent.
     :param resource_id: The identifier (_id) in DeviceHub of the resource.
     :param database: The database or inventory (db1...) to get the resource from.
     :param resource_name: The name of the resource.
     """
     url = '{}/{}/{}{}'.format(database, resource_name, resource_id, '?embedded={}'.format(json.dumps(self.embedded)))
     with self.app.app_context():
         resource = execute_get(url, self.token)
     super().submit(resource, database)
Exemplo n.º 3
0
 def get_device(self, device_id: str) -> dict:
     """Gets the device ready to be sent to another database."""
     # It is just so easy to load stuff (through permissions, etc) through Python-Eve's API
     embedded = json.dumps({'components': 1})
     projection = json.dumps({'events': 0})
     token = AccountDomain.hash_token(AccountDomain.actual_token)
     url = '{}/devices/{}?embedded={}&projection={}'.format(self.database, device_id, embedded, projection)
     device = execute_get(url, token)
     self.clean_device(device)
     for component in device.get('components', []):
         self.clean_device(component)
     return device
Exemplo n.º 4
0
 def get_device(self, device_id: str) -> dict:
     """Gets the device ready to be sent to another database."""
     # It is just so easy to load stuff (through permissions, etc) through Python-Eve's API
     embedded = json.dumps({'components': 1})
     projection = json.dumps({'events': 0})
     token = AccountDomain.hash_token(AccountDomain.actual_token)
     url = '{}/devices/{}?embedded={}&projection={}'.format(
         self.database, device_id, embedded, projection)
     device = execute_get(url, token)
     self.clean_device(device)
     for component in device.get('components', []):
         self.clean_device(component)
     return device
Exemplo n.º 5
0
 def submit(self,
            resource_id: str,
            database: str or None,
            resource_name: str = 'events'):
     """
     Submits the resource to the configured agent.
     :param resource_id: The identifier (_id) in DeviceHub of the resource.
     :param database: The database or inventory (db1...) to get the resource from.
     :param resource_name: The name of the resource.
     """
     url = '{}/{}/{}{}'.format(
         database, resource_name, resource_id,
         '?embedded={}'.format(json.dumps(self.embedded)))
     with self.app.app_context():
         resource = execute_get(url, self.token)
     super().submit(resource, database)
Exemplo n.º 6
0
 def export(self, resources_id: list, database: str or None, resource_name: str):
     where = json.dumps({'_id': {'$in': resources_id}})
     embedded = json.dumps(self.embedded)
     url = '{}/{}{}'.format(database, resource_name, '?where={}&embedded={}'.format(where, embedded))
     resources = execute_get(url, self.token)['_items']
     return self.translator.translate(resources)