diff --git a/cli/command/trust/formatter.go b/cli/command/trust/formatter.go index 9597cfbd76..e536995fd7 100644 --- a/cli/command/trust/formatter.go +++ b/cli/command/trust/formatter.go @@ -21,7 +21,15 @@ const ( // Name: name of the signed tag // Digest: hex encoded digest of the contents // Signers: list of entities who signed the tag -type SignedTagInfo struct { +// +// Deprecated: this type was only used internally and will be removed in the next release. +type SignedTagInfo = signedTagInfo + +// signedTagInfo represents all formatted information needed to describe a signed tag: +// Name: name of the signed tag +// Digest: hex encoded digest of the contents +// Signers: list of entities who signed the tag +type signedTagInfo struct { Name string Digest string Signers []string @@ -30,23 +38,41 @@ type SignedTagInfo struct { // SignerInfo represents all formatted information needed to describe a signer: // Name: name of the signer role // Keys: the keys associated with the signer -type SignerInfo struct { +// +// Deprecated: this type was only used internally and will be removed in the next release. +type SignerInfo = signerInfo + +// signerInfo represents all formatted information needed to describe a signer: +// Name: name of the signer role +// Keys: the keys associated with the signer +type signerInfo struct { Name string Keys []string } // NewTrustTagFormat returns a Format for rendering using a trusted tag Context +// +// Deprecated: this function was only used internally and will be removed in the next release. func NewTrustTagFormat() formatter.Format { return defaultTrustTagTableFormat } // NewSignerInfoFormat returns a Format for rendering a signer role info Context +// +// Deprecated: this function was only used internally and will be removed in the next release. func NewSignerInfoFormat() formatter.Format { return defaultSignerInfoTableFormat } // TagWrite writes the context -func TagWrite(ctx formatter.Context, signedTagInfoList []SignedTagInfo) error { +// +// Deprecated: this function was only used internally and will be removed in the next release. +func TagWrite(fmtCtx formatter.Context, signedTagInfoList []signedTagInfo) error { + return tagWrite(fmtCtx, signedTagInfoList) +} + +// tagWrite writes the context +func tagWrite(fmtCtx formatter.Context, signedTagInfoList []signedTagInfo) error { render := func(format func(subContext formatter.SubContext) error) error { for _, signedTag := range signedTagInfoList { if err := format(&trustTagContext{s: signedTag}); err != nil { @@ -61,12 +87,12 @@ func TagWrite(ctx formatter.Context, signedTagInfoList []SignedTagInfo) error { "Digest": trustedDigestHeader, "Signers": signersHeader, } - return ctx.Write(&trustTagCtx, render) + return fmtCtx.Write(&trustTagCtx, render) } type trustTagContext struct { formatter.HeaderContext - s SignedTagInfo + s signedTagInfo } // SignedTag returns the name of the signed tag @@ -86,11 +112,18 @@ func (c *trustTagContext) Signers() string { } // SignerInfoWrite writes the context -func SignerInfoWrite(ctx formatter.Context, signerInfoList []SignerInfo) error { +// +// Deprecated: this function was only used internally and will be removed in the next release. +func SignerInfoWrite(fmtCtx formatter.Context, signerInfoList []signerInfo) error { + return signerInfoWrite(fmtCtx, signerInfoList) +} + +// signerInfoWrite writes the context. +func signerInfoWrite(fmtCtx formatter.Context, signerInfoList []signerInfo) error { render := func(format func(subContext formatter.SubContext) error) error { for _, signerInfo := range signerInfoList { if err := format(&signerInfoContext{ - trunc: ctx.Trunc, + trunc: fmtCtx.Trunc, s: signerInfo, }); err != nil { return err @@ -103,13 +136,13 @@ func SignerInfoWrite(ctx formatter.Context, signerInfoList []SignerInfo) error { "Signer": signerNameHeader, "Keys": keysHeader, } - return ctx.Write(&signerInfoCtx, render) + return fmtCtx.Write(&signerInfoCtx, render) } type signerInfoContext struct { formatter.HeaderContext trunc bool - s SignerInfo + s signerInfo } // Keys returns the sorted list of keys associated with the signer diff --git a/cli/command/trust/formatter_test.go b/cli/command/trust/formatter_test.go index 4c0c194f4c..413a2605ab 100644 --- a/cli/command/trust/formatter_test.go +++ b/cli/command/trust/formatter_test.go @@ -23,7 +23,7 @@ func TestTrustTag(t *testing.T) { }{ { trustTagContext{ - s: SignedTagInfo{ + s: signedTagInfo{ Name: trustedTag, Digest: digest, Signers: nil, @@ -34,7 +34,7 @@ func TestTrustTag(t *testing.T) { }, { trustTagContext{ - s: SignedTagInfo{ + s: signedTagInfo{ Name: trustedTag, Digest: digest, Signers: nil, @@ -46,7 +46,7 @@ func TestTrustTag(t *testing.T) { // Empty signers makes a row with empty string { trustTagContext{ - s: SignedTagInfo{ + s: signedTagInfo{ Name: trustedTag, Digest: digest, Signers: nil, @@ -57,7 +57,7 @@ func TestTrustTag(t *testing.T) { }, { trustTagContext{ - s: SignedTagInfo{ + s: signedTagInfo{ Name: trustedTag, Digest: digest, Signers: []string{"alice", "bob", "claire"}, @@ -69,7 +69,7 @@ func TestTrustTag(t *testing.T) { // alphabetic signing on Signers { trustTagContext{ - s: SignedTagInfo{ + s: signedTagInfo{ Name: trustedTag, Digest: digest, Signers: []string{"claire", "bob", "alice"}, @@ -110,7 +110,7 @@ func TestTrustTagContextWrite(t *testing.T) { // Table Format { formatter.Context{ - Format: NewTrustTagFormat(), + Format: defaultTrustTagTableFormat, }, `SIGNED TAG DIGEST SIGNERS tag1 deadbeef alice @@ -120,7 +120,7 @@ tag3 bbbbbbbb }, } - signedTags := []SignedTagInfo{ + signedTags := []signedTagInfo{ {Name: "tag1", Digest: "deadbeef", Signers: []string{"alice"}}, {Name: "tag2", Digest: "aaaaaaaa", Signers: []string{"alice", "bob"}}, {Name: "tag3", Digest: "bbbbbbbb", Signers: []string{}}, @@ -131,7 +131,7 @@ tag3 bbbbbbbb var out bytes.Buffer tc.context.Output = &out - if err := TagWrite(tc.context, signedTags); err != nil { + if err := tagWrite(tc.context, signedTags); err != nil { assert.Error(t, err, tc.expected) } else { assert.Equal(t, out.String(), tc.expected) @@ -140,7 +140,7 @@ tag3 bbbbbbbb } } -// With no trust data, the TagWrite will print an empty table: +// With no trust data, the formatWrite will print an empty table: // it's up to the caller to decide whether or not to print this versus an error func TestTrustTagContextEmptyWrite(t *testing.T) { emptyCase := struct { @@ -148,16 +148,16 @@ func TestTrustTagContextEmptyWrite(t *testing.T) { expected string }{ formatter.Context{ - Format: NewTrustTagFormat(), + Format: defaultTrustTagTableFormat, }, `SIGNED TAG DIGEST SIGNERS `, } - emptySignedTags := []SignedTagInfo{} + emptySignedTags := []signedTagInfo{} out := bytes.NewBufferString("") emptyCase.context.Output = out - err := TagWrite(emptyCase.context, emptySignedTags) + err := tagWrite(emptyCase.context, emptySignedTags) assert.NilError(t, err) assert.Check(t, is.Equal(emptyCase.expected, out.String())) } @@ -168,15 +168,15 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) { expected string }{ formatter.Context{ - Format: NewSignerInfoFormat(), + Format: defaultSignerInfoTableFormat, }, `SIGNER KEYS `, } - emptySignerInfo := []SignerInfo{} + emptySignerInfo := []signerInfo{} out := bytes.NewBufferString("") emptyCase.context.Output = out - err := SignerInfoWrite(emptyCase.context, emptySignerInfo) + err := signerInfoWrite(emptyCase.context, emptySignerInfo) assert.NilError(t, err) assert.Check(t, is.Equal(emptyCase.expected, out.String())) } @@ -202,7 +202,7 @@ func TestSignerInfoContextWrite(t *testing.T) { // Table Format { formatter.Context{ - Format: NewSignerInfoFormat(), + Format: defaultSignerInfoTableFormat, Trunc: true, }, `SIGNER KEYS @@ -214,7 +214,7 @@ eve foobarbazqux, key31, key32 // No truncation { formatter.Context{ - Format: NewSignerInfoFormat(), + Format: defaultSignerInfoTableFormat, }, `SIGNER KEYS alice key11, key12 @@ -224,7 +224,7 @@ eve foobarbazquxquux, key31, key32 }, } - signerInfo := []SignerInfo{ + signerInfo := []signerInfo{ {Name: "alice", Keys: []string{"key11", "key12"}}, {Name: "bob", Keys: []string{"key21"}}, {Name: "eve", Keys: []string{"key31", "key32", "foobarbazquxquux"}}, @@ -234,7 +234,7 @@ eve foobarbazquxquux, key31, key32 var out bytes.Buffer tc.context.Output = &out - if err := SignerInfoWrite(tc.context, signerInfo); err != nil { + if err := signerInfoWrite(tc.context, signerInfo); err != nil { assert.Error(t, err, tc.expected) } else { assert.Equal(t, out.String(), tc.expected) diff --git a/cli/command/trust/inspect_pretty.go b/cli/command/trust/inspect_pretty.go index b0b5e8c51c..3eac2cfbe8 100644 --- a/cli/command/trust/inspect_pretty.go +++ b/cli/command/trust/inspect_pretty.go @@ -56,33 +56,33 @@ func printSortedAdminKeys(out io.Writer, adminRoles []client.RoleWithSignatures) func printSignatures(out io.Writer, signatureRows []trustTagRow) error { trustTagCtx := formatter.Context{ Output: out, - Format: NewTrustTagFormat(), + Format: defaultTrustTagTableFormat, } // convert the formatted type before printing - formattedTags := []SignedTagInfo{} + formattedTags := []signedTagInfo{} for _, sigRow := range signatureRows { formattedSigners := sigRow.Signers if len(formattedSigners) == 0 { formattedSigners = append(formattedSigners, fmt.Sprintf("(%s)", releasedRoleName)) } - formattedTags = append(formattedTags, SignedTagInfo{ + formattedTags = append(formattedTags, signedTagInfo{ Name: sigRow.SignedTag, Digest: sigRow.Digest, Signers: formattedSigners, }) } - return TagWrite(trustTagCtx, formattedTags) + return tagWrite(trustTagCtx, formattedTags) } func printSignerInfo(out io.Writer, roleToKeyIDs map[string][]string) error { signerInfoCtx := formatter.Context{ Output: out, - Format: NewSignerInfoFormat(), + Format: defaultSignerInfoTableFormat, Trunc: true, } - formattedSignerInfo := []SignerInfo{} + formattedSignerInfo := []signerInfo{} for name, keyIDs := range roleToKeyIDs { - formattedSignerInfo = append(formattedSignerInfo, SignerInfo{ + formattedSignerInfo = append(formattedSignerInfo, signerInfo{ Name: name, Keys: keyIDs, }) @@ -90,5 +90,5 @@ func printSignerInfo(out io.Writer, roleToKeyIDs map[string][]string) error { sort.Slice(formattedSignerInfo, func(i, j int) bool { return sortorder.NaturalLess(formattedSignerInfo[i].Name, formattedSignerInfo[j].Name) }) - return SignerInfoWrite(signerInfoCtx, formattedSignerInfo) + return signerInfoWrite(signerInfoCtx, formattedSignerInfo) }