mirror of
https://github.com/kopia/kopia.git
synced 2026-01-30 17:23:18 -05:00
* linter: upgraded to 1.33, disabled some linters * lint: fixed 'errorlint' errors This ensures that all error comparisons use errors.Is() or errors.As(). We will be wrapping more errors going forward so it's important that error checks are not strict everywhere. Verified that there are no exceptions for errorlint linter which guarantees that. * lint: fixed or suppressed wrapcheck errors * lint: nolintlint and misc cleanups Co-authored-by: Julio López <julio+gh@kasten.io>
44 lines
1.2 KiB
Go
44 lines
1.2 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()
|
|
)
|
|
|
|
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),
|
|
}
|
|
|
|
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))
|
|
}
|