From ce78be3eb60b276d0c50dbab632e39b11f454532 Mon Sep 17 00:00:00 2001 From: Tom Jaspers Date: Thu, 26 Mar 2015 12:49:54 +0100 Subject: [PATCH] Config: add docs & tests for --redacted option --- docs/changelog.rst | 2 ++ docs/dev/plugins.rst | 6 ++++++ docs/reference/cli.rst | 5 ++++- test/test_config_command.py | 20 +++++++++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f3e71e9dd..3e0ac8157 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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: diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index 1d610f53b..ecf1e8ab4 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index 321b766d4..0922af915 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -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`` diff --git a/test/test_config_command.py b/test/test_config_command.py index c206c7ac8..cd23f8eb2 100644 --- a/test/test_config_command.py +++ b/test/test_config_command.py @@ -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')