TruxtonRelation

From truxwiki.com
Jump to navigation Jump to search

This class lets you add to the [Relation] table in Truxton. This is how to establish some sort of relation between items in Truxton to create a graph.

Attributes and Methods

a: str

This is the GUID of the object. This corresponds to the [A_ID] column of the [Relation] table. This combined with atype allows Truxton to retrieve the correct record from the database. This is also known as a vertex in a graph.

atype: int

The type of the thing that a represents. This corresponds to the [A_ObjectTypeID] column of the [Relation] table. It should contain a value in the [ID] column of the [ObjectType] table or you can use a defined constant.

b: str

This is the GUID of the object. This corresponds to the [B_ID] column of the [Relation] table. This combined with btype allows Truxton to retrieve the correct record from the database This is also known as a vertex in a graph.

btype: int

The type of the thing that b represents. This corresponds to the [B_ObjectTypeID] column of the [Relation] table. It should contain a value in the [ID] column of the [ObjectType] table or you can use a defined constant.

relation: int

This provides the reason why a and b are related. This corresponds to the [RelationTypeID] column of the [Relation] table. It should be a value in the [ID] column of the [RelationType] table or you can use a defined constant. It is known as an edge in a graph.

source: str

This is the GUID of the object this relation came from. This corresponds to the [SourceID] column of the [Relation] table. This combined with sourcetype allows Truxton to retrieve the correct record from the database.

sourcetype: int

The type of the thing that source represents. This corresponds to the [SourceObjectTypeID] column of the [Relation] table. It should contain a value in the [ID] column of the [ObjectType] table or you can use a defined constant.

save() -> boolean

This will commit the information to the [Relation] table. It will return True if the record was saved to the database, False if there was an error.

Remarks

When creating a relationship between objects in Truxton, the relationship should read "A is a XXX of B"

Sample

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
import shutil

from datetime import datetime
from calendar import timegm
from pathlib import Path

EPOCH_AS_FILETIME = 116444736000000000
HUNDREDS_OF_NANOSECONDS = 10000000

def date_to_filetime(dt):
  return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)

def create_event_type(t, id, name):
  event_type = t.neweventtype()
  event_type.id = id
  event_type.name = name
  event_type.save()
  return None

def add_file(parent_truxton_file, filename):
  source_file = open(filename, "rb")
  child = parent_truxton_file.newchild()
  child.name = Path(filename).name
  shutil.copyfileobj(source_file, child)
  source_file.close()
  child.save()

  return child

def add_media(t):
  media = t.newmedia()
  media.name = "Public Documents"
  media.description = "Publicly available documents"
  media.case = "DC-SNAFU-2016.2020"
  media.evidencebag = "EV-0937459386623-a"
  media.originator = "Jeffrey Jensen"
  media.latitude = 38.897661
  media.longitude = -77.036458
  media.type = truxton.MEDIA_TYPE_LOGICAL_FILES
  media.save()

  return media

def add_ec(parent_file ):
  child_file = add_file(parent_file, "JW-v-DOJ-reply-02743.pdf")

  a = child_file.newartifact()
  a.type = truxton.ENTITY_TYPE_ACCOUNT
  a.value = "r0cker"
  a.datatype = truxton.DATA_TYPE_ASCII
  a.length = 6
  a.save()

  b = child_file.newartifact()
  b.type = truxton.ENTITY_TYPE_PERSON
  b.value = "Bob Smith"
  b.datatype = truxton.DATA_TYPE_ASCII
  b.length = 9
  b.save()

  relation = child_file.newrelation()
  relation.a = a.id
  relation.atype = truxton.OBJECT_TYPE_ENTITY
  relation.b = b.id
  relation.btype = truxton.OBJECT_TYPE_ENTITY
  relation.relation = truxton.RELATION_LOGON_ACCOUNT
  relation.save()

  return None

def main():
  t = truxton.create()

  media = add_media(t)

  root_file = media.addroot()
  root_file.save()

  add_ec(root_file)

  return None

if __name__ == "__main__":
  sys.exit(main())