Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kopia repository connect server command #2663

Merged
merged 118 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
680e782
Add safecli dependency
plar Feb 3, 2024
72011e7
add new flag implementations based on the safecli package for the Kop…
plar Feb 3, 2024
0f635ad
apply go fmt
plar Feb 4, 2024
d0a6dd1
Add common Kopia args and flags
plar Feb 6, 2024
ca853c1
Add Kopia storage core flags
plar Feb 6, 2024
2d44961
Add kopia filesystem storage flags
plar Feb 6, 2024
8f363ed
cleanup storage tests
plar Feb 6, 2024
0eb826a
Add kopia GCS storage flags
plar Feb 6, 2024
1326624
add gcs flag tests
plar Feb 6, 2024
c3ba3eb
Add kopia azure storage flags
plar Feb 6, 2024
0c7c121
Add kopia s3 and s3 compliant storage flags
plar Feb 6, 2024
03df94c
Use test.FlagSuite for storage tests
plar Feb 6, 2024
6224599
Fix typo
plar Feb 6, 2024
02f0449
Add kopia CLI repository connect command
plar Feb 7, 2024
067ecc3
Add kopia CLI repository connect command
plar Feb 7, 2024
bb8f0d5
Add kopia CLI repository connect server command
plar Feb 7, 2024
9850f4a
Fix Apply and test.Suit
plar Feb 12, 2024
246e1c1
Remove variadic args for Common and Cache flags
plar Feb 12, 2024
419652c
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 12, 2024
24707e5
pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now
plar Feb 17, 2024
c029fc1
Merge branch 'master' into kopia-cli-core-infra
plar Feb 17, 2024
cff7220
Re-implement Kopia common args and opts; Sync with the master
plar Feb 17, 2024
550d124
Add pkg/kopia/cli package
plar Feb 17, 2024
fc918a0
go mod tidy
plar Feb 17, 2024
9530c91
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 17, 2024
75fb036
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 17, 2024
9fdf94b
Add Kopia storage helpers
plar Feb 17, 2024
6e7963a
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 17, 2024
57adfc2
Implement Kopia storage Filesystem opts
plar Feb 17, 2024
18d8dd6
Add (c) headers
plar Feb 17, 2024
e1bf966
Remove unused error
plar Feb 17, 2024
e51868b
Reorganize imports
plar Feb 17, 2024
4037b32
Sync with kopia-cli-storage-fs-flags
plar Feb 17, 2024
ff01936
Add Kopia GCS storage opts
plar Feb 17, 2024
c3cd83c
Reorganize imports
plar Feb 17, 2024
dad30a1
Sync with kopia-cli-storage-gcs-flags
plar Feb 17, 2024
78c7092
Add Kopia Azure storage opts
plar Feb 17, 2024
b2f956a
Fix gcs test
plar Feb 17, 2024
b77c3d4
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 17, 2024
3f1218a
Sync with kopia-cli-storage-azure-flags
plar Feb 17, 2024
b755966
Add Kopia S3 and S3 compliant storage opts
plar Feb 17, 2024
0764e28
Add Kopia S3 and S3 compliant storage opts
plar Feb 17, 2024
0360761
Cleanup tests
plar Feb 17, 2024
169b2e3
Sync with kopia-cli-storage-s3-flags
plar Feb 17, 2024
be4031d
Add Kopia repository create command
plar Feb 17, 2024
130747e
Cleanup
plar Feb 17, 2024
74a6567
Reorganize tests
plar Feb 17, 2024
88280a9
Sync kopia-cli-repo-create-command
plar Feb 17, 2024
37991ae
Add Kopia repository connect command
plar Feb 18, 2024
209e87b
Add opts tests
plar Feb 18, 2024
f00879c
Add opts tests
plar Feb 18, 2024
3684167
Sync add-kopia-cli-repo-connect-command
plar Feb 18, 2024
2c6cb6e
Convert common flags from vars to funcs
plar Feb 26, 2024
1a3ee2d
Add safecli dependency
plar Feb 3, 2024
386e7e9
add new flag implementations based on the safecli package for the Kop…
plar Feb 3, 2024
b815f63
apply go fmt
plar Feb 4, 2024
bcafabb
Fix Apply and test.Suit
plar Feb 12, 2024
6d61bb4
pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now
plar Feb 17, 2024
e6ddb8f
Add pkg/kopia/cli package
plar Feb 17, 2024
4e7ffd7
go mod tidy
plar Feb 17, 2024
f16aea7
Update safecli to v0.0.5
plar Feb 27, 2024
dcd6425
Update safecli to v0.0.6
plar Feb 28, 2024
d3dfb31
Sync with upstream
plar Feb 28, 2024
d2ac987
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 28, 2024
dfa748c
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 28, 2024
e358e9b
Merge branch 'kopia-cli-storage-fs-flags' into kopia-cli-storage-gcs-…
plar Feb 28, 2024
4b781e8
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 28, 2024
c60ce72
Merge branch 'kopia-cli-storage-azure-flags' into kopia-cli-storage-s…
plar Feb 28, 2024
522fbf8
Merge branch 'kopia-cli-storage-s3-flags' into kopia-cli-repo-create-…
plar Feb 28, 2024
f8d689c
Merge branch 'kopia-cli-repo-create-command' into add-kopia-cli-repo-…
plar Feb 28, 2024
d17287f
Merge branch 'add-kopia-cli-repo-connect-command' into add-kopia-cli-…
plar Feb 28, 2024
b093421
Fix tests
plar Feb 28, 2024
6e71143
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 28, 2024
de3a52b
Add Location.IsPointInTypeSupported
plar Feb 28, 2024
722b279
Add tests for Location.IsPointInTypeSupported
plar Feb 28, 2024
71a5aa5
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 28, 2024
e0a37df
Merge branch 'kopia-cli-storage-fs-flags' into kopia-cli-storage-gcs-…
plar Feb 28, 2024
174a2b7
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 28, 2024
e3c97f1
Merge branch 'kopia-cli-storage-azure-flags' into kopia-cli-storage-s…
plar Feb 28, 2024
db06c40
Fix s3 options
plar Feb 28, 2024
0962e3b
Fix s3 options
plar Feb 28, 2024
a005389
Fix options to return errors for empty args
plar Feb 29, 2024
7cabf8a
Fix options to return errors for empty args
plar Feb 29, 2024
c2bf064
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 29, 2024
8e1c1f7
Fix options to return errors for empty args
plar Feb 29, 2024
ebcc539
Merge branch 'kopia-cli-storage-azure-flags' into kopia-cli-storage-s…
plar Feb 29, 2024
9500b32
Support empty prefix
plar Feb 29, 2024
4630719
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 29, 2024
7772096
Support empty prefix
plar Feb 29, 2024
a4ddad6
Support empty prefix
plar Feb 29, 2024
de5741b
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 29, 2024
abdc53e
Merge branch 'kopia-cli-storage-azure-flags' into kopia-cli-storage-s…
plar Feb 29, 2024
37e1dc7
Support empty prefix
plar Feb 29, 2024
1f57fee
Merge branch 'kopia-cli-storage-s3-flags' into kopia-cli-repo-create-…
plar Feb 29, 2024
8a33fda
Support empty argument for hostname and username options
plar Feb 29, 2024
76f82a4
Merge branch 'kopia-cli-repo-create-command' into add-kopia-cli-repo-…
plar Feb 29, 2024
378d255
Support PIT option for Azure and S3 only
plar Feb 29, 2024
3c71f1f
Merge branch 'add-kopia-cli-repo-connect-command' into add-kopia-cli-…
plar Feb 29, 2024
241e693
Server URL option is required
plar Feb 29, 2024
44c133e
Fix formatting
plar Feb 29, 2024
1897a1e
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 29, 2024
33b1342
organize imports
plar Feb 29, 2024
83292af
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 29, 2024
516a14c
organize imports
plar Feb 29, 2024
9d7d01d
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 29, 2024
6fa6960
Merge branch 'kopia-cli-storage-fs-flags' into kopia-cli-storage-gcs-…
plar Feb 29, 2024
78c04af
Merge branch 'kopia-cli-storage-gcs-flags' into kopia-cli-storage-azu…
plar Feb 29, 2024
26178ea
Merge branch 'kopia-cli-storage-azure-flags' into kopia-cli-storage-s…
plar Feb 29, 2024
c7a16c8
Merge branch 'kopia-cli-storage-s3-flags' into kopia-cli-repo-create-…
plar Feb 29, 2024
ead6178
Merge branch 'kopia-cli-repo-create-command' into add-kopia-cli-repo-…
plar Feb 29, 2024
3030d2f
organize imports
plar Feb 29, 2024
e0ba8b0
Merge branch 'add-kopia-cli-repo-connect-command' into add-kopia-cli-…
plar Feb 29, 2024
da5058d
Fix s3 tests
plar Mar 1, 2024
61028d1
Merge branch 'kopia-cli-storage-s3-flags' into kopia-cli-repo-create-…
plar Mar 1, 2024
683d20a
Merge branch 'kopia-cli-repo-create-command' into add-kopia-cli-repo-…
plar Mar 1, 2024
1ab9cc3
Merge branch 'add-kopia-cli-repo-connect-command' into add-kopia-cli-…
plar Mar 1, 2024
8f98358
Merge branch 'master' into add-kopia-cli-repo-connect-server-command
plar Mar 5, 2024
0cb497b
Merge branch 'master' into add-kopia-cli-repo-connect-server-command
mergify[bot] Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/kopia/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ var (
ErrInvalidCredentialsFile = errors.New("credentials file cannot be empty")
// ErrInvalidContainerName is returned when the containerName is empty.
ErrInvalidContainerName = errors.New("container name cannot be empty")
// ErrInvalidServerURL is returned when the serverURL is empty.
ErrInvalidServerURL = errors.New("server URL cannot be empty")
)
17 changes: 17 additions & 0 deletions pkg/kopia/cli/repository/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (

subcmdCreate = command.NewArgument("create")
subcmdConnect = command.NewArgument("connect")
subcmdServer = command.NewArgument("server")
)

// optHostname creates a new option for the hostname of the repository.
Expand Down Expand Up @@ -104,3 +105,19 @@ func optPointInTime(l internal.Location, pit strfmt.DateTime) command.Applier {
}
return command.NewOptionWithArgument("--point-in-time", pit.String())
}

// optServerURL creates a new server URL flag with a given server URL.
func optServerURL(serverURL string) command.Applier {
if serverURL == "" {
return command.NewErrorArgument(cli.ErrInvalidServerURL)
}
return command.NewOptionWithArgument("--url", serverURL)
}

// optServerCertFingerprint creates a new server certificate fingerprint flag with a given fingerprint.
func optServerCertFingerprint(fingerprint string) command.Applier {
if fingerprint == "" {
return command.NewNoopArgument()
}
return command.NewOptionWithRedactedArgument("--server-cert-fingerprint", fingerprint)
}
18 changes: 18 additions & 0 deletions pkg/kopia/cli/repository/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,22 @@ var _ = check.Suite(&test.ArgumentSuite{Cmd: "cmd", Arguments: []test.ArgumentTe
"--point-in-time=2021-02-04T01:02:03.000Z",
},
},
{
Name: "optServerURL with ServerURL should return option",
Argument: optServerURL("http://test-server"),
ExpectedCLI: []string{"cmd", "--url=http://test-server"},
},
{
Name: "optServerURL with empty ServerURL should return error",
Argument: optServerURL(""),
ExpectedErr: cli.ErrInvalidServerURL,
},
{
Name: "optServerCertFingerprint",
Argument: command.NewArguments(
optServerCertFingerprint("fingerprint"),
optServerCertFingerprint(""), // no output
),
ExpectedCLI: []string{"cmd", "--server-cert-fingerprint=fingerprint"},
},
}})
54 changes: 54 additions & 0 deletions pkg/kopia/cli/repository/repository_connect_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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/kopia/cli/args"
"github.com/kanisterio/kanister/pkg/kopia/cli/internal"
"github.com/kanisterio/kanister/pkg/kopia/cli/internal/opts"
"github.com/kanisterio/kanister/pkg/log"
)

// ConnectServerArgs defines the arguments for the `kopia repository connect server` command.
type ConnectServerArgs struct {
args.Common
args.Cache

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.Builder, error) {
return internal.NewKopiaCommand(
opts.Common(args.Common),
cmdRepository, subcmdConnect, subcmdServer,
opts.CheckForUpdates(false),
opts.GRPC(false),
optReadOnly(args.ReadOnly),
opts.Cache(args.Cache),
optHostname(args.Hostname),
optUsername(args.Username),
optServerURL(args.ServerURL),
optServerCertFingerprint(args.Fingerprint),
)
}
50 changes: 50 additions & 0 deletions pkg/kopia/cli/repository/repository_connect_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package repository

import (
"testing"

"github.com/kanisterio/safecli"
"gopkg.in/check.v1"

"github.com/kanisterio/kanister/pkg/kopia/cli/internal/test"
)

func TestRepositoryConnectServerCommand(t *testing.T) { check.TestingT(t) }

// Test Repository Connect Server command
var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
{
Name: "repository connect server",
Command: func() (*safecli.Builder, error) {
args := ConnectServerArgs{
Common: common,
Cache: cache,
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-dir=cache/log",
"--log-level=error",
"--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",
},
},
}))