Files
paralus/pkg/auth/v3/pool.go
nirav-rafay c66bdc25cd restructure rcloud-base as a single base controller (#37)
* restructure rcloud-base as a single base controller
* updated master.rest
* moved sentry from internal to pkg as it is used by relay
* removing unused rpc and it's dependencies
* Fix usermgmt tests
* Don't redefine variables in rest file
Co-authored-by: Abin Simon <abin.simon@rafay.co>
2022-03-03 17:59:06 +05:30

61 lines
1.1 KiB
Go

package authv3
import (
"github.com/RafaySystems/rcloud-base/pkg/pool"
rpcv3 "github.com/RafaySystems/rcloud-base/proto/rpc/v3"
"context"
grpcpool "github.com/processout/grpc-go-pool"
)
// AuthPoolClient is the interface for auth pool client
type AuthPoolClient interface {
Unhealthy()
Close() error
rpcv3.AuthClient
}
type authPoolClient struct {
*grpcpool.ClientConn
rpcv3.AuthClient
}
var _ AuthPoolClient = (*authPoolClient)(nil)
// AuthPool maintains pool of grpc connections to auth service
type AuthPool interface {
Close()
NewClient(ctx context.Context) (AuthPoolClient, error)
}
var _ AuthPool = (*authPool)(nil)
type authPool struct {
*pool.GRPCPool
}
func (p *authPool) Close() {
if p.GRPCPool != nil {
p.GRPCPool.Close()
}
}
func (p *authPool) NewClient(ctx context.Context) (AuthPoolClient, error) {
cc, err := p.GetConnection(ctx)
if err != nil {
return nil, err
}
return &authPoolClient{
cc,
rpcv3.NewAuthClient(cc.ClientConn),
}, nil
}
// NewAuthPool returns auth pool
func NewAuthPool(addr string, maxConn int) AuthPool {
return &authPool{
GRPCPool: pool.NewGRPCPool(addr, maxConn, nil),
}
}