-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): new storage config input from file when creating a repo #2756
Merged
Shrekster
merged 4 commits into
kopia:master
from
kastenhq:storage-config-provisioning-flag
Jul 27, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cli_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kopia/kopia/repo" | ||
"github.com/kopia/kopia/repo/blob" | ||
"github.com/kopia/kopia/repo/blob/filesystem" | ||
"github.com/kopia/kopia/tests/testenv" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRepositoryCreateWithConfigFile(t *testing.T) { | ||
env := testenv.NewCLITest(t, nil, testenv.NewInProcRunner(t)) | ||
|
||
_, stderr := env.RunAndExpectFailure(t, "repo", "create", "from-config", "--file", path.Join(env.ConfigDir, "does_not_exist.config")) | ||
require.Contains(t, stderr, "can't connect to storage: one of --token-file, --token-stdin or --token must be provided") | ||
|
||
_, stderr = env.RunAndExpectFailure(t, "repo", "connect", "from-config") | ||
require.Contains(t, stderr, "can't connect to storage: one of --file, --token-file, --token-stdin or --token must be provided") | ||
|
||
_, stderr = env.RunAndExpectFailure(t, "repo", "create", "from-config", "--token", "bad-token") | ||
require.Contains(t, stderr, "can't connect to storage: invalid token: unable to decode token") | ||
|
||
storageCfgFName := path.Join(env.ConfigDir, "storage-config.json") | ||
ci := blob.ConnectionInfo{ | ||
Type: "filesystem", | ||
Config: filesystem.Options{Path: env.RepoDir}, | ||
} | ||
token, err := repo.EncodeToken("12345678", ci) | ||
require.Nil(t, err) | ||
|
||
// expect failure before writing to file | ||
_, stderr = env.RunAndExpectFailure(t, "repo", "create", "from-config", "--token-file", storageCfgFName) | ||
require.Contains(t, strings.Join(stderr, "\n"), "can't connect to storage: unable to open token file") | ||
|
||
require.Nil(t, os.WriteFile(storageCfgFName, []byte(token), 0o600)) | ||
|
||
defer os.Remove(storageCfgFName) //nolint:errcheck,gosec | ||
|
||
env.RunAndExpectSuccess(t, "repo", "create", "from-config", "--token-file", storageCfgFName) | ||
} | ||
|
||
func TestRepositoryCreateWithConfigFromStdin(t *testing.T) { | ||
runner := testenv.NewInProcRunner(t) | ||
env := testenv.NewCLITest(t, nil, runner) | ||
|
||
ci := blob.ConnectionInfo{ | ||
Type: "filesystem", | ||
Config: filesystem.Options{Path: env.RepoDir}, | ||
} | ||
token, err := repo.EncodeToken("12345678", ci) | ||
require.Nil(t, err) | ||
|
||
// set stdin | ||
runner.SetNextStdin(strings.NewReader(token)) | ||
|
||
env.RunAndExpectSuccess(t, "repo", "create", "from-config", "--token-stdin") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about (also) adding a boolean
token-stdin
or something similar ? This would make it work on Windows where /dev/stdin is not available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkowalski, According to my understanding, we want to introduce a flag
token-stdin
, which is basically of boolean type. If the value is false than user have to pass the token file path and if true than user have to pass the value of token thru stdin ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the
--token-stdin
changes with the unit-test