-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_scans.go
71 lines (56 loc) · 1.88 KB
/
list_scans.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package antivirus
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/ironstar-io/ironstar-cli/cmd/flags"
"github.com/ironstar-io/ironstar-cli/internal/api"
"github.com/ironstar-io/ironstar-cli/internal/errs"
"github.com/ironstar-io/ironstar-cli/internal/services"
"github.com/ironstar-io/ironstar-cli/internal/system/utils"
"github.com/olekukonko/tablewriter"
)
func ListScans(args []string, flg flags.Accumulator) error {
creds, err := services.ResolveUserCredentials(flg.Login)
if err != nil {
return err
}
seCtx, err := api.GetSubscriptionEnvironmentContext(creds, flg)
if err != nil {
return err
}
if seCtx.Subscription.Alias == "" {
return errs.ErrNoSubLink
}
utils.PrintCommandContext(flg.Output, creds.Login, seCtx.Subscription.Alias, seCtx.Subscription.HashedID)
avs, err := api.GetEnvironmentAntivirusScans(creds, flg.Output, seCtx.Subscription.HashedID, seCtx.Environment.HashedID)
if err != nil {
return err
}
if strings.ToLower(flg.Output) == "json" {
utils.PrintInterfaceAsJSON(avs)
return nil
}
if len(avs) == 0 {
fmt.Println()
fmt.Println("No antivirus scans found for this environment")
return nil
}
fmt.Println()
fmt.Println("Recent antivirus scans for environment [" + seCtx.Environment.Name + "]:")
antivirusScanRows := make([][]string, len(avs))
for _, av := range avs {
// Prepend rows, we want dates ordered oldest to newest
row := make([][]string, 1)
row = append(row, []string{av.Result, strconv.Itoa(av.ScannedFiles), strconv.Itoa(av.InfectedFiles), strconv.Itoa(av.Duration), av.CreatedAt.Format(time.RFC3339)})
antivirusScanRows = append(row, antivirusScanRows...)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Result", "Scanned Files", "Infected Files", "Duration", "Created"})
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.AppendBulk(antivirusScanRows)
table.Render()
return nil
}