-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit.go
More file actions
64 lines (61 loc) · 1.75 KB
/
Copy pathaudit.go
File metadata and controls
64 lines (61 loc) · 1.75 KB
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
package commands
import (
"context"
"errors"
"github.com/loilo-inc/canarycage/v6/cli/cage/cageapp"
"github.com/loilo-inc/canarycage/v6/env"
"github.com/urfave/cli/v3"
)
func Audit(app *cageapp.App, provider cageapp.AuditCmdProvider) *cli.Command {
input := cageapp.NewAuditCmdInput()
input.App = app
return &cli.Command{
Name: "audit",
Usage: "Audit container images used in an ECS service",
ArgsUsage: "[directory path of service.json]",
Flags: []cli.Flag{
cageapp.RegionFlag(&input.Region),
cageapp.ClusterFlag(&input.Cluster),
cageapp.ServiceFlag(&input.Service),
&cli.BoolFlag{
Name: "detail",
Usage: "By default, only the name and URI of the finding are logged.",
Value: false,
Destination: &input.LogDetail,
},
&cli.BoolFlag{
Name: "json",
Usage: "Output the audit result in JSON format",
Value: false,
Destination: &input.JSON,
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
dir, _, err := RequireArgs(cmd, 0, 1)
if err != nil {
return err
}
if input.Region == "" {
return errors.New("--region flag is required")
}
if dir != "" {
srv, err := env.LoadServiceDefinition(dir)
if err != nil {
return err
}
if srv.ServiceName == nil || srv.Cluster == nil {
return errors.New("service.json must contain ServiceName and Cluster")
}
input.Service = *srv.ServiceName
input.Cluster = *srv.Cluster
} else if input.Cluster == "" || input.Service == "" {
return errors.New("either directory argument or both --cluster and --service flags must be provided")
}
auditCmd, err := provider(ctx, input)
if err != nil {
return err
}
return auditCmd.Run(ctx)
},
}
}