Skip to content

Commit 3567020

Browse files
Merge pull request containerd#3798 from estesp/common-indentifiers
Common identifiers validation
2 parents 4d77395 + fdf7a79 commit 3567020

File tree

7 files changed

+11
-162
lines changed

7 files changed

+11
-162
lines changed

events/exchange/exchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func validateTopic(topic string) error {
225225
}
226226

227227
func validateEnvelope(envelope *events.Envelope) error {
228-
if err := namespaces.Validate(envelope.Namespace); err != nil {
228+
if err := identifiers.Validate(envelope.Namespace); err != nil {
229229
return errors.Wrapf(err, "event envelope has invalid namespace")
230230
}
231231

identifiers/validate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ var (
4242
identifierRe = regexp.MustCompile(reAnchor(alphanum + reGroup(separators+reGroup(alphanum)) + "*"))
4343
)
4444

45-
// Validate return nil if the string s is a valid identifier.
45+
// Validate returns nil if the string s is a valid identifier.
4646
//
47-
// identifiers must be valid domain names according to RFC 1035, section 2.3.1. To
48-
// enforce case insensitivity, all characters must be lower case.
47+
// identifiers are similar to the domain name rules according to RFC 1035, section 2.3.1. However
48+
// rules in this package are relaxed to allow numerals to follow period (".") and mixed case is
49+
// allowed.
4950
//
50-
// In general, identifiers that pass this validation, should be safe for use as
51-
// a domain names or filesystem path component.
51+
// In general identifiers that pass this validation should be safe for use as filesystem path components.
5252
func Validate(s string) error {
5353
if len(s) == 0 {
5454
return errors.Wrapf(errdefs.ErrInvalidArgument, "identifier must not be empty")

identifiers/validate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestValidIdentifiers(t *testing.T) {
3434
"swarmkit.docker.io",
3535
"0912341234",
3636
"task.0.0123456789",
37+
"container.system-75-f19a.00",
3738
"underscores_are_allowed",
3839
strings.Repeat("a", maxLength),
3940
} {

metadata/namespaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/containerd/containerd/errdefs"
23+
"github.com/containerd/containerd/identifiers"
2324
l "github.com/containerd/containerd/labels"
2425
"github.com/containerd/containerd/namespaces"
2526
"github.com/pkg/errors"
@@ -41,7 +42,7 @@ func (s *namespaceStore) Create(ctx context.Context, namespace string, labels ma
4142
return err
4243
}
4344

44-
if err := namespaces.Validate(namespace); err != nil {
45+
if err := identifiers.Validate(namespace); err != nil {
4546
return err
4647
}
4748

namespaces/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222

2323
"github.com/containerd/containerd/errdefs"
24+
"github.com/containerd/containerd/identifiers"
2425
"github.com/pkg/errors"
2526
)
2627

@@ -70,7 +71,7 @@ func NamespaceRequired(ctx context.Context) (string, error) {
7071
if !ok || namespace == "" {
7172
return "", errors.Wrapf(errdefs.ErrFailedPrecondition, "namespace is required")
7273
}
73-
if err := Validate(namespace); err != nil {
74+
if err := identifiers.Validate(namespace); err != nil {
7475
return "", errors.Wrap(err, "namespace validation")
7576
}
7677
return namespace, nil

namespaces/validate.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

namespaces/validate_test.go

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)