Config: add docs & tests for --redacted option

This commit is contained in:
Tom Jaspers 2015-03-26 12:49:54 +01:00
parent 944d38064d
commit ce78be3eb6
4 changed files with 31 additions and 2 deletions

View file

@ -63,6 +63,8 @@ Features:
flexible attribute `data_source` of an Item/Album. :bug:`1311`
* :doc:`/plugins/permissions`: Now handles also the permissions of the
directories. :bug:`1308` :bug:`1324`
* Config: A new option ``-r/--redacted`` will automatically redact sensitive
values (e.g., passwords) when printing the config. :bug:`1376`
Core changes:

View file

@ -283,6 +283,12 @@ If you want to access configuration values *outside* of your plugin's section,
import the `config` object from the `beets` module. That is, just put ``from
beets import config`` at the top of your plugin and access values from there.
If your plugin provides configuration values for sensitive data (e.g.,
passwords, api keys, ...), you should add these to the config so they can be
redacted automatically when users dump their config. This can be done by
calling ``self.config.add_redacted_fields('field1', 'field2', ..., 'fieldN')``
in your plugin.
Add Path Format Functions and Fields
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -340,7 +340,7 @@ config
``````
::
beet config [-pd]
beet config [-pdr]
beet config -e
Show or edit the user configuration. This command does one of three things:
@ -351,6 +351,9 @@ Show or edit the user configuration. This command does one of three things:
* The ``--path`` option instead shows the path to your configuration file.
This can be combined with the ``--default`` flag to show where beets keeps
its internal defaults.
* The ``--redacted`` option will automatically mask sensitive values (e.g.,
passwords) when printing the configuration. This makes it easier to
copy/paste your config when reporting bugs.
* With the ``--edit`` option, beets attempts to open your config file for
editing. It first tries the ``$EDITOR`` environment variable and then a
fallback option depending on your platform: ``open`` on OS X, ``xdg-open``

View file

@ -26,7 +26,8 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
self.config_path = os.path.join(self.temp_dir, 'config.yaml')
with open(self.config_path, 'w') as file:
file.write('library: lib\n')
file.write('option: value')
file.write('option: value\n')
file.write('password: password_value')
self.cli_config_path = os.path.join(self.temp_dir, 'cli_config.yaml')
with open(self.cli_config_path, 'w') as file:
@ -43,12 +44,14 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
self.run_command('config')
output = yaml.load(output.getvalue())
self.assertEqual(output['option'], 'value')
self.assertEqual(output['password'], 'password_value')
def test_show_user_config_with_defaults(self):
with capture_stdout() as output:
self.run_command('config', '-d')
output = yaml.load(output.getvalue())
self.assertEqual(output['option'], 'value')
self.assertEqual(output['password'], 'password_value')
self.assertEqual(output['library'], 'lib')
self.assertEqual(output['import']['timid'], False)
@ -59,6 +62,21 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
self.assertEqual(output['library'], 'lib')
self.assertEqual(output['option'], 'cli overwrite')
def test_show_redacted_user_config(self):
with capture_stdout() as output:
self.run_command('config', '-r')
output = yaml.load(output.getvalue())
self.assertEqual(output['option'], 'value')
self.assertEqual(output['password'], 'REDACTED')
def test_show_redacted_user_config_with_defaults(self):
with capture_stdout() as output:
self.run_command('config', '-rd')
output = yaml.load(output.getvalue())
self.assertEqual(output['option'], 'value')
self.assertEqual(output['password'], 'REDACTED')
self.assertEqual(output['import']['timid'], False)
def test_config_paths(self):
with capture_stdout() as output:
self.run_command('config', '-p')