mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Make PKI data and RunnerFactory public objects (#865)
* Make PKI data and RunnerFactory public objects * removes unnecessary nullRunner object * renames secure factory to point out MTLS
This commit is contained in:
@@ -27,7 +27,7 @@ type mockRunner struct {
|
|||||||
type mockRunnerPool struct {
|
type mockRunnerPool struct {
|
||||||
runners []pool.Runner
|
runners []pool.Runner
|
||||||
generator insecureRunnerFactory
|
generator insecureRunnerFactory
|
||||||
pki *pkiData
|
pki *pool.PKIData
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockRunnerPool(rf insecureRunnerFactory, runnerAddrs []string) *mockRunnerPool {
|
func newMockRunnerPool(rf insecureRunnerFactory, runnerAddrs []string) *mockRunnerPool {
|
||||||
@@ -43,7 +43,7 @@ func newMockRunnerPool(rf insecureRunnerFactory, runnerAddrs []string) *mockRunn
|
|||||||
return &mockRunnerPool{
|
return &mockRunnerPool{
|
||||||
runners: runners,
|
runners: runners,
|
||||||
generator: rf,
|
generator: rf,
|
||||||
pki: &pkiData{},
|
pki: &pool.PKIData{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,28 +16,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pkiData struct {
|
|
||||||
ca string
|
|
||||||
key string
|
|
||||||
cert string
|
|
||||||
}
|
|
||||||
|
|
||||||
type nullRunner struct{}
|
|
||||||
|
|
||||||
func (n *nullRunner) TryExec(ctx context.Context, call pool.RunnerCall) (bool, error) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *nullRunner) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *nullRunner) Address() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var nullRunnerSingleton = new(nullRunner)
|
|
||||||
|
|
||||||
type gRPCRunner struct {
|
type gRPCRunner struct {
|
||||||
// Need a WaitGroup of TryExec in flight
|
// Need a WaitGroup of TryExec in flight
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
@@ -46,16 +24,8 @@ type gRPCRunner struct {
|
|||||||
client pb.RunnerProtocolClient
|
client pb.RunnerProtocolClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// allow factory to be overridden in tests
|
func SecureGRPCRunnerFactory(addr string, pki *pool.PKIData) (pool.Runner, error) {
|
||||||
type secureRunnerFactory func(addr string, cert string, key string, ca string) (pool.Runner, error)
|
conn, client, err := runnerConnection(addr, pki)
|
||||||
|
|
||||||
func secureGRPCRunnerFactory(addr string, cert string, key string, ca string) (pool.Runner, error) {
|
|
||||||
p := &pkiData{
|
|
||||||
cert: cert,
|
|
||||||
key: key,
|
|
||||||
ca: ca,
|
|
||||||
}
|
|
||||||
conn, client, err := runnerConnection(addr, p)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -85,13 +55,13 @@ func (r *gRPCRunner) Close(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runnerConnection(address string, pki *pkiData) (*grpc.ClientConn, pb.RunnerProtocolClient, error) {
|
func runnerConnection(address string, pki *pool.PKIData) (*grpc.ClientConn, pb.RunnerProtocolClient, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var creds credentials.TransportCredentials
|
var creds credentials.TransportCredentials
|
||||||
if pki != nil {
|
if pki != nil {
|
||||||
var err error
|
var err error
|
||||||
creds, err = grpcutil.CreateCredentials(pki.cert, pki.key, pki.ca)
|
creds, err = grpcutil.CreateCredentials(pki.Cert, pki.Key, pki.Ca)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("Unable to create credentials to connect to runner node")
|
logrus.WithError(err).Error("Unable to create credentials to connect to runner node")
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|||||||
@@ -21,6 +21,15 @@ type RunnerPool interface {
|
|||||||
Shutdown(context.Context) error
|
Shutdown(context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PKIData struct {
|
||||||
|
Ca string
|
||||||
|
Key string
|
||||||
|
Cert string
|
||||||
|
}
|
||||||
|
|
||||||
|
// MTLSRunnerFactory represents a factory method for constructing runners using mTLS
|
||||||
|
type MTLSRunnerFactory func(addr string, pki *PKIData) (Runner, error)
|
||||||
|
|
||||||
// Runner is the interface to invoke the execution of a function call on a specific runner
|
// Runner is the interface to invoke the execution of a function call on a specific runner
|
||||||
type Runner interface {
|
type Runner interface {
|
||||||
TryExec(ctx context.Context, call RunnerCall) (bool, error)
|
TryExec(ctx context.Context, call RunnerCall) (bool, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user