Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to add additional identities via the command line #413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libagent/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def create_agent_parser(device_type):

p.add_argument('identity', type=_to_unicode, default=None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be simpler to add nargs='+' to the existing identity argument:

p.add_argument('identity', type=_to_unicode, default=None, nargs='+',
               help='proto://[user@]host[:port][/path]')

See https://docs.python.org/3/library/argparse.html#nargs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me test how that works.

help='proto://[user@]host[:port][/path]')

p.add_argument('-i', '--additional_identities', type=_to_unicode, default=[], action='append',
help='proto://[user@]host[:port][/path]')

p.add_argument('command', type=str, nargs='*', metavar='ARGUMENT',
help='command to run under the SSH agent')
return p
Expand Down Expand Up @@ -250,12 +254,19 @@ def _get_sock_path(args):
return sock_path


def _add_additional_identities(identities, additional_identities, ecdsa_curve_name):
for identity in additional_identities:
identities.append(device.interface.Identity(
identity_str=identity, curve_name=ecdsa_curve_name))


@handle_connection_error
def main(device_type):
"""Run ssh-agent using given hardware client factory."""
args = create_agent_parser(device_type=device_type).parse_args()
util.setup_logging(verbosity=args.verbose, filename=args.log_file)

identities = []
public_keys = None
filename = None
if args.identity.startswith('/'):
Expand All @@ -268,6 +279,9 @@ def main(device_type):
else:
identities = [device.interface.Identity(
identity_str=args.identity, curve_name=args.ecdsa_curve_name)]

_add_additional_identities(identities, args.additional_identities, args.ecdsa_curve_name)

for index, identity in enumerate(identities):
identity.identity_dict['proto'] = 'ssh'
log.info('identity #%d: %s', index, identity.to_string())
Expand Down