2018-12-11 22:01:50 +01:00
|
|
|
// Package fromconfig instantiates transports based on zrepl config structures
|
|
|
|
// (see package config).
|
|
|
|
package fromconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-12-11 22:01:50 +01:00
|
|
|
"github.com/pkg/errors"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-12-11 22:01:50 +01:00
|
|
|
"github.com/zrepl/zrepl/config"
|
|
|
|
"github.com/zrepl/zrepl/transport"
|
|
|
|
"github.com/zrepl/zrepl/transport/local"
|
|
|
|
"github.com/zrepl/zrepl/transport/ssh"
|
|
|
|
"github.com/zrepl/zrepl/transport/tcp"
|
|
|
|
"github.com/zrepl/zrepl/transport/tls"
|
|
|
|
)
|
|
|
|
|
2022-03-30 04:39:10 +02:00
|
|
|
func ListenerFactoryFromConfig(g *config.Global, in config.ServeEnum, parseFlags config.ParseFlags) (transport.AuthenticatedListenerFactory, error) {
|
2018-12-11 22:01:50 +01:00
|
|
|
|
|
|
|
var (
|
2019-03-22 19:41:12 +01:00
|
|
|
l transport.AuthenticatedListenerFactory
|
2018-12-11 22:01:50 +01:00
|
|
|
err error
|
|
|
|
)
|
|
|
|
switch v := in.Ret.(type) {
|
|
|
|
case *config.TCPServe:
|
|
|
|
l, err = tcp.TCPListenerFactoryFromConfig(g, v)
|
|
|
|
case *config.TLSServe:
|
2022-03-30 04:39:10 +02:00
|
|
|
l, err = tls.TLSListenerFactoryFromConfig(g, v, parseFlags)
|
2018-12-11 22:01:50 +01:00
|
|
|
case *config.StdinserverServer:
|
|
|
|
l, err = ssh.MultiStdinserverListenerFactoryFromConfig(g, v)
|
|
|
|
case *config.LocalServe:
|
|
|
|
l, err = local.LocalListenerFactoryFromConfig(g, v)
|
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("internal error: unknown serve type %T", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return l, err
|
|
|
|
}
|
|
|
|
|
2022-03-30 04:39:10 +02:00
|
|
|
func ConnecterFromConfig(g *config.Global, in config.ConnectEnum, parseFlags config.ParseFlags) (transport.Connecter, error) {
|
2018-12-11 22:01:50 +01:00
|
|
|
var (
|
|
|
|
connecter transport.Connecter
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
switch v := in.Ret.(type) {
|
|
|
|
case *config.SSHStdinserverConnect:
|
|
|
|
connecter, err = ssh.SSHStdinserverConnecterFromConfig(v)
|
|
|
|
case *config.TCPConnect:
|
|
|
|
connecter, err = tcp.TCPConnecterFromConfig(v)
|
|
|
|
case *config.TLSConnect:
|
2022-03-30 04:39:10 +02:00
|
|
|
connecter, err = tls.TLSConnecterFromConfig(v, parseFlags)
|
2018-12-11 22:01:50 +01:00
|
|
|
case *config.LocalConnect:
|
|
|
|
connecter, err = local.LocalConnecterFromConfig(v)
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("implementation error: unknown connecter type %T", v))
|
|
|
|
}
|
|
|
|
|
|
|
|
return connecter, err
|
|
|
|
}
|