github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/tunnel/provider.go (about) 1 package tunnel 2 3 import ( 4 "context" 5 6 "google.golang.org/grpc" 7 8 "github.com/telepresenceio/telepresence/rpc/v2/agent" 9 "github.com/telepresenceio/telepresence/rpc/v2/connector" 10 rpc "github.com/telepresenceio/telepresence/rpc/v2/manager" 11 ) 12 13 type Client interface { 14 Send(*rpc.TunnelMessage) error 15 Recv() (*rpc.TunnelMessage, error) 16 grpc.ClientStream 17 } 18 19 type Provider interface { 20 Tunnel(ctx context.Context, opts ...grpc.CallOption) (Client, error) 21 } 22 23 type mgrProvider struct { 24 rpc.ManagerClient 25 } 26 27 func (m mgrProvider) Tunnel(ctx context.Context, opts ...grpc.CallOption) (Client, error) { 28 return m.ManagerClient.Tunnel(ctx, opts...) 29 } 30 31 func ManagerProvider(m rpc.ManagerClient) Provider { 32 return mgrProvider{m} 33 } 34 35 type mgrProxyProvider struct { 36 connector.ManagerProxyClient 37 } 38 39 func (m mgrProxyProvider) Tunnel(ctx context.Context, opts ...grpc.CallOption) (Client, error) { 40 return m.ManagerProxyClient.Tunnel(ctx, opts...) 41 } 42 43 func ManagerProxyProvider(m connector.ManagerProxyClient) Provider { 44 return mgrProxyProvider{m} 45 } 46 47 type agentProvider struct { 48 agent.AgentClient 49 } 50 51 func (m agentProvider) Tunnel(ctx context.Context, opts ...grpc.CallOption) (Client, error) { 52 return m.AgentClient.Tunnel(ctx, opts...) 53 } 54 55 func AgentProvider(a agent.AgentClient) Provider { 56 return agentProvider{a} 57 }