-
Notifications
You must be signed in to change notification settings - Fork 4
/
audit.go
78 lines (59 loc) · 1.59 KB
/
audit.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
72
73
74
75
76
77
78
package trust
import (
"context"
"github.com/spf13/cobra"
"github.com/anchordotdev/cli"
"github.com/anchordotdev/cli/api"
"github.com/anchordotdev/cli/trust/models"
"github.com/anchordotdev/cli/truststore"
"github.com/anchordotdev/cli/ui"
)
var CmdTrustAudit = cli.NewCmd[Audit](CmdTrust, "audit", func(cmd *cobra.Command) {
cfg := cli.ConfigFromCmd(cmd)
cmd.Flags().StringVarP(&cfg.Trust.Org, "org", "o", "", "Organization to trust.")
cmd.Flags().StringVarP(&cfg.Trust.Realm, "realm", "r", "", "Realm to trust.")
cmd.Flags().StringSliceVar(&cfg.Trust.Stores, "trust-stores", []string{"homebrew", "nss", "system"}, "Trust stores to update.")
cmd.MarkFlagsRequiredTogether("org", "realm")
})
type Audit struct{}
func (a Audit) UI() cli.UI {
return cli.UI{
RunTUI: a.RunTUI,
}
}
func (c *Audit) RunTUI(ctx context.Context, drv *ui.Driver) error {
cfg := cli.ConfigFromContext(ctx)
drv.Activate(ctx, &models.TrustAuditHeader{})
drv.Activate(ctx, &models.TrustAuditScan{})
anc, err := api.NewClient(cfg)
if err != nil {
return err
}
org, realm, err := fetchOrgAndRealm(ctx, anc)
if err != nil {
return err
}
expectedCAs, err := fetchExpectedCAs(ctx, anc, org, realm)
if err != nil {
return err
}
stores, _, err := loadStores(cfg)
if err != nil {
return err
}
audit := &truststore.Audit{
Expected: expectedCAs,
Stores: stores,
SelectFn: checkAnchorCert,
}
info, err := audit.Perform()
if err != nil {
return err
}
drv.Send(models.TrustAuditScanFinishedMsg(true))
drv.Activate(ctx, &models.TrustAuditInfo{
AuditInfo: info,
Stores: stores,
})
return nil
}