mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
pkg/stringid: remove deprecated IsShortID, ValidateID
- `IsShortID` was deprecated in2100a70741- `ValidateID` was deprecated ine19e6cf7f4Both are part of 27.0, so we can remove these. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -4,8 +4,6 @@ package stringid // import "github.com/docker/docker/pkg/stringid"
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -15,22 +13,6 @@ const (
|
||||
fullLen = 64
|
||||
)
|
||||
|
||||
var (
|
||||
validShortID = regexp.MustCompile("^[a-f0-9]{12}$")
|
||||
validHex = regexp.MustCompile(`^[a-f0-9]{64}$`)
|
||||
)
|
||||
|
||||
// IsShortID determines if id has the correct format and length for a short ID.
|
||||
// It checks the IDs length and if it consists of valid characters for IDs (a-f0-9).
|
||||
//
|
||||
// Deprecated: this function is no longer used, and will be removed in the next release.
|
||||
func IsShortID(id string) bool {
|
||||
if len(id) != shortLen {
|
||||
return false
|
||||
}
|
||||
return validShortID.MatchString(id)
|
||||
}
|
||||
|
||||
// TruncateID returns a shorthand version of a string identifier for convenience.
|
||||
// A collision with other shorthands is very unlikely, but possible.
|
||||
// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller
|
||||
@@ -62,16 +44,3 @@ func GenerateRandomID() string {
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateID checks whether an ID string is a valid, full-length image ID.
|
||||
//
|
||||
// Deprecated: use [github.com/docker/docker/image/v1.ValidateID] instead. Will be removed in the next release.
|
||||
func ValidateID(id string) error {
|
||||
if len(id) != fullLen {
|
||||
return errors.New("image ID '" + id + "' is invalid")
|
||||
}
|
||||
if !validHex.MatchString(id) {
|
||||
return errors.New("image ID '" + id + "' is invalid")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package stringid // import "github.com/docker/docker/pkg/stringid"
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -44,46 +43,3 @@ func TestShortenIdInvalid(t *testing.T) {
|
||||
t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsShortIDNonHex(t *testing.T) {
|
||||
id := "some non-hex value"
|
||||
if IsShortID(id) {
|
||||
t.Fatalf("%s is not a short ID", id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsShortIDNotCorrectSize(t *testing.T) {
|
||||
id := strings.Repeat("a", shortLen+1)
|
||||
if IsShortID(id) {
|
||||
t.Fatalf("%s is not a short ID", id)
|
||||
}
|
||||
id = strings.Repeat("a", shortLen-1)
|
||||
if IsShortID(id) {
|
||||
t.Fatalf("%s is not a short ID", id)
|
||||
}
|
||||
}
|
||||
|
||||
var testIDs = []string{
|
||||
"4e38e38c8ce0",
|
||||
strings.Repeat("a", shortLen+1),
|
||||
strings.Repeat("a", 16000),
|
||||
"90435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a2",
|
||||
}
|
||||
|
||||
func BenchmarkIsShortID(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, id := range testIDs {
|
||||
_ = IsShortID(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkValidateID(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, id := range testIDs {
|
||||
_ = ValidateID(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user