@@ -17,11 +17,12 @@ import (
1717 "encoding/base64"
1818 "encoding/gob"
1919 "fmt"
20- "github.com/VirusTotal/vt-cli/utils"
2120 "os"
2221 "path"
2322 "sync"
2423
24+ "github.com/VirusTotal/vt-cli/utils"
25+
2526 vt "github.com/VirusTotal/vt-go"
2627 homedir "github.com/mitchellh/go-homedir"
2728 "github.com/spf13/cobra"
@@ -69,7 +70,7 @@ func getRelatedObjects(collection, objectID, relationship string, limit int) ([]
6970}
7071
7172// NewRelationshipCmd returns a new instance of the 'relationship' command.
72- func NewRelationshipCmd (collection , relationship , use , description string ) * cobra.Command {
73+ func NewRelationshipCmd (collection , relationship , use , description string , private_flag bool ) * cobra.Command {
7374 cmd := & cobra.Command {
7475 Args : cobra .ExactArgs (1 ),
7576 Use : fmt .Sprintf ("%s %s" , relationship , use ),
@@ -85,6 +86,9 @@ func NewRelationshipCmd(collection, relationship, use, description string) *cobr
8586 if err != nil {
8687 return err
8788 }
89+ if viper .GetBool ("private" ) {
90+ collection = "private/" + collection
91+ }
8892 url := vt .URL ("%s/%s/%s" , collection , objectID , relationship )
8993 return p .PrintCollection (url )
9094 },
@@ -95,18 +99,26 @@ func NewRelationshipCmd(collection, relationship, use, description string) *cobr
9599 addLimitFlag (cmd .Flags ())
96100 addCursorFlag (cmd .Flags ())
97101
102+ if private_flag {
103+ addPrivateFlag (cmd .Flags ())
104+ }
105+
98106 return cmd
99107}
100108
101109// NewRelationshipsCmd returns a new instance of the 'relationships' command.
102- func NewRelationshipsCmd (collection , objectType , use string ) * cobra.Command {
110+ func NewRelationshipsCmd (collection , objectType , use string , private_flag bool ) * cobra.Command {
103111 cmd := & cobra.Command {
104112 Use : fmt .Sprintf ("relationships %s" , use ),
105113 Short : "Get all relationships." ,
106114 Args : cobra .ExactArgs (1 ),
107115 RunE : func (cmd * cobra.Command , args []string ) error {
108116 var wg sync.WaitGroup
109117 var sm sync.Map
118+ if viper .GetBool ("private" ) {
119+ objectType = "private_" + objectType
120+ collection = "private/" + collection
121+ }
110122 for _ , r := range objectRelationshipsMap [objectType ] {
111123 wg .Add (1 )
112124 go func (relationshipName string ) {
@@ -148,13 +160,17 @@ func NewRelationshipsCmd(collection, objectType, use string) *cobra.Command {
148160 addIncludeExcludeFlags (cmd .Flags ())
149161 addLimitFlag (cmd .Flags ())
150162
163+ if private_flag {
164+ addPrivateFlag (cmd .Flags ())
165+ }
166+
151167 return cmd
152168}
153169
154- func addRelationshipCmds (cmd * cobra.Command , collection , objectType , use string ) {
170+ func addRelationshipCmds (cmd * cobra.Command , collection , objectType , use string , private_flag bool ) {
155171 relationships := objectRelationshipsMap [objectType ]
156172 for _ , r := range relationships {
157- cmd .AddCommand (NewRelationshipCmd (collection , r .Name , use , r .Description ))
173+ cmd .AddCommand (NewRelationshipCmd (collection , r .Name , use , r .Description , private_flag ))
158174 }
159- cmd .AddCommand (NewRelationshipsCmd (collection , objectType , use ))
175+ cmd .AddCommand (NewRelationshipsCmd (collection , objectType , use , private_flag ))
160176}
0 commit comments