identifiers: use common package for identifier validation

A few days ago, we added validation for namespaces. We've decided to
expand these naming rules to include containers. To facilitate this, a
common package `identifiers` now provides a common validation area.
These rules will be extended to apply to task identifiers, snapshot keys
and other areas where user-provided identifiers may be used.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-06-23 16:17:56 -07:00
parent e69423f931
commit 70815af652
9 changed files with 119 additions and 136 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/boltdb/bolt"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/identifiers"
"github.com/containerd/containerd/namespaces"
"github.com/pkg/errors"
)
@@ -77,6 +78,10 @@ func (s *containerStore) Create(ctx context.Context, container containers.Contai
return containers.Container{}, err
}
if err := identifiers.Validate(container.ID); err != nil {
return containers.Container{}, err
}
bkt, err := createContainersBucket(s.tx, namespace)
if err != nil {
return containers.Container{}, err

View File

@@ -4,6 +4,7 @@ import (
"context"
"github.com/boltdb/bolt"
"github.com/containerd/containerd/identifiers"
"github.com/containerd/containerd/namespaces"
)
@@ -21,7 +22,7 @@ func (s *namespaceStore) Create(ctx context.Context, namespace string, labels ma
return err
}
if err := namespaces.Validate(namespace); err != nil {
if err := identifiers.Validate(namespace); err != nil {
return err
}