Skip to content

Commit

Permalink
ovirt_user: add ssh_public_key (#232)
Browse files Browse the repository at this point in the history
* ovirt_user: add ssh_public_key

* Update ovirt_user.py
  • Loading branch information
mnecas authored Mar 16, 2021
1 parent 3be5076 commit 2d7eb1d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/modules/ovirt_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
- "Namespace where the user resides. When using the authorization provider that stores users in the LDAP server,
this attribute equals the naming context of the LDAP server."
type: str
ssh_public_key:
description:
- "The user public key."
type: str
extends_documentation_fragment: @NAMESPACE@.@[email protected]
'''

Expand All @@ -76,6 +80,12 @@
state: absent
name: user1
authz_name: example.com-authz
# Remove ssh_public_key
- @NAMESPACE@.@[email protected]_user:
name: user1
authz_name: example.com-authz
ssh_public_key: ""
'''

RETURN = '''
Expand Down Expand Up @@ -134,6 +144,7 @@ def main():
name=dict(required=True),
authz_name=dict(required=True, aliases=['domain']),
namespace=dict(default=None),
ssh_public_key=dict(default=None),
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand All @@ -160,6 +171,20 @@ def main():
'usrname': username(module),
}
)
if module.params['ssh_public_key'] is not None:
ssh_public_keys_service = users_service.user_service(ret['id']).ssh_public_keys_service()
ssh_public_keys = ssh_public_keys_service.list()
if ssh_public_keys:
if not module.params['ssh_public_key']:
ssh_public_keys_service.service(ssh_public_keys[0].id).remove()
ret['changed'] = True
elif module.params['ssh_public_key'] != ssh_public_keys[0].content:
ssh_public_keys_service.service(ssh_public_keys[0].id).update(otypes.SshPublicKey(content=module.params['ssh_public_key']))
ret['changed'] = True
elif module.params['ssh_public_key']:
ssh_public_keys_service.add(otypes.SshPublicKey(content=module.params['ssh_public_key']))
ret['changed'] = True

elif state == 'absent':
ret = users_module.remove(
search_params={
Expand Down

0 comments on commit 2d7eb1d

Please sign in to comment.