implement CLI init cluster, add SSH and WireGuard cluster connectors

This commit is contained in:
Pavel Sviderski
2024-09-10 13:48:14 +10:00
parent fd314bcf65
commit 9e44d30328
8 changed files with 729 additions and 223 deletions
+41
View File
@@ -0,0 +1,41 @@
package client
import (
"context"
"errors"
"fmt"
"google.golang.org/grpc"
"uncloud/internal/machine/api/pb"
)
type Client struct {
connector Connector
conn *grpc.ClientConn
pb.MachineClient
}
// Connector is an interface for establishing a connection to the machine API.
type Connector interface {
Connect(ctx context.Context) (*grpc.ClientConn, error)
Close() error
}
func New(ctx context.Context, connector Connector) (*Client, error) {
c := &Client{
connector: connector,
}
var err error
c.conn, err = connector.Connect(ctx)
if err != nil {
return nil, fmt.Errorf("connect to machine: %w", err)
}
c.MachineClient = pb.NewMachineClient(c.conn)
return c, nil
}
func (c *Client) Close() error {
err := c.conn.Close()
return errors.Join(err, c.connector.Close())
}