Skip to content

Commit e19e6cf

Browse files
committed
pkg/stringid: deprecate ValidateID
This function is only used for the legacy v1 image format. Deprecate the function, and make image/v1 self-contained. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 98fecb0 commit e19e6cf

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

image/v1/imagev1.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ package v1 // import "github.com/docker/docker/image/v1"
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
7+
"regexp"
68
"strings"
79

810
"github.com/containerd/log"
911
"github.com/docker/docker/api/types/versions"
1012
"github.com/docker/docker/image"
1113
"github.com/docker/docker/layer"
12-
"github.com/docker/docker/pkg/stringid"
1314
"github.com/opencontainers/go-digest"
1415
)
1516

16-
// noFallbackMinVersion is the minimum version for which v1compatibility
17-
// information will not be marshaled through the Image struct to remove
18-
// blank fields.
19-
const noFallbackMinVersion = "1.8.3"
17+
const (
18+
// noFallbackMinVersion is the minimum version for which v1compatibility
19+
// information will not be marshaled through the Image struct to remove
20+
// blank fields.
21+
noFallbackMinVersion = "1.8.3"
22+
23+
fullLen = 64
24+
)
25+
26+
var validHex = regexp.MustCompile(`^[a-f0-9]{64}$`)
2027

2128
// HistoryFromConfig creates a History struct from v1 configuration JSON
2229
func HistoryFromConfig(imageJSON []byte, emptyLayer bool) (image.History, error) {
@@ -116,5 +123,11 @@ func rawJSON(value interface{}) *json.RawMessage {
116123

117124
// ValidateID checks whether an ID string is a valid image ID.
118125
func ValidateID(id string) error {
119-
return stringid.ValidateID(id)
126+
if len(id) != fullLen {
127+
return errors.New("image ID '" + id + "' is invalid")
128+
}
129+
if !validHex.MatchString(id) {
130+
return errors.New("image ID '" + id + "' is invalid")
131+
}
132+
return nil
120133
}

pkg/stringid/stringid.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func GenerateRandomID() string {
6262
}
6363

6464
// ValidateID checks whether an ID string is a valid, full-length image ID.
65+
//
66+
// Deprecated: use [github.com/docker/docker/image/v1.ValidateID] instead. Will be removed in the next release.
6567
func ValidateID(id string) error {
6668
if len(id) != fullLen {
6769
return errors.New("image ID '" + id + "' is invalid")

0 commit comments

Comments
 (0)