community.crypto/plugins/module_utils
patchback[bot] 7a1494cbe4
Always generate a new key pair if the private key doesn't exist (#598) (#599)
* Always generate a new key pair if the private key doesn't exist (#597)

This commit updates `KeypairBackend._should_generate()` to first check
if the original private key named by the `path` argument exists, and
return True if it does not. This brings the code in line with
the documentation, which says that a new key will always be generated if
the key file doesn't already exist.

As an alternative to the approach implemented here, I also considered
only modifying the condition in the `fail` branch of the if statement,
but I thought that would not map as cleanly to the behavior specified in
the documentation, so doing it the way I did should make it easier to
check that the code is doing the right thing just by looking at it.
I also considered doing something to make the logic more similar to
`PrivateKeyBackend.needs_regeneration()` (the openssl version of this
functionality), because the two are supposed to be acting the same way,
but I thought that'd be going beyond the scope of just fixing this bug.
If it'd be useful to make both methods work the same way, someone can
refactor the code in a future commit.

* Test different regenerate values with nonexistent keys

This commit changes the test task that generates new keys to use each of
the different values for the `regenerate` argument, which will ensure
that the module is capable of generating a key when no previous key
exists regardless of the value of `regenerate`. Previously, the task
would always run with the `partial_idempotence` value, and that obscured
a bug (#597) that would occur when it was set to `fail`. The bug was
fixed in the previous commit.

(cherry picked from commit ce3299f106)

Co-authored-by: David Zaslavsky <diazona@ellipsix.net>
2023-05-01 21:34:10 +02:00
..
acme Prepare for distutils.version being removed in Python 3.12 (#353) (#354) 2021-12-24 12:15:45 +01:00
compat Remove dependency on ansible.netcommon collection (#2) 2020-03-29 18:44:40 +02:00
crypto openssl_csr: fix bad tests, avoid accepting invalid crl_distribution_points records (#560) (#561) 2023-01-02 17:28:28 +01:00
ecs Add simplified_bsd.txt license file (#467) (#468) 2022-06-02 08:14:26 +02:00
openssh Always generate a new key pair if the private key doesn't exist (#598) (#599) 2023-05-01 21:34:10 +02:00
_version.py [stable-1] Add PSF-license.txt file (#455) 2022-05-16 09:02:58 +02:00
io.py Avoid crash in check mode (#243) 2021-06-02 16:44:26 +02:00
version.py Fix comment. (#372) (#373) 2022-01-06 15:10:40 +01:00