@@ -10,7 +10,11 @@ import (
1010 "text/tabwriter"
1111
1212 "github.com/dustin/go-humanize"
13+ "github.com/google/go-containerregistry/pkg/authn"
14+ "github.com/google/go-containerregistry/pkg/crane"
15+ "github.com/google/go-containerregistry/pkg/name"
1316 v1 "github.com/google/go-containerregistry/pkg/v1"
17+ "github.com/google/go-containerregistry/pkg/v1/remote"
1418 "github.com/google/go-containerregistry/pkg/v1/tarball"
1519 "github.com/urfave/cli/v2"
1620)
@@ -68,17 +72,49 @@ func main() {
6872 app .Run (os .Args )
6973}
7074
71- func getImage (filename string ) (v1.Image , error ) {
72- if filename == "" {
73- return nil , fmt .Errorf ("no filename provided" )
75+ func getImage (r string ) (v1.Image , error ) {
76+ if r == "" {
77+ return nil , fmt .Errorf ("no image ref provided" )
7478 }
75- image , err := tarball .ImageFromPath (filename , nil )
79+
80+ image , _ , err := getRemoteImage (r )
81+ if err == nil {
82+ return image , nil
83+ }
84+
85+ image , err = tarball .ImageFromPath (r , nil )
7686 if err != nil {
7787 return nil , err
7888 }
89+
7990 return image , nil
8091}
8192
93+ func makeOptions (opts ... crane.Option ) crane.Options {
94+ opt := crane.Options {
95+ Remote : []remote.Option {
96+ remote .WithAuthFromKeychain (authn .DefaultKeychain ),
97+ },
98+ }
99+ for _ , o := range opts {
100+ o (& opt )
101+ }
102+ return opt
103+ }
104+
105+ func getRemoteImage (r string , opt ... crane.Option ) (v1.Image , name.Reference , error ) {
106+ o := makeOptions (opt ... )
107+ ref , err := name .ParseReference (r , o .Name ... )
108+ if err != nil {
109+ return nil , nil , fmt .Errorf ("parsing reference %q: %w" , r , err )
110+ }
111+ img , err := remote .Image (ref , o .Remote ... )
112+ if err != nil {
113+ return nil , nil , fmt .Errorf ("reading image %q: %w" , ref , err )
114+ }
115+ return img , ref , nil
116+ }
117+
82118// info returns the config file for the given filename.
83119func info (cfg * config ) error {
84120 image , err := getImage (cfg .filename )
0 commit comments