Debian Codegraph @

cmd/soci/commands/index/info.go

raw symbols SCIP
1 /*
2 Copyright The Soci Snapshotter Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
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 }