Skip to content

Commit f80aee1

Browse files
authored
add digests flag and detailed arch (#21)
* add digests flag * add variants and features to arch
1 parent e5e312d commit f80aee1

File tree

6 files changed

+92
-72
lines changed

6 files changed

+92
-72
lines changed

cmd/dockertags/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ OPTIONS:
3535
app.Name = "dockertags"
3636
app.Version = version
3737
app.ArgsUsage = "image_name"
38-
3938
app.Usage = "fetch docker image tags"
4039

4140
app.Flags = []cli.Flag{
@@ -74,6 +73,10 @@ OPTIONS:
7473
Name: "password, p",
7574
Usage: "Using -password via CLI is insecure. Be careful.",
7675
},
76+
cli.BoolFlag{
77+
Name: "digests",
78+
Usage: "Show long digests",
79+
},
7780
cli.BoolFlag{
7881
Name: "debug, d",
7982
Usage: "Show debug logs",

internal/report/table.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616

1717
// TableWriter output table format
1818
type TableWriter struct {
19-
Output io.Writer
19+
Output io.Writer
20+
LongDigests bool
2021
}
2122

2223
// Write is
@@ -31,7 +32,11 @@ func (w TableWriter) Write(tags types.ImageTags) (err error) {
3132
var sizes, digests, osArchs []string
3233
for _, datum := range tag.Data {
3334
sizes = append(sizes, getBytesize(datum.Byte))
34-
digests = append(digests, trimHash(datum.Digest))
35+
digest := datum.Digest
36+
if !w.LongDigests {
37+
digest = trimHash(datum.Digest)
38+
}
39+
digests = append(digests, digest)
3540
if datum.Os != "" {
3641
osArchs = append(osArchs, fmt.Sprintf("%s/%s", datum.Os, datum.Arch))
3742
}

pkg/provider/dockerhub/dockerhub.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,27 @@ func (p *DockerHub) summarizeByTagNames(keyDigestMap map[string]types.ImageTag)
158158
func convertUploadImageTag(is tagSummary, img image) types.ImageTag {
159159
uploadedAt, _ := time.Parse(time.RFC3339Nano, is.LastUpdated)
160160
tagNames := []string{is.Name}
161+
archName := concatWithSlash(img.Architecture, img.Features)
162+
archName = concatWithSlash(archName, img.Variant)
161163
return types.ImageTag{
162164
Tags: tagNames,
163165
Data: []types.TagAttr{{
164166
Os: img.Os,
165-
Arch: img.Architecture,
167+
Arch: archName,
166168
Digest: img.Digest,
167169
Byte: img.Size,
168170
}},
169171
UploadedAt: uploadedAt,
170172
}
171173
}
172174

175+
func concatWithSlash(original, adding string) string {
176+
if adding == "" {
177+
return original
178+
}
179+
return original + "/" + adding
180+
}
181+
173182
// getTagResponse returns the tags for a specific repository.
174183
// curl 'https://registry.hub.docker.com/v2/repositories/library/debian/tags/'
175184
func getTagResponse(ctx context.Context, auth dockertypes.AuthConfig, timeout time.Duration, repository string, page int) (tagsResponse, error) {

0 commit comments

Comments
 (0)