Files
kopia/cli/command_repository_connect_server.go
Jarek Kowalski 646c325826 Implemented new streaming GRPC protocol for Kopia Repository Server (#789)
* grpcapi: added GPRC API for the repository server

* repo: added transparent retries to GRPC repository client

Normally GRPC reconnects automatically, which can survive server
restarts (minus transient errors).

In our case we're establishing a stream which will be broken and
needs to be restarted after io.EOF is detected.

It safe to do transparent retries for read-only (repo.Repository),
but not safe for write sessions (repo.RepositoryWriter), because the
session may re-connect to different server that won't have the buffered
content write available in memory.
2021-01-28 05:15:12 -08:00

46 lines
1.4 KiB
Go

package cli
import (
"context"
"strings"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
)
var (
connectAPIServerCommand = connectCommand.Command("server", "Connect to a repository API Server.")
connectAPIServerURL = connectAPIServerCommand.Flag("url", "Server URL").Required().String()
connectAPIServerCertFingerprint = connectAPIServerCommand.Flag("server-cert-fingerprint", "Server certificate fingerprint").String()
connectAPIServerUseGRPCAPI = connectAPIServerCommand.Flag("grpc", "Use GRPC API").Default("true").Bool()
)
func runConnectAPIServerCommand(ctx context.Context) error {
password, err := getPasswordFromFlags(ctx, false, false)
if err != nil {
return errors.Wrap(err, "getting password")
}
as := &repo.APIServerInfo{
BaseURL: strings.TrimSuffix(*connectAPIServerURL, "/"),
TrustedServerCertificateFingerprint: strings.ToLower(*connectAPIServerCertFingerprint),
DisableGRPC: !*connectAPIServerUseGRPCAPI,
}
configFile := repositoryConfigFileName()
if err := repo.ConnectAPIServer(ctx, configFile, as, password, connectOptions()); err != nil {
return errors.Wrap(err, "error connecting to API server")
}
log(ctx).Infof("Connected to repository API Server.")
maybeInitializeUpdateCheck(ctx)
return nil
}
func init() {
connectAPIServerCommand.Action(noRepositoryAction(runConnectAPIServerCommand))
}