Skip to content

Commit

Permalink
Add Kopia Azure storage opts (#2658)
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

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

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

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

---------

Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>
  • Loading branch information
plar committed Mar 5, 2024
1 parent 3bb32d3 commit dfca3a5
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/kopia/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ var (
ErrInvalidBucketName = errors.New("bucket name cannot be empty")
// ErrInvalidCredentialsFile is returned when the credentials file is empty.
ErrInvalidCredentialsFile = errors.New("credentials file cannot be empty")
// ErrInvalidContainerName is returned when the containerName is empty.
ErrInvalidContainerName = errors.New("container name cannot be empty")
)
31 changes: 31 additions & 0 deletions pkg/kopia/cli/repository/storage/azure/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 azure

import (
"github.com/kanisterio/safecli/command"

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

// New creates a new subcommand for the Azure storage.
func New(location internal.Location, repoPathPrefix string, _ log.Logger) command.Applier {
prefix := internal.GenerateFullRepoPath(location.Prefix(), repoPathPrefix)
return command.NewArguments(subcmdAzure,
optContainer(location.BucketName()),
optPrefix(prefix),
)
}
39 changes: 39 additions & 0 deletions pkg/kopia/cli/repository/storage/azure/azure_opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 azure

import (
"github.com/kanisterio/safecli/command"

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

var (
subcmdAzure = command.NewArgument("azure")
)

// optPrefix creates a new prefix option with a given prefix.
func optPrefix(prefix string) command.Applier {
return command.NewOptionWithArgument("--prefix", prefix)
}

// optContainer creates a new container option with a given container name.
// If the name is empty, it returns ErrInvalidContainerName.
func optContainer(name string) command.Applier {
if name == "" {
return command.NewErrorArgument(cli.ErrInvalidContainerName)
}
return command.NewOptionWithArgument("--container", name)
}
45 changes: 45 additions & 0 deletions pkg/kopia/cli/repository/storage/azure/azure_opts_test.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 azure

import (
"testing"

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

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

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

var _ = check.Suite(&test.ArgumentSuite{Cmd: "cmd", Arguments: []test.ArgumentTest{
{
Name: "optContainer",
Argument: optContainer("containername"),
ExpectedCLI: []string{"cmd", "--container=containername"},
},
{
Name: "optContainer with empty containername should return error",
Argument: optContainer(""),
ExpectedErr: cli.ErrInvalidContainerName,
},
{
Name: "optPrefix",
Argument: command.NewArguments(optPrefix("prefix"), optPrefix("")),
ExpectedCLI: []string{"cmd", "--prefix=prefix", "--prefix="},
},
}})
59 changes: 59 additions & 0 deletions pkg/kopia/cli/repository/storage/azure/azure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 azure

import (
"testing"

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

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

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

func newAzure(prefix, repoPath, bucket string) command.Applier {
l := internal.Location{
"prefix": []byte(prefix),
"bucket": []byte(bucket),
}
return New(l, repoPath, nil)
}

var _ = check.Suite(&test.ArgumentSuite{Cmd: "cmd", Arguments: []test.ArgumentTest{
{
Name: "NewAzure",
Argument: newAzure("prefix", "repoPath", "bucket"),
ExpectedCLI: []string{"cmd", "azure", "--container=bucket", "--prefix=prefix/repoPath/"},
},
{
Name: "NewAzure with empty repoPath",
Argument: newAzure("prefix", "", "bucket"),
ExpectedCLI: []string{"cmd", "azure", "--container=bucket", "--prefix=prefix/"},
},
{
Name: "NewAzure with empty local prefix and repo prefix should return error",
Argument: newAzure("", "", "bucket"),
ExpectedCLI: []string{"cmd", "azure", "--container=bucket", "--prefix="},
},
{
Name: "NewAzure with empty bucket should return ErrInvalidContainerName",
Argument: newAzure("", "", ""),
ExpectedErr: cli.ErrInvalidContainerName,
},
}})

0 comments on commit dfca3a5

Please sign in to comment.