mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-25 01:44:43 +01:00
1df0f8912a
It may be desirable to check that a config is valid without checking for the existence of certificate files (e.g. when validating a config inside a sandbox without access to the cert files). This will be very useful for NixOS so that we can check the config file at nix-build time (e.g. potentially without proper permissions to read cert files for a TLS connection). fixes https://github.com/zrepl/zrepl/issues/467 closes https://github.com/zrepl/zrepl/pull/587
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
// Package fromconfig instantiates transports based on zrepl config structures
|
|
// (see package config).
|
|
package fromconfig
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"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"
|
|
)
|
|
|
|
func ListenerFactoryFromConfig(g *config.Global, in config.ServeEnum, parseFlags config.ParseFlags) (transport.AuthenticatedListenerFactory, error) {
|
|
|
|
var (
|
|
l transport.AuthenticatedListenerFactory
|
|
err error
|
|
)
|
|
switch v := in.Ret.(type) {
|
|
case *config.TCPServe:
|
|
l, err = tcp.TCPListenerFactoryFromConfig(g, v)
|
|
case *config.TLSServe:
|
|
l, err = tls.TLSListenerFactoryFromConfig(g, v, parseFlags)
|
|
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
|
|
}
|
|
|
|
func ConnecterFromConfig(g *config.Global, in config.ConnectEnum, parseFlags config.ParseFlags) (transport.Connecter, error) {
|
|
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:
|
|
connecter, err = tls.TLSConnecterFromConfig(v, parseFlags)
|
|
case *config.LocalConnect:
|
|
connecter, err = local.LocalConnecterFromConfig(v)
|
|
default:
|
|
panic(fmt.Sprintf("implementation error: unknown connecter type %T", v))
|
|
}
|
|
|
|
return connecter, err
|
|
}
|