pick icon indicating copy to clipboard operation
pick copied to clipboard

backends: Use defaults even if config option was provided but empty

Open leonklingele opened this issue 7 years ago • 6 comments

This is a workaround for #190

leonklingele avatar Dec 01 '18 15:12 leonklingele

Feel free to merge, otherwise I'll provide some tests in this PR (which might take some time though).

This PR was tested using the following configurations:

  1. Missing ~/.pick/config.toml
$ pick ls # will access safe at ~/.pick/pick.safe

$ pick --safe ./test.safe ls # will access safe at $PWD/test.safe
  1. Empty ~/.pick/config.toml
$ pick ls # will access safe at ~/.pick/pick.safe

$ pick --safe ./test.safe ls # will access safe at $PWD/test.safe
  1. Default ~/.pick/config.toml with correct syntax & semantic
$ pick ls # will access safe at ~/.pick/pick.safe

$ pick --safe ./test.safe ls # will access safe at $PWD/test.safe
  1. ~/.pick/config.toml with correct syntax & semantic and custom file path
$ pick ls # will access safe at the configured file backend path

$ pick --safe ./test.safe ls # will access safe at $PWD/test.safe
  1. ~/.pick/config.toml with incorrect syntax

An error message will be shown.

@bndw can you please test cases 3. & 4. using the S3 backend?

leonklingele avatar Dec 01 '18 16:12 leonklingele

  • I'll test those configurations against S3 this weekend
  • Let's get tests in before considering the merge
  • @leonklingele thoughts on writing a config file on pick init?

bndw avatar Dec 01 '18 20:12 bndw

thoughts on writing a config file on pick init

That'd be nice! Probably worth adding a --config flag to the init command to support installing a config file after the fact. The example config (config.toml.in) could be embedded into the binary using for example statik.

leonklingele avatar Dec 01 '18 22:12 leonklingele

LGTM with the S3 backend, tested as follows:

  1. Default ~/.pick/config.toml with the S3 backend pointed to a non-existent safe file
[storage]
type = "s3"
  [storage.settings]
  profile = "personal"
  region = "us-west-2"
  bucket = "bndw-pick"
  key = "tmp/default.safe"
  1. Initialized and added an account
$ pick init
...
pick initialized

$ pick add foo
...
Password successfully copied to clipboard
  1. Modified ~/.pick/config.toml to use a second, new safe file
[storage]
type = "s3"
  [storage.settings]
  profile = "personal"
  region = "us-west-2"
  bucket = "bndw-pick"
  key = "tmp/default_two.safe"
  1. Initialized the second safe
$ pick init
...
pick initialized

$ pick add bar
...
Password successfully copied to clipboard
  1. And confirmed the --safe override works
› pick --safe tmp/default.safe ls
Enter your master password for safe 's3://bndw-pick/tmp/default.safe'
>
foo

bndw avatar Jan 06 '19 17:01 bndw

@leonklingele did you have any more tests to add?

bndw avatar Jan 06 '19 17:01 bndw

Whoops, totally forgot about them. I hope to find some time by the end of next week and will update this PR.

leonklingele avatar Jan 06 '19 20:01 leonklingele