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

Function getRelatedObjects

cmd/relationship.go:57–83  ·  view source on GitHub ↗
(collection, objectID, relationship string, limit int)

Source from the content-addressed store, hash-verified

55}
56
57func getRelatedObjects(collection, objectID, relationship string, limit int) ([]map[string]interface{}, error) {
58 if collection == "urls" {
59 // If collections is "urls" the objectID is the URL itself and
60 // it needs to be encoded in base64.
61 objectID = base64.RawURLEncoding.EncodeToString([]byte(objectID))
62 }
63 client, err := NewAPIClient()
64 if err != nil {
65 return nil, err
66 }
67 it, err := client.Iterator(
68 vt.URL("%s/%s/%s", collection, objectID, relationship),
69 vt.IteratorLimit(limit))
70 if err != nil {
71 return nil, err
72 }
73 defer it.Close()
74 result := make([]map[string]interface{}, 0)
75 for it.Next() {
76 obj := it.Get()
77 result = append(result, utils.ObjectToMap(obj))
78 }
79 if err := it.Error(); err != nil {
80 return nil, err
81 }
82 return result, nil
83}
84
85// NewRelationshipCmd returns a new instance of the 'relationship' command.
86func NewRelationshipCmd(collection, relationship, use, description string, private_flag bool) *cobra.Command {

Callers 1

NewRelationshipsCmdFunction · 0.85

Calls 2

ObjectToMapFunction · 0.92
NewAPIClientFunction · 0.70

Tested by

no test coverage detected