Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 go-imageinspect authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package imageinspect

import (
"context"
"encoding/json"

"github.com/containerd/containerd/content"
"github.com/containerd/containerd/remotes"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
)

type Config struct {
ocispecs.Image
}

func (l *Loader) scanConfig(ctx context.Context, fetcher remotes.Fetcher, desc ocispecs.Descriptor, img *Image) error {
_, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc)
if err != nil {
return err
}

dt, err := content.ReadBlob(ctx, l.cache, desc)
if err != nil {
return err
}

return json.Unmarshal(dt, &img.Config)
}
4 changes: 4 additions & 0 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func (l *Loader) Load(ctx context.Context, ref string) (*Result, error) {
img.Title = title
}

if err := l.scanConfig(ctx, fetcher, mfst.manifest.Config, &img); err != nil {
return nil, err
}

refs, ok := r.refs[dgst]
if ok {
if err := l.scanSBOM(ctx, fetcher, r, dgst, refs, &img); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestSingleArchManifest(t *testing.T) {

require.Equal(t, int64(300), img.Size)
require.Equal(t, "linux/arm64", img.Platform)
require.NotNil(t, img.Config)
}

func TestMultiArchManifest(t *testing.T) {
Expand Down Expand Up @@ -146,12 +147,14 @@ func TestMultiArchManifest(t *testing.T) {

require.Equal(t, int64(25), img.Size)
require.Equal(t, "linux/arm64", img.Platform)
require.NotNil(t, img.Config)

img, ok = r.Images["linux/amd64"]
require.True(t, ok)

require.Equal(t, int64(50), img.Size)
require.Equal(t, "linux/amd64", img.Platform)
require.NotNil(t, img.Config)
}

func TestTitle(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Image struct {
Size int64

Signatures []Signature
Config *Config `json:",omitempty"`
SBOM *SBOM `json:",omitempty"`
Provenance *Provenance `json:",omitempty"`

Expand Down