Skip to content

Commit

Permalink
Fix list_keys verb
Browse files Browse the repository at this point in the history
backport and adaptation of #219 to eloquent

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
  • Loading branch information
mikaelarguedas committed Jun 5, 2020
1 parent d3d9de1 commit 04482e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions sros2/sros2/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

from collections import namedtuple
import datetime
import errno
import os
import pathlib
import shutil
import sys

Expand Down Expand Up @@ -324,9 +326,13 @@ def create_key(keystore_path, identity):


def list_keys(keystore_path):
for name in os.listdir(keystore_path):
if os.path.isdir(os.path.join(keystore_path, name)):
print(name)
if not os.path.isdir(keystore_path):
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), keystore_path)
p = pathlib.Path(keystore_path)
key_file_paths = sorted(p.glob('**/key.pem'))
for key_file_path in key_file_paths:
print('/{}'.format(key_file_path.parent.relative_to(keystore_path).as_posix()))
return True


Expand Down
6 changes: 4 additions & 2 deletions sros2/test/sros2/commands/security/verbs/test_list_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@


def test_list_keys(capsys):
key_names = ['/test_node', '/test_namespace/test_node', '/sky/is/the/limit']
with tempfile.TemporaryDirectory() as keystore_dir:
with capsys.disabled():
# First, create the keystore
assert create_keystore(keystore_dir)

# Now using that keystore, create a keypair
assert create_key(keystore_dir, '/test_node')
for key in key_names:
assert create_key(keystore_dir, key)

# Now verify that the key we just created is included in the list
assert cli.main(argv=['security', 'list_keys', keystore_dir]) == 0
assert capsys.readouterr().out.strip() == 'test_node'
assert capsys.readouterr().out.strip() == '\n'.join(sorted(key_names))


def test_list_keys_no_keys(capsys):
Expand Down

0 comments on commit 04482e3

Please sign in to comment.