-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add public cloud user modules #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
__metaclass__ = type | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: public_cloud_user | ||
short_description: Manage a OVH public cloud user | ||
description: | ||
- This module manages a OVH public cloud user | ||
author: Jonathan Piron <[email protected]> | ||
requirements: | ||
- ovh >= 0.5.0 | ||
options: | ||
service_name: | ||
required: true | ||
description: | ||
- The service_name | ||
role: | ||
required: false | ||
description: | ||
- the role to assign to the user | ||
roles: | ||
required: false | ||
description: | ||
- the roles to assign to the user | ||
description: | ||
required: false | ||
user_id: | ||
required: false | ||
description: The user_id to manage. Required with state: absent | ||
state: | ||
required: false | ||
default: present | ||
choices: ['present', 'absent'] | ||
description: Indicate the desired state of the public cloud user | ||
|
||
''' | ||
|
||
EXAMPLES = ''' | ||
- name: "Create a user on public cloud OVH" | ||
synthesio.ovh.public_cloud_user: | ||
service_name: "{{ service_name }}" | ||
role: "{{ role }}" | ||
roles: "{{ roles }}" | ||
description: "{{ description }}" | ||
delegate_to: localhost | ||
register: user_creation | ||
|
||
- name: "Wait for user creation completion" | ||
public_cloud_user_info: | ||
service_name: "{{ service_name }}" | ||
user_id: "{{ user_creation.json.id }}" | ||
delegate_to: localhost | ||
register: user_retrieval | ||
until: user_retrieval.status == "ok" | ||
retries: 6 | ||
delay: 5 | ||
''' | ||
|
||
RETURN = ''' # ''' | ||
|
||
from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, OVHResourceNotFound, ovh_argument_spec | ||
|
||
|
||
def run_module(): | ||
module_args = ovh_argument_spec() | ||
module_args.update(dict( | ||
service_name=dict(required=True), | ||
role=dict(required=False, default=None), | ||
roles=dict(required=False, default=None), | ||
description=dict(required=False, default=None), | ||
user_id=dict(required=False, default=None), | ||
state=dict(choices=['present', 'absent'], default='present') | ||
)) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
client = OVH(module) | ||
|
||
service_name = module.params['service_name'] | ||
role = module.params['role'] | ||
roles = module.params['roles'] | ||
description = module.params['description'] | ||
user_id = module.params['user_id'] | ||
state = module.params['state'] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are missing a check mode here |
||
if state == 'absent': | ||
if user_id is None: | ||
module.fail_json(msg="user_id is required with state: absent") | ||
try: | ||
client.wrap_call("DELETE", | ||
f"/cloud/project/{service_name}/user/{user_id}") | ||
except OVHResourceNotFound: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exception should be catched in the OVH class. |
||
module.exit_json(changed=False) | ||
else: | ||
module.exit_json(changed=True) | ||
else: | ||
user = client.wrap_call("POST", | ||
f"/cloud/project/{service_name}/user", | ||
role=role, | ||
description=description, | ||
roles=roles) | ||
module.exit_json(msg="User was created on OVH public cloud", changed=True, **user) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
__metaclass__ = type | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: public_cloud_user_info | ||
short_description: Retrieve info for a OVH public cloud user | ||
description: | ||
- This module retrieves info for a OVH public cloud user | ||
author: Jonathan Piron <[email protected]> | ||
requirements: | ||
- ovh >= 0.5.0 | ||
options: | ||
service_name: | ||
required: true | ||
description: The service_name | ||
user_id: | ||
required: true | ||
description: The user_id to retrieve information about | ||
''' | ||
|
||
EXAMPLES = ''' | ||
synthesio.ovh.public_cloud_user_info: | ||
service_name: "{{ service_name }}" | ||
user_id: "{{ user_id }}" | ||
delegate_to: localhost | ||
''' | ||
|
||
RETURN = ''' # ''' | ||
|
||
from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
||
|
||
def run_module(): | ||
module_args = ovh_argument_spec() | ||
module_args.update(dict( | ||
service_name=dict(required=True), | ||
user_id=dict(required=True), | ||
)) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
client = OVH(module) | ||
|
||
service_name = module.params['service_name'] | ||
user_id = module.params['user_id'] | ||
result = client.wrap_call("GET", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check mode is also missing here |
||
f"/cloud/project/{service_name}/user/{user_id}") | ||
module.exit_json(changed=False, **result) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
__metaclass__ = type | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: public_cloud_user_s3credentials | ||
short_description: Manage s3 credentials for an OVH public cloud user | ||
description: | ||
- This module manages s3 credentials for an OVH public cloud user | ||
author: Jonathan Piron <[email protected]> | ||
requirements: | ||
- ovh >= 0.5.0 | ||
options: | ||
service_name: | ||
required: true | ||
description: | ||
- The service_name | ||
user_id: | ||
required: true | ||
description: The user_id to manage s3 credentials force | ||
access: | ||
required: false | ||
description: The access to delete. Required with state: absent | ||
state: | ||
required: false | ||
default: present | ||
choices: ['present', 'absent'] | ||
description: Indicate the desired state of the S3 credential | ||
|
||
''' | ||
|
||
EXAMPLES = ''' | ||
synthesio.ovh.public_cloud_user_s3credentials: | ||
service_name: "{{ service_name }}" | ||
user_id: "{{ user_id }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As credentials are returned you could maybe add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add an exemple of the |
||
delegate_to: localhost | ||
''' | ||
|
||
RETURN = ''' # ''' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module returns credentials |
||
|
||
from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, OVHResourceNotFound, ovh_argument_spec | ||
|
||
|
||
def run_module(): | ||
module_args = ovh_argument_spec() | ||
module_args.update(dict( | ||
service_name=dict(required=True), | ||
user_id=dict(required=True), | ||
access=dict(required=False, default=None), | ||
state=dict(choices=['present', 'absent'], default='present') | ||
)) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
client = OVH(module) | ||
|
||
service_name = module.params['service_name'] | ||
user_id = module.params['user_id'] | ||
access = module.params['access'] | ||
state = module.params['state'] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing check mode also |
||
if state == 'absent': | ||
if access is None: | ||
module.fail_json(msg="access is required with state: absent") | ||
try: | ||
access = client.wrap_call("GET", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this, you define |
||
f"/cloud/project/{service_name}/user/{user_id}/s3Credentials/{access}") | ||
except OVHResourceNotFound: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exception should be raised by the OVH class |
||
module.exit_json(changed=False) | ||
else: | ||
client.wrap_call("DELETE", | ||
f"/cloud/project/{service_name}/user/{user_id}/s3Credentials/{access}") | ||
module.exit_json(changed=True) | ||
else: | ||
credentials = client.wrap_call("POST", | ||
f'/cloud/project/{service_name}/user/{user_id}/s3Credentials') | ||
module.exit_json(changed=True, **credentials) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
__metaclass__ = type | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: public_cloud_user_s3credentials_info | ||
short_description: Retrieve s3 credentials info for an OVH public cloud user | ||
description: | ||
- This module retrieves s3 credentials info for an OVH public cloud user | ||
author: Jonathan Piron <[email protected]> | ||
requirements: | ||
- ovh >= 0.5.0 | ||
options: | ||
service_name: | ||
required: true | ||
description: The service_name | ||
user_id: | ||
required: true | ||
description: The user_id to retrieve s3 credentials information about | ||
''' | ||
|
||
EXAMPLES = ''' | ||
synthesio.ovh.public_cloud_user_s3credentials_info: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module returns credentials, examples should mention a |
||
service_name: "{{ service_name }}" | ||
user_id: "{{ user_id }}" | ||
delegate_to: localhost | ||
''' | ||
|
||
RETURN = ''' # ''' | ||
|
||
from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
||
|
||
def run_module(): | ||
module_args = ovh_argument_spec() | ||
module_args.update(dict( | ||
service_name=dict(required=True), | ||
user_id=dict(required=True), | ||
)) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
client = OVH(module) | ||
|
||
service_name = module.params['service_name'] | ||
user_id = module.params['user_id'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check mode is missing |
||
result = client.wrap_call("GET", | ||
f"/cloud/project/{service_name}/user/{user_id}/s3Credentials") | ||
module.exit_json(changed=False, results=result) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module returns a json