func validateClientName(name string) util.Gerror { if !util.ValidateName(name) { err := util.Errorf("Invalid client name '%s' using regex: 'Malformed client name. Must be A-Z, a-z, 0-9, _, -, or .'.", name) return err } return nil }
// New creates a new cookbook. func New(name string) (*Cookbook, util.Gerror) { var found bool if !util.ValidateName(name) { err := util.Errorf("Invalid cookbook name '%s' using regex: 'Malformed cookbook name. Must only contain A-Z, a-z, 0-9, _ or -'.", name) return nil, err } if config.UsingDB() { var cerr error found, cerr = checkForCookbookSQL(datastore.Dbh, name) if cerr != nil { err := util.CastErr(cerr) err.SetStatus(http.StatusInternalServerError) return nil, err } } else { ds := datastore.New() _, found = ds.Get("cookbook", name) } if found { err := util.Errorf("Cookbook %s already exists", name) err.SetStatus(http.StatusConflict) } cookbook := &Cookbook{ Name: name, Versions: make(map[string]*CookbookVersion), } return cookbook, nil }