diff --git a/cmd/notation/internal/display/metadata/tree/inspect.go b/cmd/notation/internal/display/metadata/tree/inspect.go index c9f58ed23..51aa161e5 100644 --- a/cmd/notation/internal/display/metadata/tree/inspect.go +++ b/cmd/notation/internal/display/metadata/tree/inspect.go @@ -29,7 +29,6 @@ import ( "github.com/notaryproject/notation-go/registry" "github.com/notaryproject/notation/cmd/notation/internal/display/output" "github.com/notaryproject/notation/internal/envelope" - "github.com/notaryproject/notation/internal/tree" "github.com/notaryproject/tspclient-go" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -41,10 +40,10 @@ type InspectHandler struct { // rootReferenceNode is the root node with the artifact reference as the // value. - rootReferenceNode *tree.Node + rootReferenceNode *Node // notationSignaturesNode is the node for all signatures associated with the // artifact. - notationSignaturesNode *tree.Node + notationSignaturesNode *Node } // NewInspectHandler creates a TreeHandler to inspect signatures and print in tree @@ -60,7 +59,7 @@ func NewInspectHandler(printer *output.Printer) *InspectHandler { // // mediaType is a no-op for this handler. func (h *InspectHandler) OnReferenceResolved(reference, _ string) { - h.rootReferenceNode = tree.New(reference) + h.rootReferenceNode = New(reference) h.notationSignaturesNode = h.rootReferenceNode.Add(registry.ArtifactTypeNotation) } @@ -78,7 +77,7 @@ func (h *InspectHandler) Render() error { return h.rootReferenceNode.Print(h.printer) } -func addSignature(node *tree.Node, digest string, sigEnvelope coresignature.Envelope) error { +func addSignature(node *Node, digest string, sigEnvelope coresignature.Envelope) error { envelopeContent, err := sigEnvelope.Content() if err != nil { return err @@ -104,7 +103,7 @@ func addSignature(node *tree.Node, digest string, sigEnvelope coresignature.Enve return nil } -func addSignedAttributes(node *tree.Node, envelopeContent *coresignature.EnvelopeContent) { +func addSignedAttributes(node *Node, envelopeContent *coresignature.EnvelopeContent) { signedAttributesNode := node.Add("signed attributes") signedAttributesNode.AddPair("content type", string(envelopeContent.Payload.ContentType)) signedAttributesNode.AddPair("signing scheme", string(envelopeContent.SignerInfo.SignedAttributes.SigningScheme)) @@ -117,7 +116,7 @@ func addSignedAttributes(node *tree.Node, envelopeContent *coresignature.Envelop } } -func addUserDefinedAttributes(node *tree.Node, annotations map[string]string) { +func addUserDefinedAttributes(node *Node, annotations map[string]string) { userDefinedAttributesNode := node.Add("user defined attributes") if len(annotations) == 0 { userDefinedAttributesNode.Add("(empty)") @@ -129,7 +128,7 @@ func addUserDefinedAttributes(node *tree.Node, annotations map[string]string) { } } -func addUnsignedAttributes(node *tree.Node, envelopeContent *coresignature.EnvelopeContent) { +func addUnsignedAttributes(node *Node, envelopeContent *coresignature.EnvelopeContent) { unsignedAttributesNode := node.Add("unsigned attributes") if signingAgent := envelopeContent.SignerInfo.UnsignedAttributes.SigningAgent; signingAgent != "" { unsignedAttributesNode.AddPair("signing agent", signingAgent) @@ -139,14 +138,14 @@ func addUnsignedAttributes(node *tree.Node, envelopeContent *coresignature.Envel } } -func addSignedArtifact(node *tree.Node, signedArtifactDesc ocispec.Descriptor) { +func addSignedArtifact(node *Node, signedArtifactDesc ocispec.Descriptor) { artifactNode := node.Add("signed artifact") artifactNode.AddPair("media type", signedArtifactDesc.MediaType) artifactNode.AddPair("digest", signedArtifactDesc.Digest.String()) artifactNode.AddPair("size", strconv.FormatInt(signedArtifactDesc.Size, 10)) } -func addTimestamp(node *tree.Node, signerInfo coresignature.SignerInfo) { +func addTimestamp(node *Node, signerInfo coresignature.SignerInfo) { timestampNode := node.Add("timestamp signature") signedToken, err := tspclient.ParseSignedToken(signerInfo.UnsignedAttributes.TimestampSignature) if err != nil { @@ -167,7 +166,7 @@ func addTimestamp(node *tree.Node, signerInfo coresignature.SignerInfo) { addCertificates(timestampNode, signedToken.Certificates) } -func addCertificates(node *tree.Node, certChain []*x509.Certificate) { +func addCertificates(node *Node, certChain []*x509.Certificate) { certListNode := node.Add("certificates") for _, cert := range certChain { hash := sha256.Sum256(cert.Raw) diff --git a/cmd/notation/internal/display/metadata/tree/inspect_test.go b/cmd/notation/internal/display/metadata/tree/inspect_test.go index 6a5eddeca..3900c9595 100644 --- a/cmd/notation/internal/display/metadata/tree/inspect_test.go +++ b/cmd/notation/internal/display/metadata/tree/inspect_test.go @@ -20,19 +20,18 @@ import ( "time" coresignature "github.com/notaryproject/notation-core-go/signature" - "github.com/notaryproject/notation/internal/tree" ) func TestAddSignedAttributes(t *testing.T) { t.Run("empty envelopeContent", func(t *testing.T) { - node := tree.New("root") + node := New("root") ec := &coresignature.EnvelopeContent{} addSignedAttributes(node, ec) // No error or panic expected; minimal check or just ensure it doesn't crash. }) t.Run("with expiry and extented node", func(t *testing.T) { - node := tree.New("root") + node := New("root") expiryTime := time.Now().Add(time.Hour) ec := &coresignature.EnvelopeContent{ Payload: coresignature.Payload{ @@ -77,7 +76,7 @@ func TestAddSignedAttributes(t *testing.T) { func TestAddUserDefinedAttributes(t *testing.T) { t.Run("empty map", func(t *testing.T) { - node := tree.New("root") + node := New("root") addUserDefinedAttributes(node, nil) if len(node.Children) == 0 { t.Fatal("expected node to have children") @@ -92,7 +91,7 @@ func TestAddUserDefinedAttributes(t *testing.T) { }) t.Run("non-empty map", func(t *testing.T) { - node := tree.New("root") + node := New("root") annotations := map[string]string{"key1": "val1", "key2": "val2"} addUserDefinedAttributes(node, annotations) udaNode := node.Children[0] @@ -107,7 +106,7 @@ func TestAddUserDefinedAttributes(t *testing.T) { func TestAddTimestamp(t *testing.T) { t.Run("invalid timestamp signature", func(t *testing.T) { - node := tree.New("root") + node := New("root") signerInfo := coresignature.SignerInfo{ UnsignedAttributes: coresignature.UnsignedAttributes{ TimestampSignature: []byte("invalid"), @@ -141,7 +140,7 @@ func TestAddTimestamp(t *testing.T) { TimestampSignature: tsaToken, }, } - node := tree.New("root") + node := New("root") addTimestamp(node, signerInfo) if len(node.Children) == 0 { t.Fatal("expected node to have children") diff --git a/internal/tree/tree.go b/cmd/notation/internal/display/metadata/tree/tree.go similarity index 100% rename from internal/tree/tree.go rename to cmd/notation/internal/display/metadata/tree/tree.go diff --git a/internal/tree/tree_test.go b/cmd/notation/internal/display/metadata/tree/tree_test.go similarity index 100% rename from internal/tree/tree_test.go rename to cmd/notation/internal/display/metadata/tree/tree_test.go