MCPcopy Create free account
hub / github.com/VirusTotal/vt-cli / ObjectToMap

Function ObjectToMap

utils/printer.go:93–127  ·  view source on GitHub ↗

ObjectToMap function that returns the attributes for an object as a map. Keys are attribute names and values are the attribute's value. Two special keys _id and _type are also included in the map with object's identifier and type respectively. The map is filtered according to the filters specified i

(obj *vt.Object)

Source from the content-addressed store, hash-verified

91// and type respectively. The map is filtered according to the filters specified
92// in the --include and --exclude command-line arguments.
93func ObjectToMap(obj *vt.Object) map[string]interface{} {
94 m := make(map[string]interface{})
95 m["_id"] = obj.ID()
96 m["_type"] = obj.Type()
97
98 contextAttributes := make(map[string]interface{})
99 for _, attr := range obj.ContextAttributes() {
100 contextAttributes[attr], _ = obj.GetContext(attr)
101 }
102 if len(contextAttributes) > 0 {
103 m["_context_attributes"] = contextAttributes
104 }
105
106 for _, attr := range obj.Attributes() {
107 m[attr], _ = obj.Get(attr)
108 }
109 for _, name := range obj.Relationships() {
110 r, _ := obj.GetRelationship(name)
111 relatedObjs := r.Objects()
112 if r.IsOneToOne() {
113 if len(relatedObjs) > 0 {
114 m[name] = relatedObjs[0].ID()
115 } else {
116 m[name] = nil
117 }
118 } else {
119 l := make([]string, 0)
120 for _, obj := range relatedObjs {
121 l = append(l, obj.ID())
122 }
123 m[name] = l
124 }
125 }
126 return m
127}
128
129// PrintObjects prints all the specified objects to stdout.
130func (p *Printer) PrintObjects(objs []*vt.Object) error {

Callers 2

getRelatedObjectsFunction · 0.92
PrintObjectsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected