Skip to content

Commit

Permalink
fix: resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Feb 13, 2025
1 parent 8603956 commit 25ce72a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 3 additions & 1 deletion cmd/notation/blob/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ Example - Inspect a signature:
}

func runInspect(opts *inspectOpts) error {
// initialize display handler
displayHandler, err := display.NewBlobInspectHandler(opts.Printer, opts.Format)
if err != nil {
return err
}

// parse signature file
envelopeMediaType, err := parseEnvelopeMediaType(filepath.Base(opts.sigPath))
if err != nil {
return err
}

envelopeBytes, err := os.ReadFile(opts.sigPath)
if err != nil {
return fmt.Errorf("failed to read signature file: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/notation/internal/display/metadata/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type InspectHandler interface {
type BlobInspectHandler interface {
Renderer

// OnEvelopeParsed sets the parsed envelope for the handler.
OnEnvelopeParsed(nodeName, envelopeMediaType string, envelope signature.Envelope) error
// OnEnvelopeParsed sets the parsed envelope for the handler.
OnEnvelopeParsed(signaturePath, signatureEnvelopeType string, envelope signature.Envelope) error
}

// VerifyHandler is a handler for rendering metadata information of
Expand Down
9 changes: 4 additions & 5 deletions cmd/notation/internal/display/metadata/json/blob_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import (
)

// BlobInspectHandler is a handler for inspecting metadata information and
// rendering it in a JSON format. It implements the metadata.BlobInspectHandler
// rendering it in JSON format. It implements the metadata.BlobInspectHandler
// interface.
type BlobInspectHandler struct {
printer *output.Printer

printer *output.Printer
signature *signature
}

Expand All @@ -36,9 +35,9 @@ func NewBlobInspectHandler(printer *output.Printer) *BlobInspectHandler {
}

// OnEnvelopeParsed sets the parsed envelope for the handler.
func (h *BlobInspectHandler) OnEnvelopeParsed(nodeName, envelopeMediaType string, envelope coresignature.Envelope) error {
func (h *BlobInspectHandler) OnEnvelopeParsed(nodeName, signatureEnvelopeType string, envelope coresignature.Envelope) error {
// blob signature does not have a digest
sig, err := newSignature("", envelopeMediaType, envelope)
sig, err := newSignature("", signatureEnvelopeType, envelope)
if err != nil {
return err
}

Check warning on line 43 in cmd/notation/internal/display/metadata/json/blob_inspect.go

View check run for this annotation

Codecov / codecov/patch

cmd/notation/internal/display/metadata/json/blob_inspect.go#L42-L43

Added lines #L42 - L43 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions cmd/notation/internal/display/metadata/json/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (h *InspectHandler) Render() error {
}

// newSignature parses the signature blob and returns a Signature object.
func newSignature(digest, envelopeMediaType string, sigEnvelope coresignature.Envelope) (*signature, error) {
func newSignature(digest, signatureEnvelopeType string, sigEnvelope coresignature.Envelope) (*signature, error) {
envelopeContent, err := sigEnvelope.Content()
if err != nil {
return nil, err
Expand All @@ -123,7 +123,7 @@ func newSignature(digest, envelopeMediaType string, sigEnvelope coresignature.En
}
sig := &signature{
Digest: digest,
SignatureEnvelopeType: envelopeMediaType,
SignatureEnvelopeType: signatureEnvelopeType,
SignatureAlgorithm: string(signatureAlgorithm),
SignedAttributes: getSignedAttributes(envelopeContent),
UserDefinedAttributes: signedArtifactDesc.Annotations,
Expand Down
7 changes: 3 additions & 4 deletions cmd/notation/internal/display/metadata/tree/blob_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
// rendering it in a tree format. It implements the metadata.BlobInspectHandler
// interface.
type BlobInspectHandler struct {
printer *output.Printer

printer *output.Printer
signatureNode *node
}

Expand All @@ -36,8 +35,8 @@ func NewBlobInspectHandler(printer *output.Printer) *BlobInspectHandler {
}

// OnEnvelopeParsed sets the parsed envelope for the handler.
func (h *BlobInspectHandler) OnEnvelopeParsed(nodeName, envelopeMediaType string, envelope signature.Envelope) error {
sigNode, err := newSignatureNode(nodeName, envelopeMediaType, envelope)
func (h *BlobInspectHandler) OnEnvelopeParsed(signaturePath, signatureEnvelopeType string, envelope signature.Envelope) error {
sigNode, err := newSignatureNode(signaturePath, signatureEnvelopeType, envelope)
if err != nil {
return err
}

Check warning on line 42 in cmd/notation/internal/display/metadata/tree/blob_inspect.go

View check run for this annotation

Codecov / codecov/patch

cmd/notation/internal/display/metadata/tree/blob_inspect.go#L41-L42

Added lines #L41 - L42 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions cmd/notation/internal/display/metadata/tree/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (h *InspectHandler) Render() error {
return h.rootReferenceNode.Print(h.printer)
}

func newSignatureNode(nodeName, envelopeMediaType string, sigEnvelope coresignature.Envelope) (*node, error) {
func newSignatureNode(nodeName, signatureEnvelopeType string, sigEnvelope coresignature.Envelope) (*node, error) {
envelopeContent, err := sigEnvelope.Content()
if err != nil {
return nil, err

Check warning on line 88 in cmd/notation/internal/display/metadata/tree/inspect.go

View check run for this annotation

Codecov / codecov/patch

cmd/notation/internal/display/metadata/tree/inspect.go#L88

Added line #L88 was not covered by tests
Expand All @@ -99,7 +99,7 @@ func newSignatureNode(nodeName, envelopeMediaType string, sigEnvelope coresignat
// create signature node
sigNode := newNode(nodeName)
sigNode.AddPair("signature algorithm", string(signatureAlgorithm))
sigNode.AddPair("signature envelope type", envelopeMediaType)
sigNode.AddPair("signature envelope type", signatureEnvelopeType)

addSignedAttributes(sigNode, envelopeContent)
addUserDefinedAttributes(sigNode, signedArtifactDesc.Annotations)
Expand Down

0 comments on commit 25ce72a

Please sign in to comment.