Skip to content

Commit

Permalink
Add Kopia repository set-parameters command (#2664)
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

* 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>

* Fix s3 tests

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 dd90c25 commit 7ec1131
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/kopia/cli/repository/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import (
var (
cmdRepository = command.NewArgument("repository")

subcmdCreate = command.NewArgument("create")
subcmdConnect = command.NewArgument("connect")
subcmdServer = command.NewArgument("server")
subcmdCreate = command.NewArgument("create")
subcmdConnect = command.NewArgument("connect")
subcmdServer = command.NewArgument("server")
subcmdSetParameters = command.NewArgument("set-parameters")
)

// optHostname creates a new option for the hostname of the repository.
Expand Down
45 changes: 45 additions & 0 deletions pkg/kopia/cli/repository/repository_set_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 (
"time"

"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"
)

// SetParametersArgs defines the arguments for the `kopia repository set-parameters ...` command.
type SetParametersArgs struct {
args.Common

RetentionMode string // retention mode for supported storage backends
RetentionPeriod time.Duration // retention period for supported storage backends

Logger log.Logger
}

// SetParameters creates a new `kopia repository set-parameters ...` command.
func SetParameters(args SetParametersArgs) (*safecli.Builder, error) {
return internal.NewKopiaCommand(
opts.Common(args.Common),
cmdRepository, subcmdSetParameters,
optBlobRetention(args.RetentionMode, args.RetentionPeriod),
)
}
74 changes: 74 additions & 0 deletions pkg/kopia/cli/repository/repository_set_parameters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package repository

import (
"testing"

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

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

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

// Test Repository Set Parameters command
var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
{
Name: "repository set-parameters with default retention",
Command: func() (*safecli.Builder, error) {
args := SetParametersArgs{
Common: common,
}
return SetParameters(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-dir=cache/log",
"--log-level=error",
"--password=encr-key",
"repository",
"set-parameters",
},
},
{
Name: "repository set-parameters with custom retention args",
Command: func() (*safecli.Builder, error) {
args := SetParametersArgs{
Common: common,
RetentionMode: retentionMode,
RetentionPeriod: retentionPeriod,
}
return SetParameters(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-dir=cache/log",
"--log-level=error",
"--password=encr-key",
"repository",
"set-parameters",
"--retention-mode=Locked",
"--retention-period=15m0s",
},
},
{
Name: "repository set-parameters with custom retention mode only",
Command: func() (*safecli.Builder, error) {
args := SetParametersArgs{
Common: common,
RetentionMode: retentionMode,
}
return SetParameters(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-dir=cache/log",
"--log-level=error",
"--password=encr-key",
"repository",
"set-parameters",
"--retention-mode=Locked",
"--retention-period=0s",
},
},
}))

0 comments on commit 7ec1131

Please sign in to comment.