Example #1
0
func NewMultilineCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	var err error

	result := &CodecMultilineFactory{}
	if err = config.PopulateConfig(result, config_path, unused); err != nil {
		return nil, err
	}

	if result.Pattern == "" {
		return nil, errors.New("Multiline codec pattern must be specified.")
	}

	result.matcher, err = regexp.Compile(result.Pattern)
	if err != nil {
		return nil, fmt.Errorf("Failed to compile multiline codec pattern, '%s'.", err)
	}

	if result.What == "" || result.What == "previous" {
		result.what = codecMultiline_What_Previous
	} else if result.What == "next" {
		result.what = codecMultiline_What_Next
	}

	return result, nil
}
Example #2
0
func NewTcpTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportTcpFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	// Only allow SSL configurations if this is "tls"
	if name == "tls" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if len(ret.SSLCertificate) > 0 && len(ret.SSLKey) > 0 {
			cert, err := tls.LoadX509KeyPair(ret.SSLCertificate, ret.SSLKey)
			if err != nil {
				return nil, fmt.Errorf("Failed loading client ssl certificate: %s", err)
			}

			ret.tls_config.Certificates = []tls.Certificate{cert}
		}

		if len(ret.SSLCA) > 0 {
			ret.tls_config.RootCAs = x509.NewCertPool()

			pemdata, err := ioutil.ReadFile(ret.SSLCA)
			if err != nil {
				return nil, fmt.Errorf("Failure reading CA certificate: %s", err)
			}

			block, _ := pem.Decode(pemdata)
			if block == nil {
				return nil, errors.New("Failed to decode CA certificate data")
			}
			if block.Type != "CERTIFICATE" {
				return nil, fmt.Errorf("Specified CA certificate is not a certificate: %s", ret.SSLCA)
			}

			cert, err := x509.ParseCertificate(block.Bytes)
			if err != nil {
				return nil, fmt.Errorf("Failed to parse CA certificate: %s", err)
			}

			ret.tls_config.RootCAs.AddCert(cert)
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
Example #3
0
func NewFilterCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	var err error

	result := &CodecFilterFactory{}
	if err = config.PopulateConfig(result, config_path, unused); err != nil {
		return nil, err
	}

	if len(result.Patterns) == 0 {
		return nil, errors.New("Filter codec pattern must be specified.")
	}

	result.matchers = make([]*regexp.Regexp, len(result.Patterns))
	for k, pattern := range result.Patterns {
		result.matchers[k], err = regexp.Compile(pattern)
		if err != nil {
			return nil, fmt.Errorf("Failed to compile filter codec pattern, '%s'.", err)
		}
	}

	return result, nil
}
Example #4
0
func NewZmqTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportZmqFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	if name == "zmq" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if len(ret.CurveServerkey) == 0 {
			return nil, fmt.Errorf("Option %scurve server key is required", config_path)
		} else if len(ret.CurveServerkey) != 40 || !z85Validate(ret.CurveServerkey) {
			return nil, fmt.Errorf("Option %scurve server key must be a valid 40 character Z85 encoded string", config_path)
		}
		if len(ret.CurvePublickey) == 0 {
			return nil, fmt.Errorf("Option %scurve public key is required", config_path)
		} else if len(ret.CurvePublickey) != 40 || !z85Validate(ret.CurvePublickey) {
			return nil, fmt.Errorf("Option %scurve public key must be a valid 40 character Z85 encoded string", config_path)
		}
		if len(ret.CurveSecretkey) == 0 {
			return nil, fmt.Errorf("Option %scurve secret key is required", config_path)
		} else if len(ret.CurveSecretkey) != 40 || !z85Validate(ret.CurveSecretkey) {
			return nil, fmt.Errorf("Option %scurve secret key must be a valid 40 character Z85 encoded string", config_path)
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}