Exemple #1
0
/* Initialize a set of validator used throughout the Haproxy package

Validators are used on the side of the API but also internally to check validity
of generated artifacts like socket paths.
*/
func init() {

	// validation for route names. Should be ascii, alphanumeric but allowing - _ . (dash, underscore, period)
	valid.TagMap["routeName"] = valid.Validator(func(str string) bool {

		pattern := "^[a-zA-Z0-9]{1}[a-zA-Z0-9.\\-_]{3,63}$"
		routeName := regexp.MustCompile(pattern)
		return routeName.MatchString(str)
	})

	// validation for route names. Should be ascii, alphanumeric but allowing - _ . : (dash, underscore, period, colon)
	valid.TagMap["filterName"] = valid.Validator(func(str string) bool {

		pattern := "^[a-zA-Z0-9]{1}[a-zA-Z0-9:.\\-_]{3,63}$"
		routeName := regexp.MustCompile(pattern)
		return routeName.MatchString(str)
	})

	// validation for full sockets paths. These cannot be longer than 103 characters.
	valid.TagMap["socketPath"] = valid.Validator(func(str string) bool {

		pattern := "^[a-zA-Z0-9/]{1}[a-zA-Z0-9.\\-_/]{1,102}$"
		socketPath := regexp.MustCompile(pattern)
		return socketPath.MatchString(str)
	})
}
Exemple #2
0
// Slug name validator
func init() {
	govalidator.TagMap["slug"] = govalidator.Validator(func(str string) bool {
		return slugRegexp.MatchString(str)
	})

	col := C(applicationCollection)
	defer col.Database.Session.Close()

	// App Index
	col.EnsureIndex(mgo.Index{
		Key:        []string{"name"},
		Unique:     true,
		DropDups:   true,
		Background: true, // See notes.
		Sparse:     true,
	})
}
func CustomValidators(c *web.C, h http.Handler) http.Handler {
	handler := func(w http.ResponseWriter, r *http.Request) {
		// ISO 8601 Validator
		v.TagMap["iso8601"] = v.Validator(func(str string) bool {
			_, err := time.Parse(time.RFC3339, str)
			if err != nil {
				return false
			}

			return true
		})

		h.ServeHTTP(w, r)
	}

	return http.HandlerFunc(handler)
}
Exemple #4
0
func init() {

	col := C(accessCollection)
	defer col.Database.Session.Close()

	// Name Index
	col.EnsureIndex(mgo.Index{
		Key:        []string{"type"},
		Unique:     true,
		DropDups:   true,
		Background: true, // See notes.
		Sparse:     true,
	})

	govalidator.TagMap["access_provider"] = govalidator.Validator(func(str string) bool {

		if str == "ec2" || str == "do" {
			return true
		}
		return false
	})
}
Exemple #5
0
func init() {

	govalidator.TagMap["nagios_plugin"] = govalidator.Validator(func(str string) bool {
		for _, p := range NagiosPlugins {
			if str == p {
				return true
			}
		}
		return false
	})

	// govalidator.TagMap["cond_type"] = govalidator.Validator(func(str string) bool {
	// 	for _, c := range CondTypes {
	// 		if str == c {
	// 			return true
	// 		}
	// 	}
	// 	return false
	// })
	//
	// govalidator.TagMap["http_proto"] = govalidator.Validator(func(str string) bool {
	// 	for _, p := range []string{"http", "https"} {
	// 		if str == p {
	// 			return true
	// 		}
	// 	}
	// 	return false
	// })
	//
	// govalidator.TagMap["http_path"] = govalidator.Validator(func(str string) bool {
	//
	// 	if _, err := url.Parse(str); err != nil {
	// 		return false
	// 	}
	// 	return true
	// })
	//
	// govalidator.TagMap["http_hostname"] = govalidator.Validator(func(str string) bool {
	//
	// 	return hostnameRegexp.MatchString(str)
	// })

	govalidator.TagMap["target_type"] = govalidator.Validator(func(str string) bool {
		for _, c := range TargetTypes {
			if str == c {
				return true
			}
		}
		return false
	})

	// col := C(alertPolicyCollection)
	// defer col.Database.Session.Close()

	// // Name Index
	// col.EnsureIndex(mgo.Index{
	// 	Key:        []string{"name"},
	// 	Unique:     true,
	// 	DropDups:   true,
	// 	Background: true, // See notes.
	// 	Sparse:     true,
	// })
}
Exemple #6
-1
func init() {
	valid.CustomTypeTagMap.Set("btw_zero_and_one", valid.CustomTypeValidator(btwZeroAndOne))
	valid.CustomTypeTagMap.Set("greater_zero", valid.CustomTypeValidator(greaterZeroValidator))
	valid.CustomTypeTagMap.Set("environment", valid.CustomTypeValidator(envValidator))

	valid.TagMap["email_val"] = valid.Validator(emailValidator)
}