Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for reading sbom file from stdin #517

Merged
merged 1 commit into from
Aug 4, 2021
Merged
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
18 changes: 17 additions & 1 deletion cmd/cosign/cli/attach/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package attach

import (
"context"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/types"
Expand Down Expand Up @@ -73,7 +75,7 @@ func SBOMCmd(ctx context.Context, sbomRef, sbomType, imageRef string) error {
return err
}

b, err := ioutil.ReadFile(sbomRef)
b, err := sbomBytes(sbomRef)
if err != nil {
return err
}
Expand All @@ -88,3 +90,17 @@ func SBOMCmd(ctx context.Context, sbomRef, sbomType, imageRef string) error {

return nil
}

func sbomBytes(sbomRef string) ([]byte, error) {
// sbomRef can be "-", a string or a file.
switch signatureType(sbomRef) {
case StdinSignature:
return ioutil.ReadAll(os.Stdin)
case RawSignature:
return []byte(sbomRef), nil
case FileSignature:
return ioutil.ReadFile(filepath.Clean(sbomRef))
default:
return nil, errors.New("unknown SBOM arg type")
}
}