Browse Source

Fix sha issue fully

master
IamTheFij 10 months ago
parent
commit
2ad1a94f4f
  1. 5
      main.go
  2. 34
      main_test.go

5
main.go

@ -24,7 +24,8 @@ var (
maxPages = 10
// Regexp used to extract tag information
tagRegexp = regexp.MustCompile(`(.*):[vV]{0,1}([0-9.]+)(-([a-zA-Z0-9_-]*)){0,1}(@([:0-9a-z]+)){0,1}`)
// The general format is "(registry/namespace/image):v(version)-(description)@(sha)"
tagRegexp = regexp.MustCompile(`([a-zA-Z0-9-_/.]+):[vV]{0,1}([0-9.]+)(-([a-zA-Z0-9_-]*)){0,1}(@([:0-9a-z]+)){0,1}`)
// version of tag checker
version = "dev"
)
@ -156,6 +157,7 @@ func listTags(current ImageTag) ([]ImageTag, error) {
for url != "" && pageCount <= maxPages {
err = getJSON(url, &response)
if err != nil {
slog.Error("[%s] Could not get JSON response from url %s: %v", current.ImageTag, url, err)
return results, err
}
@ -176,6 +178,7 @@ func getNewerTags(current ImageTag) ([]ImageTag, error) {
newerTags := []ImageTag{}
tags, err := listTags(current)
if err != nil {
slog.Error("[%s] Could not list tags: %v", current.ImageTag, err)
return newerTags, err
}
for _, tag := range tags {

34
main_test.go

@ -21,6 +21,16 @@ func TestTagParsing(t *testing.T) {
ImageTag{},
true,
},
{
"user/image:v1",
ImageTag{
ImageTag: "user/image:v1",
Image: "user/image",
Version: "1",
VersionParts: []int{1},
},
false,
},
{
"image:v1",
ImageTag{
@ -63,28 +73,40 @@ func TestTagParsing(t *testing.T) {
false,
},
{
"image:v1.0.0-desc@sha256:abc",
"image:v1.0.0-desc@sha256:123abc",
ImageTag{
ImageTag: "image:v1.0.0-desc@sha256:abc",
ImageTag: "image:v1.0.0-desc@sha256:123abc",
Image: "library/image",
TagDesc: "desc",
TagSha: "sha256:abc",
TagSha: "sha256:123abc",
Version: "1.0.0",
VersionParts: []int{1, 0, 0},
},
false,
},
{
"image:v1.0.0@sha256:abc",
"image:v1.0.0@sha256:123abc",
ImageTag{
ImageTag: "image:v1.0.0@sha256:abc",
ImageTag: "image:v1.0.0@sha256:123abc",
Image: "library/image",
TagSha: "sha256:abc",
TagSha: "sha256:123abc",
Version: "1.0.0",
VersionParts: []int{1, 0, 0},
},
false,
},
// Real world example that had caused issues
{
"matrixdotorg/synapse:v1.41.0@sha256:75f2b3c35c047693f4f4334d4ceb97951de1ba12bd3c6182c8a2ee624d7c5ab7",
ImageTag{
ImageTag: "matrixdotorg/synapse:v1.41.0@sha256:75f2b3c35c047693f4f4334d4ceb97951de1ba12bd3c6182c8a2ee624d7c5ab7",
Image: "matrixdotorg/synapse",
TagSha: "sha256:75f2b3c35c047693f4f4334d4ceb97951de1ba12bd3c6182c8a2ee624d7c5ab7",
Version: "1.41.0",
VersionParts: []int{1, 41, 0},
},
false,
},
}
for _, c := range cases {

Loading…
Cancel
Save