feat: add ability to check for multiple default ssh key locations#406
Conversation
6d98b02 to
2e1190a
Compare
|
putting this into draft until i fix tests. |
|
Also, should i add new unit tests that verify the functionality of the added changes? @holmanb (tag you're it) |
holmanb
left a comment
There was a problem hiding this comment.
Also, should i add new unit tests that verify the functionality of the added changes? @holmanb (tag you're it)
Pycloudlib's test coverage is unfortunately very light on tests, but in this case the feature being tested is something that a user would immediately notice if it isn't working.
I'm honestly not sure whether it would be worth the effort in this case to write and maintain a test given the infrequency of changes to this part of the code and the immediate feedback that we would receive.
What do you think?
pycloudlib/cloud.py
Outdated
| self._check_and_set_config(config_file, required_values) | ||
|
|
||
| user = getpass.getuser() | ||
| # check if id_rsa or id_ed25519 keys exist in the user's .ssh directory |
There was a problem hiding this comment.
This turns __init__() mostly into a key-handling function. I would prefer a helper method _get_ssh_keys()[1] to contain this logic and get called from __init__()
[1] maybe a better name, I didn't put any thought into that one
There was a problem hiding this comment.
Haha agreed! Way too much going on there. And would allow for actually unit testing that (if so desired)
Let me go fix the existing unit tests that this change broke, and see if this change gets inherently tested that way. If not, it should be sufficient to just test the helper function that I'll create encapsulating this functionality. |
e540971 to
92b30f6
Compare
|
@holmanb ready for re-review! |
880791c to
2b0eb2b
Compare
@holmanb all those double whitespaces are because they are between classes not functions and this is the formatting enforced by ruff. to verify, I removed the double whitespace then ran |
Since Ubuntu 24.04 LTS and newer, the default location for ssh keys is `~/.ssh/id_ed25519` instead of `~/.ssh/id_rsa`. Thus, when no ssh key path is specified, this commit changes pycloudlib to check for an existing ssh key at either `~/.ssh/id_ed25519` or `~/.ssh/id_rsa`. Fixes GH canonical#341
2b0eb2b to
bbb2e80
Compare
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that!
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that!
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that!
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that! Also, migrate existing pytest configuration from tox.ini to pyproject.toml
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that! Also, migrate existing pytest configuration from tox.ini to pyproject.toml
In PR canonical#406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that! Also, migrate existing pytest configuration from tox.ini to pyproject.toml
In PR #406, two pytest marks were added to help with mocking ssh keys in unit tests, but the marks were not registered with pytest so it was raising errors. This commit fixes that! Also, migrate existing pytest configuration from tox.ini to pyproject.toml
PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes/reverts the error that gets raised at the Cloud class instantation when those two cases are true. There was no way for an end user to override/prevent pycloudlib from erroring out besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting their ssh keys.
PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes/reverts the error that gets raised at the Cloud class instantation when those two cases are true. There was no way for an end user to override/prevent pycloudlib from erroring out besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting their ssh keys.
PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes/reverts the error that gets raised at the Cloud class instantation when those two cases are true. There was no way for an end user to override/prevent pycloudlib from erroring out besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting their ssh keys.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR canonical#406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR canonical#406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR canonical#406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR canonical#406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR canonical#406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR canonical#406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
This commit will once again allow for setting ssh keys at runtime using the `Cloud.use_key()` method when default ssh keys dont exist on the system and no ssh key paths are provided in pycloudlib.toml. Further context: PR #406 broke some end consumers/users of pycloudlib on systems where 1) ssh keys are not set in the pycloudlib.toml and the ssh key is later set using the Cloud.use_key() method 2) no ssh keys exist at the default paths of '~/.ssh/id_rsa.pub' or '~/.ssh/id_ed25519.pub'. This commit removes / reverts the error that was introduced in PR #406 which gets raised at the Cloud class instantation when those two cases are true. The biggest issue with this change, is there was no way for an end user to override/prevent pycloudlib from erroring out if those cases are true - besides for creating a fake ssh key at one of the two default paths. Now, a warning is just logged instead, restoring the flexibility pycloudlib preivously provided to end users for setting / using ssh keys. If both scenarios 1 and 2 are true (ssh key is unset/doesn't exist), a new exception type `UnsetSSHKeyError` will be raised with verbose exception message explaining why this happened and how to fix.
Since Ubuntu 24.04 LTS and newer, the default location for ssh keys is
~/.ssh/id_ed25519instead of~/.ssh/id_rsa. Thus, when no ssh keypath is specified, this commit changes pycloudlib to check for an
existing ssh key at either
~/.ssh/id_ed25519or~/.ssh/id_rsa.Fixes GH #341
Testing of changes
Testing id_ed25519 can be found
~/.ssh/id_rsa~/.ssh/id_ed25519public_key_pathandprivate_key_pathfrom[oci]config in my pycloudlib.toml config filepython3 examples/oracle.pyTesting error is raised when neither default key is found
~/.ssh/id_ed25519python3 examples/oracle.pyTesting error is raised when key from config does not exist:
public_key_pathin[oci]config in my pycloudlib.toml config file to be~/.ssh/nonexistant-key.pubpython3 examples/oracle.py