Skip to content

Commit

Permalink
Add Kopia CLI repository status command (#2665)
Browse files Browse the repository at this point in the history
* Add safecli dependency

* add new flag implementations based on the safecli package for the Kopia CLI

* apply go fmt

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add common Kopia args and flags

* Add Kopia storage core flags

* Add kopia filesystem storage flags

* cleanup storage tests

* Add kopia GCS storage flags

* add gcs flag tests

* Add kopia azure storage flags

* Add kopia s3 and s3 compliant storage flags

* Use test.FlagSuite for storage tests

* Fix typo

* Add kopia CLI repository connect command

* Add kopia CLI repository connect command

* Add kopia CLI repository connect server command

* Add kopia CLI repository set-parameters command

* Add kopia CLI repository status command

* Fix Apply and test.Suit

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Remove variadic args for Common and Cache flags

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add pkg/kopia/cli package

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* go mod tidy

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia storage helpers

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Implement Kopia storage Filesystem opts

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add (c) headers

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Remove unused error

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Reorganize imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia GCS storage opts

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Reorganize imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia Azure storage opts

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix gcs test

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia S3 and S3 compliant storage opts

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia S3 and S3 compliant storage opts

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Cleanup tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia repository create command

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Cleanup

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Reorganize tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Kopia repository connect command

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add opts tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add opts tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Convert common flags from vars to funcs

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add safecli dependency

* add new flag implementations based on the safecli package for the Kopia CLI

* apply go fmt

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix Apply and test.Suit

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add pkg/kopia/cli package

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* go mod tidy

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Update safecli to v0.0.5

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Update safecli to v0.0.6

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add Location.IsPointInTypeSupported

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add tests for Location.IsPointInTypeSupported

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix s3 options

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix s3 options

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix options to return errors for empty args

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix options to return errors for empty args

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix options to return errors for empty args

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support empty prefix

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support empty prefix

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support empty prefix

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support empty prefix

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support empty argument for hostname and username options

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Support PIT option for Azure and S3 only

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Server URL option is required

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix formatting

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* organize imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* organize imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* organize imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Add missed copyright headers

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix s3 tests

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

* Fix imports

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>

---------

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>
  • Loading branch information
plar committed Mar 5, 2024
1 parent 7ec1131 commit 3e505d0
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/kopia/cli/internal/kopia_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 internal_test

import (
Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/cli/internal/test/command_suite.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 test

import (
Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/cli/repository/data_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
1 change: 1 addition & 0 deletions pkg/kopia/cli/repository/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
subcmdConnect = command.NewArgument("connect")
subcmdServer = command.NewArgument("server")
subcmdSetParameters = command.NewArgument("set-parameters")
subcmdStatus = command.NewArgument("status")
)

// optHostname creates a new option for the hostname of the repository.
Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/cli/repository/repository_connect_server_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/cli/repository/repository_connect_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/cli/repository/repository_set_parameters_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
42 changes: 42 additions & 0 deletions pkg/kopia/cli/repository/repository_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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"
)

// StatusArgs defines the arguments for the `kopia repository status ...` command.
type StatusArgs struct {
args.Common // embed common arguments

JSONOutput bool // shows the output in JSON format

Logger log.Logger
}

// Status creates a new `kopia repository status ...` command.
func Status(args StatusArgs) (*safecli.Builder, error) {
return internal.NewKopiaCommand(
opts.Common(args.Common),
cmdRepository, subcmdStatus,
opts.JSON(args.JSONOutput),
)
}
66 changes: 66 additions & 0 deletions pkg/kopia/cli/repository/repository_status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 (
"testing"

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

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

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

// Test Repository Status command
var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
{
Name: "repository status with default args",
Command: func() (*safecli.Builder, error) {
args := StatusArgs{
Common: common,
}
return Status(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-dir=cache/log",
"--log-level=error",
"--password=encr-key",
"repository",
"status",
},
},
{
Name: "repository status with JSON output",
Command: func() (*safecli.Builder, error) {
args := StatusArgs{
Common: common,
JSONOutput: true,
}
return Status(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-dir=cache/log",
"--log-level=error",
"--password=encr-key",
"repository",
"status",
"--json",
},
},
}))

0 comments on commit 3e505d0

Please sign in to comment.