Skip to content

Commit

Permalink
Add json_body to api_call
Browse files Browse the repository at this point in the history
This helps providing actual 'null' values in the body.

Fixes #1818
  • Loading branch information
mdellweg committed Jan 14, 2025
1 parent 0fc96e2 commit feec9e5
Show file tree
Hide file tree
Showing 6 changed files with 54,301 additions and 8,565 deletions.
26 changes: 22 additions & 4 deletions plugins/modules/api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
DOCUMENTATION = r"""
---
module: api_call
short_description: TBD
short_description: "Make generic API calls to Pulp"
description:
- "TBD"
- "This allows performing api calls to Pulp by specifying their operation id."
options:
operation_id:
description: "ID of the openapi operation to perform."
Expand All @@ -20,9 +20,19 @@
type: dict
required: false
body:
description: "JSON representation of the body to send in the request (only POST, PUT and PATCH requests.)"
description: |
Representation of the body to send in the request
(only POST, PUT and PATCH requests)
Mutually exclusive with O(json_body).
type: dict
required: false
json_body:
description: |
JSON representation of the body to send in the request
(only POST, PUT and PATCH requests)
Mutually exclusive with O(body).
type: str
required: false
extends_documentation_fragment:
- pulp.squeezer.pulp.glue
- pulp.squeezer.pulp
Expand Down Expand Up @@ -50,6 +60,8 @@
"""


import json

from ansible_collections.pulp.squeezer.plugins.module_utils.pulp_glue import PulpAnsibleModule

try:
Expand All @@ -64,11 +76,17 @@ def main():
"operation_id": {"required": True},
"parameters": {"type": "dict"},
"body": {"type": "dict"},
"json_body": {},
},
mutually_exclusive=[["body", "json_body"]],
) as module:
operation_id = module.params["operation_id"]
parameters = module.params["parameters"]
body = module.params["body"]
json_body = module.params["json_body"]
if json_body is None:
body = module.params["body"]
else:
body = json.loads(json_body)
if module.pulp_ctx.api.operations[operation_id][0].upper() not in ["GET", "HEAD"]:
module.set_changed()
try:
Expand Down
Loading

0 comments on commit feec9e5

Please sign in to comment.