Skip to content

Commit

Permalink
Add kopia CLI repository set-parameters command
Browse files Browse the repository at this point in the history
  • Loading branch information
plar committed Feb 7, 2024
1 parent bb8f0d5 commit c5da317
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/kopia/cli/internal/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ var (

// Repository commands.
var (
Repository = Command{"repository"}
Create = Command{"create"}
Connect = Command{"connect"}
Server = Command{"server"}
Repository = Command{"repository"}
Create = Command{"create"}
Connect = Command{"connect"}
Server = Command{"server"}
SetParameters = Command{"set-parameters"}
)

// Repository storage sub commands.
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/log"

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

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

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.CommandBuilder, error) {
return command.NewKopiaCommandBuilder(args.CommonArgs,
command.Repository, command.SetParameters,
flagrepo.BlobRetention(args.RetentionMode, args.RetentionPeriod),
)
}
62 changes: 62 additions & 0 deletions pkg/kopia/cli/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,65 @@ var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
},
},
}))

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

0 comments on commit c5da317

Please sign in to comment.