Exemplo n.º 1
0
  def populate(self, json):

    self.identifier = json.get('identifier', None)
    self.title = json.get('title', None)
    self.description = json.get('description', None)
    self.version = json.get('version', '')
    self.properties.populate(json.get('properties', Properties('0')))
    obj = self.title = json.get('object', None)
    if obj:
      obj_instance = Object()
      obj_instance.populate(obj)
      self.object = obj_instance
    comp = self.title = json.get('observable_composition', None)
    if comp:
      comp_instance = ObservableComposition()
      comp_instance.populate(comp)
      self.observable_composition = comp_instance
    rel_obs = self.title = json.get('related_observables', None)
    if rel_obs:
      for rel_ob in rel_obs:
        obj_instance = RelatedObservable()
        obj_instance.populate(rel_ob)
        self.related_observables.append(obj_instance)
    modifier_group = json.get('modifier_group', None)
    if modifier_group:
      cg_instance = Group()
      cg_instance.populate(modifier_group)
      self.modifier = cg_instance
    creator_group = json.get('creator_group', None)
    if creator_group:
      cg_instance = Group()
      cg_instance.populate(creator_group)
      self.creator_group = cg_instance
    created_at = json.get('created_at', None)
    if created_at:
      self.created_at = strings.stringToDateTime(created_at)
    modified_on = json.get('modified_on', None)
    if modified_on:
      self.modified_on = strings.stringToDateTime(modified_on)
Exemplo n.º 2
0
class SearchResult(RestBase):

  def __init__(self):
    RestBase.__init__(self)
    self.event = None
    self.object = None
    self.observable = None
    self.attribute = None
    self.report = None
    self.reference = None

  def populate(self, json):
    item = json['event']
    self.event = Event()
    self.event.populate(item)
    # Check if not a report
    if json.get('report', None) or json.get('reference', None):
      item = json.get('report', None)
      if item:
        self.report = Report()
        self.report.populate(item)
      item = json.get('reference', None)
      if item:
        self.reference = Reference()
        self.reference.populate(item)
    else:
      item = json.get('observable', None)
      if item:
        self.observable = Observable()
        self.observable.populate(item)
      item = json.get('object', None)
      if item:
        self.object = Object()
        self.object.populate(item)
      item = json.get('attribute', None)
      if item:
        self.attribute = Attribute()
        self.attribute.populate(item)