Skip to content

Commit

Permalink
fix for reading sbom file from stdin (#517)
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
  • Loading branch information
developer-guy committed Aug 4, 2021
1 parent 749cd29 commit fbc9831
Showing 1 changed file with 17 additions and 1 deletion.
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")
}
}

0 comments on commit fbc9831

Please sign in to comment.