mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
* Add version check mechanism to gRPC calls
* Use semver not semver/v3
* Give dev builds a special "infinite" version number (999.0.0-dev)
* Handle no metadata on grpc call correctly for version check
* Move versioncheck package to root pkg/ from pkg/api/ since it is shared by both pkg/api/ and pkg/client/
* Only show "no daemon version" warning once
* Append version headers to metadata, not overwrite...
* Unit tests on versioncheck logic
* Move SetHeader to the ServerStream in ServerStreamInterceptor
* Go modernizer nits: interface{} -> any
* Use more conventional gRPC header names for version/min-versions
* Add TODO notes on checkDaemonVersionInResponse and related code that can be removed eventually after transition to version checking client/daemons
* Use testify for testing assertions
* Add explanatory comments on MinCLIVersion and MinDaemonVersion
---------
Co-authored-by: Pasha Sviderski <me@psviderski.name>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package connector
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/psviderski/uncloud/pkg/versioncheck"
|
|
"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()),
|
|
grpc.WithDefaultServiceConfig(defaultServiceConfig),
|
|
grpc.WithUnaryInterceptor(versioncheck.ClientUnaryInterceptor),
|
|
grpc.WithStreamInterceptor(versioncheck.ClientStreamInterceptor),
|
|
)
|
|
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
|
|
}
|