Esempio n. 1
0
def create_update(key: str, name: str, description: str, attributes: list) -> update_pb2.Update:
    upd = update_pb2.Update()
    upd.key = key.encode("utf-8")
    dm = query_pb2.Query.DataModel()
    dm.name = name
    dm.description = description
    dm.attributes.extend(attributes)
    upd.data_models.extend([dm])
    return upd
Esempio n. 2
0
def create_update(key: str, agent: str, name: str, description: str, attributes: list) -> update_pb2.Update:
    upd = update_pb2.Update()
    upd.key = key.encode("utf-8")
    dm = query_pb2.Query.DataModel()
    dm.name = name
    dm.description = description
    dm.attributes.extend(attributes)
    dm_instance = update_pb2.Update.DataModelInstance()
    dm_instance.key = agent.encode("utf-8")
    dm_instance.model.CopyFrom(dm)
    upd.data_models.extend([dm_instance])
    return upd
Esempio n. 3
0
def create_address_attribute_update(key: str, ip: str, port: int):
    attr = update_pb2.Update.Attribute()
    key = key.encode("utf-8")
    attr.name = update_pb2.Update.Attribute.Name.Value("NETWORK_ADDRESS")
    attr.value.type = 10
    attr.value.a.ip = ip
    attr.value.a.port = port
    attr.value.a.key = key
    attr.value.a.signature = "Signed".encode("utf-8")
    upd = update_pb2.Update()
    upd.key = key
    upd.attributes.extend([attr])
    return upd
Esempio n. 4
0
 async def async_register_service(self, agent_id, service_update):
     self.error("OEF got service from agent {}".format(agent_id))
     upd = service_update
     if not isinstance(service_update, update_pb2.Update):
         upd = update_pb2.Update()
         upd.key = self._bin_id
         dm_instance = update_pb2.Update.DataModelInstance()
         dm_instance.key = agent_id.encode("UTF-8")
         if isinstance(service_update, query_pb2.Query.Instance):
             dm = service_update.model
             dm_instance.values.extend(service_update.values)
             #TODO service_update.values
         else:
             dm = query_pb2.Query.DataModel()
             dm.ParseFromString(service_update)
         dm_instance.model.CopyFrom(dm)
         upd.data_models.extend([dm_instance])
     self.service_directory[agent_id] = service_update
     await self.search_com.call_node("update", upd)
Esempio n. 5
0
from fetch_teams.oef_core_protocol import query_pb2
from api.src.proto.core import update_pb2

dm = query_pb2.Query.DataModel()
dm.name = "hh"
dm.description = "ewrwer"

print(dm)

dm_serialized = dm.SerializeToString()
print("serialized dm: ", dm_serialized)

try:
    upd = update_pb2.Update()
    upd.ParseFromString(dm_serialized)
    print("Update: ", upd)
except Exception as e:
    print("Failed, because: ", e)
def toUpdate(msg: remove_pb2.Remove) -> update_pb2.Update:
    upd = update_pb2.Update()
    upd.key = msg.key
    upd.attributes.extend(msg.attributes)
    upd.data_models.extend(msg.data_models)
    return upd