| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package index |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"io" |
| 23 |
"os" |
| 24 |
|
| 25 |
"github.com/awslabs/soci-snapshotter/soci" |
| 26 |
"github.com/awslabs/soci-snapshotter/soci/store" |
| 27 |
|
| 28 |
"github.com/opencontainers/go-digest" |
| 29 |
v1 "github.com/opencontainers/image-spec/specs-go/v1" |
| 30 |
"github.com/urfave/cli" |
| 31 |
) |
| 32 |
|
| 33 |
var infoCommand = cli.Command{ |
| 34 |
Name: "info", |
| 35 |
Usage: "display an index", |
| 36 |
Description: "get detailed info about an index", |
| 37 |
ArgsUsage: "<digest>", |
| 38 |
Action: func(cliContext *cli.Context) error { |
| 39 |
digest, err := digest.Parse(cliContext.Args().First()) |
| 40 |
if err != nil { |
| 41 |
return err |
| 42 |
} |
| 43 |
db, err := soci.NewDB(soci.ArtifactsDbPath()) |
| 44 |
if err != nil { |
| 45 |
return err |
| 46 |
} |
| 47 |
artifactType, err := db.GetArtifactType(digest.String()) |
| 48 |
if err != nil { |
| 49 |
return err |
| 50 |
} |
| 51 |
if artifactType == soci.ArtifactEntryTypeLayer { |
| 52 |
return fmt.Errorf("the provided digest is of ztoc not SOCI index. Use \"soci ztoc info\" command to get detailed info of ztoc") |
| 53 |
} |
| 54 |
ctx, cancel := context.WithTimeout(context.Background(), cliContext.GlobalDuration("timeout")) |
| 55 |
defer cancel() |
| 56 |
ctx, store, err := store.NewContentStore(ctx, store.WithType(store.ContentStoreType(cliContext.GlobalString("content-store"))), store.WithNamespace(cliContext.GlobalString("namespace"))) |
| 57 |
if err != nil { |
| 58 |
return err |
| 59 |
} |
| 60 |
reader, err := store.Fetch(ctx, v1.Descriptor{Digest: digest}) |
| 61 |
if err != nil { |
| 62 |
return err |
| 63 |
} |
| 64 |
defer reader.Close() |
| 65 |
|
| 66 |
_, err = io.Copy(os.Stdout, reader) |
| 67 |
return err |
| 68 |
}, |
| 69 |
} |