From 3e505d073ec2b2edff5a06e48b5d171e5b3fa363 Mon Sep 17 00:00:00 2001 From: Pavel Larkin Date: Tue, 5 Mar 2024 15:46:52 -0800 Subject: [PATCH] Add Kopia CLI repository status command (#2665) * Add safecli dependency * add new flag implementations based on the safecli package for the Kopia CLI * apply go fmt Signed-off-by: pavel.larkin * 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 * Remove variadic args for Common and Cache flags Signed-off-by: pavel.larkin * pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now Signed-off-by: pavel.larkin * Add pkg/kopia/cli package Signed-off-by: pavel.larkin * go mod tidy Signed-off-by: pavel.larkin * Add Kopia storage helpers Signed-off-by: pavel.larkin * Implement Kopia storage Filesystem opts Signed-off-by: pavel.larkin * Add (c) headers Signed-off-by: pavel.larkin * Remove unused error Signed-off-by: pavel.larkin * Reorganize imports Signed-off-by: pavel.larkin * Add Kopia GCS storage opts Signed-off-by: pavel.larkin * Reorganize imports Signed-off-by: pavel.larkin * Add Kopia Azure storage opts Signed-off-by: pavel.larkin * Fix gcs test Signed-off-by: pavel.larkin * Add Kopia S3 and S3 compliant storage opts Signed-off-by: pavel.larkin * Add Kopia S3 and S3 compliant storage opts Signed-off-by: pavel.larkin * Cleanup tests Signed-off-by: pavel.larkin * Add Kopia repository create command Signed-off-by: pavel.larkin * Cleanup Signed-off-by: pavel.larkin * Reorganize tests Signed-off-by: pavel.larkin * Add Kopia repository connect command Signed-off-by: pavel.larkin * Add opts tests Signed-off-by: pavel.larkin * Add opts tests Signed-off-by: pavel.larkin * Convert common flags from vars to funcs Signed-off-by: pavel.larkin * Add safecli dependency * add new flag implementations based on the safecli package for the Kopia CLI * apply go fmt Signed-off-by: pavel.larkin * Fix Apply and test.Suit Signed-off-by: pavel.larkin * pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now Signed-off-by: pavel.larkin * Add pkg/kopia/cli package Signed-off-by: pavel.larkin * go mod tidy Signed-off-by: pavel.larkin * Update safecli to v0.0.5 Signed-off-by: pavel.larkin * Update safecli to v0.0.6 Signed-off-by: pavel.larkin * Fix tests Signed-off-by: pavel.larkin * Add Location.IsPointInTypeSupported Signed-off-by: pavel.larkin * Add tests for Location.IsPointInTypeSupported Signed-off-by: pavel.larkin * Fix s3 options Signed-off-by: pavel.larkin * Fix s3 options Signed-off-by: pavel.larkin * Fix options to return errors for empty args Signed-off-by: pavel.larkin * Fix options to return errors for empty args Signed-off-by: pavel.larkin * Fix options to return errors for empty args Signed-off-by: pavel.larkin * Support empty prefix Signed-off-by: pavel.larkin * Support empty prefix Signed-off-by: pavel.larkin * Support empty prefix Signed-off-by: pavel.larkin * Support empty prefix Signed-off-by: pavel.larkin * Support empty argument for hostname and username options Signed-off-by: pavel.larkin * Support PIT option for Azure and S3 only Signed-off-by: pavel.larkin * Server URL option is required Signed-off-by: pavel.larkin * Fix formatting Signed-off-by: pavel.larkin * organize imports Signed-off-by: pavel.larkin * organize imports Signed-off-by: pavel.larkin * organize imports Signed-off-by: pavel.larkin * Add missed copyright headers Signed-off-by: pavel.larkin * Fix s3 tests Signed-off-by: pavel.larkin * Fix imports Signed-off-by: pavel.larkin --------- Signed-off-by: pavel.larkin --- pkg/kopia/cli/internal/kopia_test.go | 14 ++++ pkg/kopia/cli/internal/test/command_suite.go | 14 ++++ pkg/kopia/cli/repository/data_test.go | 14 ++++ pkg/kopia/cli/repository/opts.go | 1 + .../repository_connect_server_test.go | 14 ++++ .../cli/repository/repository_connect_test.go | 14 ++++ .../repository_set_parameters_test.go | 14 ++++ pkg/kopia/cli/repository/repository_status.go | 42 ++++++++++++ .../cli/repository/repository_status_test.go | 66 +++++++++++++++++++ 9 files changed, 193 insertions(+) create mode 100644 pkg/kopia/cli/repository/repository_status.go create mode 100644 pkg/kopia/cli/repository/repository_status_test.go diff --git a/pkg/kopia/cli/internal/kopia_test.go b/pkg/kopia/cli/internal/kopia_test.go index de2217bbbb..671f2af8d5 100644 --- a/pkg/kopia/cli/internal/kopia_test.go +++ b/pkg/kopia/cli/internal/kopia_test.go @@ -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 ( diff --git a/pkg/kopia/cli/internal/test/command_suite.go b/pkg/kopia/cli/internal/test/command_suite.go index 0eebf793ff..8ce690be20 100644 --- a/pkg/kopia/cli/internal/test/command_suite.go +++ b/pkg/kopia/cli/internal/test/command_suite.go @@ -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 ( diff --git a/pkg/kopia/cli/repository/data_test.go b/pkg/kopia/cli/repository/data_test.go index 0b6ef70b29..6ad10df1a3 100644 --- a/pkg/kopia/cli/repository/data_test.go +++ b/pkg/kopia/cli/repository/data_test.go @@ -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 ( diff --git a/pkg/kopia/cli/repository/opts.go b/pkg/kopia/cli/repository/opts.go index 919a322208..31c92ab0e5 100644 --- a/pkg/kopia/cli/repository/opts.go +++ b/pkg/kopia/cli/repository/opts.go @@ -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. diff --git a/pkg/kopia/cli/repository/repository_connect_server_test.go b/pkg/kopia/cli/repository/repository_connect_server_test.go index 43a188637e..b50a03b0f6 100644 --- a/pkg/kopia/cli/repository/repository_connect_server_test.go +++ b/pkg/kopia/cli/repository/repository_connect_server_test.go @@ -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 ( diff --git a/pkg/kopia/cli/repository/repository_connect_test.go b/pkg/kopia/cli/repository/repository_connect_test.go index d3f8f338ea..9f8f0d7067 100644 --- a/pkg/kopia/cli/repository/repository_connect_test.go +++ b/pkg/kopia/cli/repository/repository_connect_test.go @@ -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 ( diff --git a/pkg/kopia/cli/repository/repository_set_parameters_test.go b/pkg/kopia/cli/repository/repository_set_parameters_test.go index bf9d460e61..5f7fe01a08 100644 --- a/pkg/kopia/cli/repository/repository_set_parameters_test.go +++ b/pkg/kopia/cli/repository/repository_set_parameters_test.go @@ -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 ( diff --git a/pkg/kopia/cli/repository/repository_status.go b/pkg/kopia/cli/repository/repository_status.go new file mode 100644 index 0000000000..c13dfd37ad --- /dev/null +++ b/pkg/kopia/cli/repository/repository_status.go @@ -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), + ) +} diff --git a/pkg/kopia/cli/repository/repository_status_test.go b/pkg/kopia/cli/repository/repository_status_test.go new file mode 100644 index 0000000000..68a11cfdd4 --- /dev/null +++ b/pkg/kopia/cli/repository/repository_status_test.go @@ -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", + }, + }, +}))