mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat: add CLI connector for unix domain socket (#186)
* feat: Add cli connector for unix domain socket * Update cmd/uncloud/main.go --------- Co-authored-by: Pasha Sviderski <me@psviderski.name>
This commit is contained in:
co-authored by
Pasha Sviderski
parent
e87207eae3
commit
91a09d5d37
@@ -0,0 +1,41 @@
|
||||
package connector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
// UnixConnector establishes a connection to the machine API through a unix domain socket.
|
||||
type UnixConnector struct {
|
||||
socketPath string
|
||||
}
|
||||
|
||||
func NewUnixConnector(socketPath string) *UnixConnector {
|
||||
return &UnixConnector{socketPath: socketPath}
|
||||
}
|
||||
|
||||
func (c *UnixConnector) Connect(_ context.Context) (*grpc.ClientConn, error) {
|
||||
// gRPC uses "unix:path" syntax for unix sockets.
|
||||
target := "unix:" + c.socketPath
|
||||
|
||||
conn, err := grpc.NewClient(
|
||||
target,
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create machine API client: %w", err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (c *UnixConnector) Dialer() (proxy.ContextDialer, error) {
|
||||
return nil, fmt.Errorf("proxy connections are not supported over a unix connection")
|
||||
}
|
||||
|
||||
func (c *UnixConnector) Close() error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user