Skip to content

Commit

Permalink
Add kopia CLI repository connect server command
Browse files Browse the repository at this point in the history
  • Loading branch information
plar committed Feb 7, 2024
1 parent 067ecc3 commit bb8f0d5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kopia/cli/internal/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
Repository = Command{"repository"}
Create = Command{"create"}
Connect = Command{"connect"}
Server = Command{"server"}
)

// Repository storage sub commands.
Expand Down
55 changes: 55 additions & 0 deletions pkg/kopia/cli/repository/repository_connect_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package repository

import (
"github.com/kanisterio/safecli"

"github.com/kanisterio/kanister/pkg/log"

"github.com/kanisterio/kanister/pkg/kopia/cli"
"github.com/kanisterio/kanister/pkg/kopia/cli/internal/command"
flagcommon "github.com/kanisterio/kanister/pkg/kopia/cli/internal/flag/common"
flagrepo "github.com/kanisterio/kanister/pkg/kopia/cli/internal/flag/repository"
)

// ConnectServerArgs defines the arguments for the `kopia repository connect server` command.
type ConnectServerArgs struct {
cli.CommonArgs
cli.CacheArgs

Hostname string // hostname of the repository
Username string // username of the repository
ServerURL string // URL of the Kopia Repository API server
Fingerprint string // fingerprint of the server's TLS certificate
ReadOnly bool // connect to a repository in read-only mode

Logger log.Logger
}

// ConnectServer creates a new `kopia repository connect server...` command.
func ConnectServer(args ConnectServerArgs) (safecli.CommandBuilder, error) {
return command.NewKopiaCommandBuilder(args.CommonArgs,
command.Repository, command.Connect, command.Server,
flagcommon.NoCheckForUpdates,
flagcommon.NoGRPC,
flagcommon.ReadOnly(args.ReadOnly),
flagcommon.Cache(args.CacheArgs),
flagrepo.Hostname(args.Hostname),
flagrepo.Username(args.Username),
flagrepo.ServerURL(args.ServerURL),
flagrepo.ServerCertFingerprint(args.Fingerprint),
)
}
38 changes: 38 additions & 0 deletions pkg/kopia/cli/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,41 @@ var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
},
},
}))

// Test Repository Connect Server command
var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
{
Name: "repository connect server",
CLI: func() (safecli.CommandBuilder, error) {
args := ConnectServerArgs{
CommonArgs: test.CommonArgs,
CacheArgs: cacheArgs,
Hostname: "test-hostname",
Username: "test-username",
ServerURL: "http://test-server",
Fingerprint: "test-fingerprint",
ReadOnly: true,
}
return ConnectServer(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-level=error",
"--log-dir=cache/log",
"--password=encr-key",
"repository",
"connect",
"server",
"--no-check-for-updates",
"--no-grpc",
"--readonly",
"--cache-directory=/tmp/cache.dir",
"--content-cache-size-limit-mb=0",
"--metadata-cache-size-limit-mb=0",
"--override-hostname=test-hostname",
"--override-username=test-username",
"--url=http://test-server",
"--server-cert-fingerprint=test-fingerprint",
},
},
}))

0 comments on commit bb8f0d5

Please sign in to comment.