示例#1
0
// Validator for application creation
func (f ApplicationCreateForm) Validate() *errors.Errors {
	if errs := validator.Validate(&f); errs != nil {
		return errs
	}

	app, err := ApplicationMapper.FetchOne(f.Name)
	if err != nil {
		panic(err)
	}

	if app != nil {
		return errors.New(errors.Error{
			Label: "duplicate_name",
			Field: "name",
			Text:  "Duplicate application name: " + f.Name,
		})
	}

	for _, d := range f.Deps {
		depApp, err := ApplicationMapper.FetchOne(d)
		if err != nil {
			panic(err)
		}

		if depApp == nil {
			return errors.New(errors.Error{
				Label: "invalid_dep",
				Field: "deps",
				Text:  "Invalid dependence: " + d,
			})
		}
	}

	return nil
}
示例#2
0
// Validator for application creation
func (f LogfileCreateForm) Validate() *errors.Errors {
	if errs := validator.Validate(&f); errs != nil {
		return errs
	}

	return nil
}
示例#3
0
// Validator for application creation
func (f AlertPolicyForm) Validate() *errors.Errors {
	if errs := validator.Validate(&f); errs != nil {
		return errs
	}

	if len(f.AlertGroups) == 0 {
		return errors.New(errors.Error{
			Label: "unknown_alert_groups",
			Field: "alert_groups",
			Text:  "Missing alert groups",
		})
	}

	for _, agName := range f.AlertGroups {

		ag, err := AlertGroupMapper.FetchOne(agName)
		if err != nil {
			panic(err)
		}

		if ag == nil {
			return errors.New(errors.Error{
				Label: "unknown_alert_groups",
				Field: "alert_groups",
				Text:  "Unknown alert group: " + agName,
			})
		}
	}

	return nil
}
示例#4
0
文件: access.go 项目: KarhuTeam/Karhu
// Validator for application creation
func (f AccessCreateForm) Validate() *errors.Errors {
	if errs := validator.Validate(&f); errs != nil {
		return errs
	}

	a, err := AccessMapper.FetchOne(f.Type)
	if err != nil {
		panic(err)
	}

	if a != nil {
		return errors.New(errors.Error{
			Label: "duplicate_type",
			Field: "type",
			Text:  "Duplicate access type: " + f.Type,
		})
	}

	return nil
}
示例#5
0
文件: node.go 项目: KarhuTeam/Karhu
// Validator for node creation
func (f NodeCreateForm) Validate() *errors.Errors {
	return validator.Validate(&f)
}
示例#6
0
func (f *CreateJobForm) Validate() error {
	return validator.Validate(f)
}