From 65bc15f998bca74039f071573f124d1b11545ab6 Mon Sep 17 00:00:00 2001 From: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:56:41 -0500 Subject: [PATCH] new: Address breaking change in MDS plugin `sshkeys` command (#579) --- linodecli/plugins/metadata.py | 13 +++++++++---- tests/unit/test_plugin_metadata.py | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/linodecli/plugins/metadata.py b/linodecli/plugins/metadata.py index 7587da309..cfa1147ce 100644 --- a/linodecli/plugins/metadata.py +++ b/linodecli/plugins/metadata.py @@ -57,11 +57,16 @@ def print_ssh_keys_table(data): """ table = Table(show_lines=True) - table.add_column("ssh keys") + table.add_column("user") + table.add_column("ssh key") - if data.users.root is not None: - for key in data.users.root: - table.add_row(key) + for name, keys in data.users.items(): + # Keys will be None if no keys are configured for the user + if keys is None: + continue + + for key in keys: + table.add_row(name, key) rprint(table) diff --git a/tests/unit/test_plugin_metadata.py b/tests/unit/test_plugin_metadata.py index 599002019..72e3c6df7 100644 --- a/tests/unit/test_plugin_metadata.py +++ b/tests/unit/test_plugin_metadata.py @@ -116,7 +116,9 @@ def test_ssh_key_table(capsys: CaptureFixture): print_ssh_keys_table(SSH_KEYS) captured_text = capsys.readouterr() - assert "ssh keys" in captured_text.out + assert "user" in captured_text.out + assert "ssh key" in captured_text.out + assert "root" in captured_text.out assert "ssh-key-1" in captured_text.out assert "ssh-key-2" in captured_text.out @@ -125,4 +127,5 @@ def test_empty_ssh_key_table(capsys: CaptureFixture): print_ssh_keys_table(SSH_KEYS_EMPTY) captured_text = capsys.readouterr() - assert "ssh keys" in captured_text.out + assert "user" in captured_text.out + assert "ssh key" in captured_text.out