Adds ID validation.

Docker-DCO-1.1-Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)
This commit is contained in:
Mrunal Patel 2014-10-31 13:56:53 -07:00 committed by Victor Marmol
parent 47b41a6f5d
commit 66e6806fd2
1 changed files with 10 additions and 0 deletions

View File

@ -4,8 +4,10 @@ package libcontainer
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"regexp"
"github.com/Sirupsen/logrus"
)
@ -15,6 +17,10 @@ const (
stateFilename = "state.json"
)
var (
idRegex = regexp.MustCompile(`^[\w_]{1,1024}$`)
)
// New returns a linux based container factory based in the root directory.
func New(root string, logger *logrus.Logger) (Factory, error) {
if err := os.MkdirAll(root, 0700); err != nil {
@ -37,6 +43,10 @@ type linuxFactory struct {
}
func (l *linuxFactory) Create(id string, config *Config) (Container, error) {
if !idRegex.MatchString(id) {
return nil, newGenericError(fmt.Errorf("Invalid id format: %s ", id), InvalidIdFormat)
}
panic("not implemented")
}