コード例 #1
0
ファイル: validate.go プロジェクト: zhaytee/libyaml
func RegisterValidations(v *validator.Validate) error {
	if err := v.RegisterValidation("componentexists", ComponentExistsValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("containerexists", ContainerExistsValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("componentcontainer", ComponentContainerFormatValidation); err != nil {
		return err
	}

	// will handle this in vendor web. this prevents panic from validator.v8 library
	if err := v.RegisterValidation("integrationexists", NoopValidation); err != nil {
		return err
	}

	// will handle this in vendor web. this prevents panic from validator.v8 library
	if err := v.RegisterValidation("externalregistryexists", NoopValidation); err != nil {
		return err
	}

	return nil
}
コード例 #2
0
ファイル: validate.go プロジェクト: zhaytee/libyaml
func ContainerExistsValidation(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
	// validates that the container exists in the root.components.containers slice

	root, ok := topStruct.Interface().(*RootConfig)
	if !ok {
		// this is an issue with the code and really should be a panic
		return true
	}

	var componentName, containerName string

	if fieldKind != reflect.String {
		// this is an issue with the code and really should be a panic
		return true
	}

	containerName = field.String()

	if param != "" {
		componentField, componentKind, ok := v.GetStructFieldOK(currentStructOrField, param)

		if !ok || componentKind != reflect.String {
			// this is an issue with the code and really should be a panic
			return true
		}

		componentName = componentField.String()
	} else {
		parts := strings.SplitN(containerName, ",", 2)

		if len(parts) < 2 {
			// let "componentcontainer" validation handle this case
			return true
		}

		componentName = parts[0]
		containerName = parts[1]
	}

	if !ComponentExists(componentName, root) {
		// let "componentexists" validation handle this case
		return true
	}

	return ContainerExists(componentName, containerName, root)
}
コード例 #3
0
ファイル: validate.go プロジェクト: marccampbell/libyaml
func RegisterValidations(v *validator.Validate) error {
	if err := v.RegisterValidation("configitemwhen", ConfigItemWhenValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("apiversion", SemverValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("semver", SemverValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("componentexists", ComponentExistsValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("containerexists", ContainerExistsValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("componentcontainer", ComponentContainerFormatValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("absolutepath", IsAbsolutePath); err != nil {
		return err
	}

	// will handle this in vendor web. this prevents panic from validator.v8 library
	if err := v.RegisterValidation("integrationexists", NoopValidation); err != nil {
		return err
	}

	// will handle this in vendor web. this prevents panic from validator.v8 library
	if err := v.RegisterValidation("externalregistryexists", NoopValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("bytes", IsBytesValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("bool", IsBoolValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("tcpport", IsTcpPortValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("graphiteretention", GraphiteRetentionFormatValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("graphiteaggregation", GraphiteAggregationFormatValidation); err != nil {
		return err
	}

	if err := v.RegisterValidation("monitorlabelscale", MonitorLabelScaleValidation); err != nil {
		return err
	}

	return nil
}