chore: bump github.com/olekukonko/tablewriter from 0.0.5 to 1.0.7 (#3198)

* chore: bump github.com/olekukonko/tablewriter from 0.0.5 to 1.0.7

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>

* fix: zli failed to connect to https server using test certificates

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>

---------

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron
2025-06-16 00:07:15 +03:00
committed by GitHub
parent e7a5e09214
commit 8867814d95
8 changed files with 277 additions and 267 deletions
+7 -2
View File
@@ -87,12 +87,17 @@ func doHTTPRequest(req *http.Request, verifyTLS bool, debug bool,
host := req.Host
enableTLS := req.URL.Scheme != "http"
if verifyTLS {
// we want TLS enabled when verifyTLS is true
enableTLS = true
}
httpClientLock.Lock()
if httpClientsMap[host] == nil {
httpClient, err = common.CreateHTTPClient(&common.HTTPClientOptions{
// we want TLS enabled when verifyTLS is true.
TLSEnabled: verifyTLS,
TLSEnabled: enableTLS,
VerifyTLS: verifyTLS,
Host: host,
CertOptions: common.HTTPClientCertOptions{},
+83 -150
View File
@@ -16,6 +16,7 @@ import (
"github.com/dustin/go-humanize"
jsoniter "github.com/json-iterator/go"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
godigest "github.com/opencontainers/go-digest"
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"gopkg.in/yaml.v3"
@@ -881,15 +882,15 @@ func (cve cveResult) stringPlainText() string {
row[colCVESeverityIndex] = severity
row[colCVETitleIndex] = title
table.Append(row)
table.Append(row) //nolint:errcheck
for _, pkg := range cveListItem.PackageList {
pkgRow := generateTableRowForVulnerablePackage(pkg)
table.Append(pkgRow)
table.Append(pkgRow) //nolint:errcheck
}
}
table.Render()
table.Render() //nolint:errcheck
return builder.String()
}
@@ -953,26 +954,38 @@ func (ref referrersResult) string(format string, maxArtifactTypeLen int) (string
func (ref referrersResult) stringPlainText(maxArtifactTypeLen int) (string, error) {
var builder strings.Builder
table := getImageTableWriter(&builder)
table.SetColMinWidth(refArtifactTypeIndex, maxArtifactTypeLen)
table.SetColMinWidth(refDigestIndex, digestWidth)
table.SetColMinWidth(refSizeIndex, sizeWidth)
maxDigestWidth := digestWidth
rows := [][]string{}
for _, referrer := range ref {
artifactType := ellipsize(referrer.ArtifactType, maxArtifactTypeLen, ellipsis)
// digest := ellipsize(godigest.Digest(referrer.Digest).Encoded(), digestWidth, "")
size := ellipsize(humanize.Bytes(uint64(referrer.Size)), sizeWidth, ellipsis) //nolint:gosec,lll // refererrer.Size should >= 0
if len(referrer.Digest) > maxDigestWidth {
maxDigestWidth = len(referrer.Digest)
}
row := make([]string, refRowWidth)
row[refArtifactTypeIndex] = artifactType
row[refDigestIndex] = referrer.Digest
row[refSizeIndex] = size
table.Append(row)
rows = append(rows, row) //nolint:errcheck
}
table.Render()
table := getCommonTableWriter(&builder)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(refArtifactTypeIndex, maxArtifactTypeLen).
Set(refDigestIndex, maxDigestWidth).
Set(refSizeIndex, sizeWidth)),
)
for _, row := range rows {
table.Append(row) //nolint:errcheck
}
table.Render() //nolint:errcheck
return builder.String(), nil
}
@@ -1017,17 +1030,16 @@ func (repo repoStruct) string(format string, maxImgNameLen, maxTimeLen int, verb
func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool) (string, error) {
var builder strings.Builder
table := getImageTableWriter(&builder)
table.SetColMinWidth(repoNameIndex, repoMaxLen)
table.SetColMinWidth(repoSizeIndex, sizeWidth)
table.SetColMinWidth(repoLastUpdatedIndex, maxTimeLen)
table.SetColMinWidth(repoDownloadsIndex, downloadsWidth)
table.SetColMinWidth(repoStarsIndex, signedWidth)
if verbose {
table.SetColMinWidth(repoPlatformsIndex, platformWidth)
}
table := getCommonTableWriter(&builder)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(repoNameIndex, repoMaxLen).
Set(repoSizeIndex, sizeWidth).
Set(repoLastUpdatedIndex, maxTimeLen).
Set(repoDownloadsIndex, downloadsWidth).
Set(repoStarsIndex, signedWidth).
Set(repoPlatformsIndex, platformWidth)),
)
repoSize, err := strconv.Atoi(repo.Size)
if err != nil {
@@ -1052,7 +1064,7 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool)
repoPlatforms = repoPlatforms[1:]
}
table.Append(row)
table.Append(row) //nolint:errcheck
if verbose {
for _, platform := range repoPlatforms {
@@ -1060,11 +1072,11 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool)
row[repoPlatformsIndex] = getPlatformStr(platform)
table.Append(row)
table.Append(row) //nolint:errcheck
}
}
table.Render()
table.Render() //nolint:errcheck
return builder.String(), nil
}
@@ -1109,70 +1121,60 @@ func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatfo
func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen int, verbose bool) (string, error) {
var builder strings.Builder
table := getImageTableWriter(&builder)
tagLen := max(len("TAG"), maxTagLen, tagWidth)
imageNameLen := max(len("REPOSITORY"), maxImgNameLen, imageNameWidth)
platformLen := max(len("OS/ARCH"), maxPlatformLen, platformWidth)
configLen := configWidth
layersLen := layersWidth
table.SetColMinWidth(colImageNameIndex, maxImgNameLen)
table.SetColMinWidth(colTagIndex, maxTagLen)
table.SetColMinWidth(colPlatformIndex, platformWidth)
table.SetColMinWidth(colDigestIndex, digestWidth)
table.SetColMinWidth(colSizeIndex, sizeWidth)
table.SetColMinWidth(colIsSignedIndex, isSignedWidth)
if verbose {
table.SetColMinWidth(colConfigIndex, configWidth)
table.SetColMinWidth(colLayersIndex, layersWidth)
if !verbose {
// Ths hides the columns effectively, 0 links the neighboring columns together
configLen = 1
layersLen = 1
}
table := getCommonTableWriter(&builder)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(colImageNameIndex, imageNameLen).
Set(colTagIndex, tagLen).
Set(colPlatformIndex, platformLen).
Set(colDigestIndex, digestWidth).
Set(colSizeIndex, sizeWidth).
Set(colIsSignedIndex, isSignedWidth).
Set(colConfigIndex, configLen).
Set(colLayersIndex, layersLen)),
)
var imageName, tagName string
imageName = img.RepoName
tagName = img.Tag
if imageNameWidth > maxImgNameLen {
maxImgNameLen = imageNameWidth
}
if tagWidth > maxTagLen {
maxTagLen = tagWidth
}
// adding spaces so that image name and tag columns are aligned
// in case the name/tag are fully shown and too long
var offset string
if maxImgNameLen > len(imageName) {
offset = strings.Repeat(" ", maxImgNameLen-len(imageName))
imageName += offset
}
if maxTagLen > len(tagName) {
offset = strings.Repeat(" ", maxTagLen-len(tagName))
tagName += offset
}
err := addImageToTable(table, &img, maxPlatformLen, imageName, tagName, verbose)
err := addImageToTable(table, &img, imageName, tagName, verbose)
if err != nil {
return "", err
}
table.Render()
table.Render() //nolint:errcheck
return builder.String(), nil
}
func addImageToTable(table *tablewriter.Table, img *imageStruct, maxPlatformLen int,
func addImageToTable(table *tablewriter.Table, img *imageStruct,
imageName, tagName string, verbose bool,
) error {
switch img.MediaType {
case ispec.MediaTypeImageManifest:
return addManifestToTable(table, imageName, tagName, &img.Manifests[0], maxPlatformLen, verbose)
return addManifestToTable(table, imageName, tagName, &img.Manifests[0], verbose)
case ispec.MediaTypeImageIndex:
return addImageIndexToTable(table, img, maxPlatformLen, imageName, tagName, verbose)
return addImageIndexToTable(table, img, imageName, tagName, verbose)
}
return nil
}
func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatformLen int,
func addImageIndexToTable(table *tablewriter.Table, img *imageStruct,
imageName, tagName string, verbose bool,
) error {
indexDigest, err := godigest.Parse(img.Digest)
@@ -1194,10 +1196,10 @@ func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatfor
row[colLayersIndex] = ""
}
table.Append(row)
table.Append(row) //nolint:errcheck
for i := range img.Manifests {
err := addManifestToTable(table, "", "", &img.Manifests[i], maxPlatformLen, verbose)
err := addManifestToTable(table, "", "", &img.Manifests[i], verbose)
if err != nil {
return err
}
@@ -1207,7 +1209,7 @@ func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatfor
}
func addManifestToTable(table *tablewriter.Table, imageName, tagName string, manifest *common.ManifestSummary,
maxPlatformLen int, verbose bool,
verbose bool,
) error {
manifestDigest, err := godigest.Parse(manifest.Digest)
if err != nil {
@@ -1220,12 +1222,6 @@ func addManifestToTable(table *tablewriter.Table, imageName, tagName string, man
}
platform := getPlatformStr(manifest.Platform)
if maxPlatformLen > len(platform) {
offset := strings.Repeat(" ", maxPlatformLen-len(platform))
platform += offset
}
manifestDigestStr := ellipsize(manifestDigest.Encoded(), digestWidth, "")
configDigestStr := ellipsize(configDigest.Encoded(), configWidth, "")
imgSize, _ := strconv.ParseUint(manifest.Size, 10, 64)
@@ -1245,7 +1241,7 @@ func addManifestToTable(table *tablewriter.Table, imageName, tagName string, man
row[colLayersIndex] = ""
}
table.Append(row)
table.Append(row) //nolint:errcheck
if verbose {
for _, entry := range manifest.Layers {
@@ -1268,7 +1264,7 @@ func addManifestToTable(table *tablewriter.Table, imageName, tagName string, man
layerRow[colConfigIndex] = ""
layerRow[colLayersIndex] = layerDigestStr
table.Append(layerRow)
table.Append(layerRow) //nolint:errcheck
}
}
@@ -1346,81 +1342,18 @@ func ellipsize(text string, maxLength int, trailing string) string {
return text[:maxLength-chopLength] + trailing
}
func getImageTableWriter(writer io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(writer)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding(" ")
table.SetNoWhiteSpace(true)
return table
}
func getCVETableWriter(writer io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(writer)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding(" ")
table.SetNoWhiteSpace(true)
table.SetColMinWidth(colCVEIDIndex, cveIDWidth)
table.SetColMinWidth(colCVESeverityIndex, cveSeverityWidth)
table.SetColMinWidth(colCVETitleIndex, cveTitleWidth)
table.SetColMinWidth(colCVEVulnPkgNameIndex, cveVulnPkgNameWidth)
table.SetColMinWidth(colCVEVulnPkgPathIndex, cveVulnPkgPathWidth)
table.SetColMinWidth(colCVEVulnPkgInstalledVerIndex, cveVulnPkgInstalledVerWidth)
table.SetColMinWidth(colCVEVulnPkgFixedVerIndex, cveVulnPkgFixedVerWidth)
return table
}
func getReferrersTableWriter(writer io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(writer)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding(" ")
table.SetNoWhiteSpace(true)
return table
}
func getRepoTableWriter(writer io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(writer)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding(" ")
table.SetNoWhiteSpace(true)
table := getCommonTableWriter(writer)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(colCVEIDIndex, cveIDWidth).
Set(colCVESeverityIndex, cveSeverityWidth).
Set(colCVETitleIndex, cveTitleWidth).
Set(colCVEVulnPkgNameIndex, cveVulnPkgNameWidth).
Set(colCVEVulnPkgPathIndex, cveVulnPkgPathWidth).
Set(colCVEVulnPkgInstalledVerIndex, cveVulnPkgInstalledVerWidth).
Set(colCVEVulnPkgFixedVerIndex, cveVulnPkgFixedVerWidth)),
)
return table
}
@@ -1472,9 +1405,9 @@ const (
imageNameWidth = 10
tagWidth = 8
digestWidth = 8
platformWidth = 14
platformWidth = 16
sizeWidth = 10
isSignedWidth = 8
isSignedWidth = 6
downloadsWidth = 10
signedWidth = 10
lastUpdatedWidth = 14
+97 -59
View File
@@ -14,6 +14,8 @@ import (
"time"
"github.com/briandowns/spinner"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
"github.com/spf13/cobra"
zerr "zotregistry.dev/zot/errors"
@@ -128,47 +130,82 @@ type stringResult struct {
type printHeader func(writer io.Writer, verbose bool, maxImageNameLen, maxTagLen, maxPlatformLen int)
func getCommonTableWriter(writer io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(writer)
symbols := tw.NewSymbolCustom("Spaces").
WithRow("").
WithColumn(" ").
WithTopLeft("").
WithTopMid("").
WithTopRight("").
WithMidLeft("").
WithCenter("").
WithMidRight("").
WithBottomLeft("").
WithBottomMid("").
WithBottomRight("")
table.Options(
tablewriter.WithRendition(tw.Rendition{
Borders: tw.Border{
Left: tw.Off,
Right: tw.Off,
Top: tw.Off,
Bottom: tw.Off,
},
Symbols: symbols,
Settings: tw.Settings{
Separators: tw.Separators{
ShowHeader: tw.Off,
ShowFooter: tw.Off,
BetweenRows: tw.Off,
BetweenColumns: tw.On,
},
},
}),
tablewriter.WithPadding(tw.Padding{
Left: "",
Right: "",
}),
tablewriter.WithHeaderAlignment(tw.AlignLeft),
tablewriter.WithRowAlignment(tw.AlignLeft),
)
return table
}
func printImageTableHeader(writer io.Writer, verbose bool, maxImageNameLen, maxTagLen, maxPlatformLen int) {
table := getImageTableWriter(writer)
tagLen := max(len("TAG"), maxTagLen, tagWidth)
imageNameLen := max(len("REPOSITORY"), maxImageNameLen, imageNameWidth)
platformLen := max(len("OS/ARCH"), maxPlatformLen, platformWidth)
configLen := configWidth
layersLen := layersWidth
table.SetColMinWidth(colImageNameIndex, imageNameWidth)
table.SetColMinWidth(colTagIndex, tagWidth)
table.SetColMinWidth(colPlatformIndex, platformWidth)
table.SetColMinWidth(colDigestIndex, digestWidth)
table.SetColMinWidth(colSizeIndex, sizeWidth)
table.SetColMinWidth(colIsSignedIndex, isSignedWidth)
if verbose {
table.SetColMinWidth(colConfigIndex, configWidth)
table.SetColMinWidth(colLayersIndex, layersWidth)
if !verbose {
// Ths hides the columns effectively, 0 links the neighboring columns together
configLen = 1
layersLen = 1
}
table := getCommonTableWriter(writer)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(colImageNameIndex, imageNameLen).
Set(colTagIndex, tagLen).
Set(colPlatformIndex, platformLen).
Set(colDigestIndex, digestWidth).
Set(colSizeIndex, sizeWidth).
Set(colIsSignedIndex, isSignedWidth).
Set(colConfigIndex, configLen).
Set(colLayersIndex, layersLen)),
)
row := make([]string, 8) //nolint:mnd
// adding spaces so that repository and tag columns are aligned
// in case the name/tag are fully shown and too long
var offset string
if maxImageNameLen > len("REPOSITORY") {
offset = strings.Repeat(" ", maxImageNameLen-len("REPOSITORY"))
row[colImageNameIndex] = "REPOSITORY" + offset
} else {
row[colImageNameIndex] = "REPOSITORY"
}
if maxTagLen > len("TAG") {
offset = strings.Repeat(" ", maxTagLen-len("TAG"))
row[colTagIndex] = "TAG" + offset
} else {
row[colTagIndex] = "TAG"
}
if maxPlatformLen > len("OS/ARCH") {
offset = strings.Repeat(" ", maxPlatformLen-len("OS/ARCH"))
row[colPlatformIndex] = "OS/ARCH" + offset
} else {
row[colPlatformIndex] = "OS/ARCH"
}
row[colImageNameIndex] = "REPOSITORY"
row[colTagIndex] = "TAG"
row[colPlatformIndex] = "OS/ARCH"
row[colDigestIndex] = "DIGEST"
row[colSizeIndex] = sizeColumn
row[colIsSignedIndex] = "SIGNED"
@@ -178,8 +215,8 @@ func printImageTableHeader(writer io.Writer, verbose bool, maxImageNameLen, maxT
row[colLayersIndex] = "LAYERS"
}
table.Append(row)
table.Render()
table.Append(row) //nolint:errcheck
table.Render() //nolint:errcheck
}
func printCVETableHeader(writer io.Writer) {
@@ -189,8 +226,8 @@ func printCVETableHeader(writer io.Writer) {
"VULNERABLE PACKAGE", "PATH", "INSTALL-VER", "FIXED-VER",
}
table.Append(columnHeadingsRow)
table.Render()
table.Append(columnHeadingsRow) //nolint:errcheck
table.Render() //nolint:errcheck
}
func printReferrersTableHeader(config SearchConfig, writer io.Writer, maxArtifactTypeLen int) {
@@ -198,11 +235,13 @@ func printReferrersTableHeader(config SearchConfig, writer io.Writer, maxArtifac
return
}
table := getReferrersTableWriter(writer)
table.SetColMinWidth(refArtifactTypeIndex, maxArtifactTypeLen)
table.SetColMinWidth(refDigestIndex, digestWidth)
table.SetColMinWidth(refSizeIndex, sizeWidth)
table := getCommonTableWriter(writer)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(refArtifactTypeIndex, maxArtifactTypeLen).
Set(refDigestIndex, digestWidth).
Set(refSizeIndex, sizeWidth)),
)
row := make([]string, refRowWidth)
@@ -220,22 +259,21 @@ func printReferrersTableHeader(config SearchConfig, writer io.Writer, maxArtifac
row[refDigestIndex] = "DIGEST"
row[refSizeIndex] = sizeColumn
table.Append(row)
table.Render()
table.Append(row) //nolint:errcheck
table.Render() //nolint:errcheck
}
func printRepoTableHeader(writer io.Writer, repoMaxLen, maxTimeLen int, verbose bool) {
table := getRepoTableWriter(writer)
table.SetColMinWidth(repoNameIndex, repoMaxLen)
table.SetColMinWidth(repoSizeIndex, sizeWidth)
table.SetColMinWidth(repoLastUpdatedIndex, maxTimeLen)
table.SetColMinWidth(repoDownloadsIndex, sizeWidth)
table.SetColMinWidth(repoStarsIndex, sizeWidth)
if verbose {
table.SetColMinWidth(repoPlatformsIndex, platformWidth)
}
table := getCommonTableWriter(writer)
table.Options(
tablewriter.WithColumnWidths(tw.NewMapper[int, int]().
Set(repoNameIndex, repoMaxLen).
Set(repoSizeIndex, sizeWidth).
Set(repoLastUpdatedIndex, maxTimeLen).
Set(repoDownloadsIndex, downloadsWidth).
Set(repoStarsIndex, signedWidth).
Set(repoPlatformsIndex, platformWidth)),
)
row := make([]string, repoRowWidth)
@@ -265,8 +303,8 @@ func printRepoTableHeader(writer io.Writer, repoMaxLen, maxTimeLen int, verbose
row[repoPlatformsIndex] = "PLATFORMS"
}
table.Append(row)
table.Render()
table.Append(row) //nolint:errcheck
table.Render() //nolint:errcheck
}
func printReferrersResult(config SearchConfig, referrersList referrersResult, maxArtifactTypeLen int) error {
+3
View File
@@ -112,6 +112,9 @@ func newScrubCmd(conf *config.Config) *cobra.Command {
return nil
}
// Do not show usage on errors which are not related to cummand line arguments
cmd.SilenceUsage = true
// checking if the server is already running
req, err := http.NewRequestWithContext(context.Background(),
http.MethodGet,