-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (96 loc) · 2.2 KB
/
Copy pathmain.go
File metadata and controls
104 lines (96 loc) · 2.2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"context"
"fmt"
"log/slog"
"os"
"runtime/debug"
"github.com/go-jose/go-jose/v3/jwt"
"github.com/quay/clair/config"
_ "github.com/quay/claircore/updater/defaults"
"github.com/urfave/cli/v2"
"github.com/quay/clair/v4/cmd"
_ "github.com/quay/clair/v4/echo"
"github.com/quay/clair/v4/internal/logging"
)
var commonClaim = jwt.Claims{}
func main() {
var exit int
defer func() {
if r := recover(); r != nil {
fmt.Printf("Something unexpected happened: %s\n", r)
fmt.Print(string(debug.Stack()))
os.Exit(1)
}
os.Exit(exit)
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
app := &cli.App{
Name: "clairctl",
Version: cmd.Version,
Usage: "interact with a clair API",
Description: "A command-line tool for clair v4.",
EnableBashCompletion: true,
Before: func(c *cli.Context) error {
if c.IsSet("q") {
logging.Level.Set(slog.LevelWarn)
}
if c.IsSet("D") {
logging.Level.Set(slog.LevelDebug)
}
commonClaim.Issuer = c.String("issuer")
return nil
},
Commands: []*cli.Command{
ManifestCmd,
ReportCmd,
ExportCmd,
ImportCmd,
DeleteCmd,
CheckConfigCmd,
AdminCmd,
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "D",
Usage: "print debugging logs",
},
&cli.BoolFlag{
Name: "q",
Usage: "quieter log output",
},
&cli.PathFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "clair configuration file",
Value: "config.yaml",
TakesFile: true,
EnvVars: []string{"CLAIR_CONF"},
},
&cli.StringFlag{
Name: "issuer",
Aliases: []string{"iss"},
Usage: `jwt "issuer" to use when making authenticated requests`,
Value: "clairctl",
},
},
ExitErrHandler: func(c *cli.Context, err error) {
if err != nil {
exit = 1
if err, ok := err.(cli.ExitCoder); ok {
exit = err.ExitCode()
}
slog.ErrorContext(c.Context, "error exit", "reason", err)
}
},
}
app.RunContext(ctx, os.Args)
}
func loadConfig(n string) (*config.Config, error) {
var cfg config.Config
if err := cmd.LoadConfig(&cfg, n, false); err != nil {
return nil, err
}
return &cfg, nil
}