예제 #1
0
파일: tcp.go 프로젝트: atmosx/log-courier
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\n", err)
			}
			rest := pemdata
			var block *pem.Block
			var pemBlockNum = 1
			for {
				block, rest = pem.Decode(rest)
				if block != nil {
					if block.Type != "CERTIFICATE" {
						return nil, fmt.Errorf("Block %d does not contain a certificate: %s\n", pemBlockNum, ret.SSLCA)
					}
					cert, err := x509.ParseCertificate(block.Bytes)
					if err != nil {
						return nil, fmt.Errorf("Failed to parse CA certificate in block %d: %s\n", pemBlockNum, ret.SSLCA)
					}
					ret.tls_config.RootCAs.AddCert(cert)
					pemBlockNum += 1
				} else {
					break
				}
			}
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
예제 #2
0
파일: zmq.go 프로젝트: atmosx/log-courier
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 err := ret.processConfig(config_path); err != nil {
			return nil, err
		}

		return ret, nil
	}

	// Don't allow curve settings
	if _, ok := unused["CurveServerkey"]; ok {
		goto CheckUnused
	}
	if _, ok := unused["CurvePublickey"]; ok {
		goto CheckUnused
	}
	if _, ok := unused["CurveSecretkey"]; ok {
		goto CheckUnused
	}

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

	if ret.PeerSendQueue == 0 {
		ret.PeerSendQueue = default_NetworkConfig_PeerSendQueue
	}

CheckUnused:
	if err := config.ReportUnusedConfig(config_path, unused); err != nil {
		return nil, err
	}

	return ret, nil
}
예제 #3
0
파일: plain.go 프로젝트: atmosx/log-courier
func NewPlainCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	if err := config.ReportUnusedConfig(config_path, unused); err != nil {
		return nil, err
	}
	return &CodecPlainFactory{}, nil
}