1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ipa_user sshpubkey can now support multi word comments in the key (#2159) (#2200)

* ipa_user sshpubkey can now support multi word comments in the key

* Add documentation fragment for pull request

* Update changelogs/fragments/2159-ipa-user-sshpubkey-multi-word-comments.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Cleaner implementation of multi word comments

Co-authored-by: Chris Costa <chris.costa@compellingtech.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 7f91821bcc)

Co-authored-by: justchris1 <30219018+justchris1@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-04-07 20:42:03 +02:00 committed by GitHub
parent 5b33b0f61f
commit 4b54805693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ipa_user - allow ``sshpubkey`` to permit multiple word comments (https://github.com/ansible-collections/community.general/pull/2159).

View file

@ -269,16 +269,18 @@ def get_user_diff(client, ipa_user, module_user):
def get_ssh_key_fingerprint(ssh_key, hash_algo='sha256'): def get_ssh_key_fingerprint(ssh_key, hash_algo='sha256'):
""" """
Return the public key fingerprint of a given public SSH key Return the public key fingerprint of a given public SSH key
in format "[fp] [user@host] (ssh-rsa)" where fp is of the format: in format "[fp] [comment] (ssh-rsa)" where fp is of the format:
FB:0C:AC:0A:07:94:5B:CE:75:6E:63:32:13:AD:AD:D7 FB:0C:AC:0A:07:94:5B:CE:75:6E:63:32:13:AD:AD:D7
for md5 or for md5 or
SHA256:[base64] SHA256:[base64]
for sha256 for sha256
Comments are assumed to be all characters past the second
whitespace character in the sshpubkey string.
:param ssh_key: :param ssh_key:
:param hash_algo: :param hash_algo:
:return: :return:
""" """
parts = ssh_key.strip().split() parts = ssh_key.strip().split(None, 2)
if len(parts) == 0: if len(parts) == 0:
return None return None
key_type = parts[0] key_type = parts[0]
@ -293,8 +295,8 @@ def get_ssh_key_fingerprint(ssh_key, hash_algo='sha256'):
if len(parts) < 3: if len(parts) < 3:
return "%s (%s)" % (key_fp, key_type) return "%s (%s)" % (key_fp, key_type)
else: else:
user_host = parts[2] comment = parts[2]
return "%s %s (%s)" % (key_fp, user_host, key_type) return "%s %s (%s)" % (key_fp, comment, key_type)
def ensure(module, client): def ensure(module, client):