Skip to content

Commit 886f0ea

Browse files
committed
The vt url command now accepts URL identifiers as returned by the API.
For example ` vt url f1177df4692356280844e1d5af67cc4a9eccecf77aa61c229d483b7082c70a8e` is equivalent to `vt url https://www.virustotal.com/`. This use case was already mentioned in the examples for the command, but it was not implemented.
1 parent 80dddce commit 886f0ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cmd/url.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"encoding/base64"
1818
"github.com/VirusTotal/vt-cli/utils"
1919
"github.com/spf13/cobra"
20+
"regexp"
2021
)
2122

2223
var urlCmdHelp = `Get information about one or more URLs.
@@ -34,6 +35,10 @@ var urlCmdExample = ` vt url https://www.virustotal.com
3435
vt url f1177df4692356280844e1d5af67cc4a9eccecf77aa61c229d483b7082c70a8e
3536
cat list_of_urls | vt url -`
3637

38+
39+
// Regular expressions used for validating a URL identifier.
40+
var urlID = regexp.MustCompile(`[0-9a-fA-F]{64}`)
41+
3742
// NewURLCmd returns a new instance of the 'url' command.
3843
func NewURLCmd() *cobra.Command {
3944
cmd := &cobra.Command{
@@ -51,6 +56,14 @@ func NewURLCmd() *cobra.Command {
5156
r := utils.NewMappedStringReader(
5257
utils.StringReaderFromCmdArgs(args),
5358
func (url string) string {
59+
if urlID.MatchString(url) {
60+
// The user provided a URL identifier as returned by
61+
// VirusTotal's API, which consists in the URL's SHA-256.
62+
// In that case use the identifier as is.
63+
return url
64+
}
65+
// If the user provides an actual URL, it needs to be
66+
// encoded as base64 before being used.
5467
return base64.RawURLEncoding.EncodeToString([]byte(url))
5568
})
5669
return p.GetAndPrintObjects("urls/%s", r, nil)

0 commit comments

Comments
 (0)