...
1
2
3
4 package inspect
5
6 import (
7 "context"
8 "fmt"
9
10 "edge-infra.dev/pkg/f8n/warehouse/packagelock"
11 "edge-infra.dev/pkg/lib/cli/rags"
12 "edge-infra.dev/pkg/lib/cli/sink"
13 )
14
15 func New() *sink.Command {
16 var (
17 location string
18 project string
19 repository string
20 )
21 cmd := &sink.Command{
22 Use: "inspect [flags] <filepath>",
23 Short: "inspect build metadata for packages declared in a packagelock file",
24 Flags: []*rags.Rag{
25 {
26 Name: "location",
27 Usage: "location of the repository (e.g. us-east1)",
28 Value: &rags.String{Var: &location},
29 Short: "l",
30 Required: true,
31 },
32 {
33 Name: "project",
34 Usage: "name of the GCP project containing the registry",
35 Value: &rags.String{Var: &project},
36 Short: "p",
37 Required: true,
38 },
39 {
40 Name: "repository",
41 Usage: "name of the GAR repository",
42 Value: &rags.String{Var: &repository},
43 Short: "r",
44 Required: true,
45 },
46 },
47 Exec: func(ctx context.Context, r sink.Run) error {
48 switch len(r.Args()) {
49 case 0:
50 return fmt.Errorf("error: a lockfile path must be passed")
51 case 1:
52 default:
53 return fmt.Errorf("error: only one lockfile may be passed")
54 }
55
56 plr, err := packagelock.NewRules()
57 if err != nil {
58 return err
59 }
60 plf, err := plr.ParsePackageLock(r.Args()[0])
61 if err != nil {
62 return fmt.Errorf("invalid lockfile: %w", err)
63 }
64 r.Log.Info(fmt.Sprintf("valid lockfile: %s", r.Args()[0]))
65
66 err = packagelock.InspectPackageLock(ctx, r.Log, plf, location, project, repository)
67 if err != nil {
68 return err
69 }
70
71 r.Log.Info("all package tag versions match digest version")
72 return nil
73 },
74 }
75 return cmd
76 }
77
View as plain text