-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ovirt_user: add ssh_public_key (#232)
* ovirt_user: add ssh_public_key * Update ovirt_user.py
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
''' | ||
|
||
|
@@ -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 = ''' | ||
|
@@ -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, | ||
|
@@ -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={ | ||
|