Skip to content

Commit

Permalink
Modify upon review
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Aug 14, 2024
1 parent 5073299 commit fee82f6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
11 changes: 11 additions & 0 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

# Copyright: Contributors to the Ansible project
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)


def to_list_of_dict(result):
if result is None:
return []
if not isinstance(result, list):
return [result]
20 changes: 11 additions & 9 deletions plugins/modules/credential_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- Alina Buzachis (@alinabuzachis)
short_description: Manage credential types in EDA Controller
description:
- This module allows to create, update or delete a credential type in EDA controller.
- This module allows the user to create, update or delete a credential type in EDA controller.
version_added: 2.0.0
options:
name:
Expand Down Expand Up @@ -44,10 +44,8 @@
description:
- Desired state of the resource. V(exists) will not modify the resource if it is present.
default: "present"
choices: ["present", "absent", "exists"]
choices: ["present", "absent"]
type: str
requirements:
- The 'requests' Python module must be installed.
extends_documentation_fragment:
- ansible.eda.eda_controller.auths
"""
Expand Down Expand Up @@ -75,7 +73,13 @@
"""


RETURN = """ # """
RETURN = """
id:
description: ID of the credential type.
returned: when exists
type: int
sample: 37
"""


from ansible.module_utils.basic import AnsibleModule
Expand All @@ -93,7 +97,7 @@ def main():
description=dict(type="str"),
inputs=dict(type="dict"),
injectors=dict(type="dict"),
state=dict(choices=["present", "absent", "exists"], default="present"),
state=dict(choices=["present", "absent"], default="present"),
)

argument_spec.update(AUTH_ARGSPEC)
Expand Down Expand Up @@ -131,9 +135,7 @@ def main():

# Attempt to look up credential_type based on the provided name
try:
credential_type = controller.get_one_or_many(
"credential-types", name=name, check_exists=(state == "exists")
)
credential_type = controller.get_one_or_many("credential-types", name=name)
if state == "exists":
module.exit_json(**credential_type)
except EDAError as e:
Expand Down
37 changes: 33 additions & 4 deletions plugins/modules/credential_type_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
- The name of the credential type.
type: str
required: false
requirements:
- The 'requests' Python module must be installed.
extends_documentation_fragment:
- ansible.eda.eda_controller.auths
"""
Expand All @@ -41,11 +39,42 @@
"""


RETURN = """ # """
RETURN = """
credential_types:
description: Information about the credential types.
returned: always
type: list
elements: dict
sample: {
"created_at": "2024-08-14T08:30:14.806638Z",
"description": "A test credential type",
"id": 37,
"injectors": {
"extra_vars": {
"field1": "field1"
}
},
"inputs": {
"fields": [
{
"id": "field1",
"label": "Field 5",
"type": "string"
}
]
},
"kind": "cloud",
"managed": false,
"modified_at": "2024-08-14T08:30:14.807549Z",
"name": "Example",
"namespace": null
}
"""


from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.eda.plugins.module_utils.client import Client
from ansible_collections.ansible.eda.plugins.module_utils.common import to_list_of_dict
from ansible_collections.ansible.eda.plugins.module_utils.controller import Controller
from ansible_collections.ansible.eda.plugins.module_utils.errors import EDAError

Expand Down Expand Up @@ -80,7 +109,7 @@ def main():
except EDAError as e:
module.fail_json(msg=f"Failed to get credential type: {e}")

module.exit_json(result=result)
module.exit_json(credential_types=to_list_of_dict(result))


if __name__ == "__main__":
Expand Down

0 comments on commit fee82f6

Please sign in to comment.