Local prune: garden.Prune() removes orphaned blobs. 2 tests. CLI commands: sgard push, sgard pull (with SSH auth via --ssh-key or ssh-agent), sgard prune (local by default, remote with --remote). Server daemon: cmd/sgardd with --listen, --repo, --authorized-keys flags. Runs gRPC server with optional SSH key auth interceptor. Root command gains --remote and --ssh-key persistent flags with resolveRemote() (flag > env > repo/remote file). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/kisom/sgard/client"
|
|
"github.com/kisom/sgard/garden"
|
|
"github.com/spf13/cobra"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
var pushCmd = &cobra.Command{
|
|
Use: "push",
|
|
Short: "Push local checkpoint to remote server",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
addr, err := resolveRemote()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
g, err := garden.Open(repoFlag)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signer, err := client.LoadSigner(sshKeyFlag)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
creds := client.NewSSHCredentials(signer)
|
|
conn, err := grpc.NewClient(addr,
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
grpc.WithPerRPCCredentials(creds),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("connecting to %s: %w", addr, err)
|
|
}
|
|
defer func() { _ = conn.Close() }()
|
|
|
|
c := client.New(conn)
|
|
pushed, err := c.Push(context.Background(), g)
|
|
if errors.Is(err, client.ErrServerNewer) {
|
|
fmt.Println("Server is newer; run sgard pull instead.")
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("Pushed %d blob(s).\n", pushed)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(pushCmd)
|
|
}
|