Skip to content

Conversation

@DEvil0000
Copy link
Contributor

No description provided.


`PASSWORD` - Password in case you do not use a private key (not recommended)

`PASSPHRASE` - Passphrase to your private key
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be not mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

empty should work - I however did not explicitly test it without

allow_agent=False,
timeout=20,
)
if len(env.PASSWORD) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

you should take into account the case when PRIVATE_KEY_PATH is not provided and PASSWORD is the only secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand. PRIVATE_KEY_PATH is always provided by env.py even if PRIVATE_KEY was empty.

Copy link
Contributor

@quarckster quarckster Feb 1, 2022

Choose a reason for hiding this comment

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

PRIVATE_KEY_PATH is always provided by env.py even if PRIVATE_KEY was empty.

Sorry, I meant PRIVATE_KEY. It doesn't make sense to provide PRIVATE_KEY if you have PASSWORD and vice versa. They are mutually exclusive arguments.

def get_cred():
    if env.PASSWORD:
        return {"password": env.PASSWORD}
    if env.PRIVATE_KEY:
        pkey = paramiko.rsakey.RSASHA256Key.from_private_key_file(env.PRIVATE_KEY_PATH)
        return {"passphrase": env.PASSPHRASE, "pkey": pkey}
    raise ValueError("Either PASSWORD or PRIVATE_KEY must be defined")
...

ssh_client.connect(
    hostname=ip,
    username=env.USERNAME,
    look_for_keys=False,
    allow_agent=False,
    timeout=60,
    **get_cred()
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you can of course write it like that. How about you merge it and change this style detail then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants