Skip to content
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

Add json_body to api_call #183

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 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,12 +60,15 @@
"""


import json

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

try:
from pulp_glue.common.context import NotImplementedFake
from pulp_glue.common.context import NotImplementedFake, PreprocessedEntityDefinition
except ImportError:
NotImplementedFake = None
PreprocessedEntityDefinition = None


def main():
Expand All @@ -64,11 +77,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 = PreprocessedEntityDefinition(json.loads(json_body))
if module.pulp_ctx.api.operations[operation_id][0].upper() not in ["GET", "HEAD"]:
module.set_changed()
try:
Expand Down
62,703 changes: 54,155 additions & 8,548 deletions tests/fixtures/api_call-0.yml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions tests/fixtures/api_call-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Squeezer/0.0.14-dev
- Squeezer/0.0.18-dev
method: POST
uri: http://pulp.example.org/pulp/api/v3/repositories/file/file/
response:
body:
string: '{"pulp_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/","pulp_created":"2023-05-11T09:10:55.661956Z","versions_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/versions/0/","name":"test_api_call","description":null,"retain_repo_versions":null,"remote":null,"autopublish":false,"manifest":"PULP_MANIFEST"}'
string: '{"pulp_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/","prn":"prn:file.filerepository:019469da-8f49-76d0-9021-41eaef3f831d","pulp_created":"2025-01-15T12:05:18.794070Z","pulp_last_updated":"2025-01-15T12:05:18.799036Z","versions_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/0/","name":"test_api_call","description":null,"retain_repo_versions":null,"remote":null,"autopublish":false,"manifest":"PULP_MANIFEST"}'
headers:
Access-Control-Expose-Headers:
- Correlation-ID
Expand All @@ -27,21 +27,21 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '492'
- '611'
Content-Type:
- application/json
Correlation-ID:
- 97de04214ed04fcb97c7632c109e8bec
- 22d5fe67867a4c439a432ac4d4c5ba2e
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Thu, 11 May 2023 09:10:55 GMT
- Wed, 15 Jan 2025 12:05:18 GMT
Location:
- /pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/
- /pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/
Referrer-Policy:
- same-origin
Server:
- nginx/1.14.1
- nginx/1.22.1
Vary:
- Accept
X-Content-Type-Options:
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/api_call-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Squeezer/0.0.14-dev
- Squeezer/0.0.18-dev
method: GET
uri: http://pulp.example.org/pulp/api/v3/repositories/file/file/?name=test_api_call
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"pulp_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/","pulp_created":"2023-05-11T09:10:55.661956Z","versions_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/file/file/01880a13-e3ad-7499-b985-47f647de54e3/versions/0/","name":"test_api_call","description":null,"retain_repo_versions":null,"remote":null,"autopublish":false,"manifest":"PULP_MANIFEST"}]}'
string: '{"count":1,"next":null,"previous":null,"results":[{"pulp_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/","prn":"prn:file.filerepository:019469da-8f49-76d0-9021-41eaef3f831d","pulp_created":"2025-01-15T12:05:18.794070Z","pulp_last_updated":"2025-01-15T12:05:18.799036Z","versions_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/0/","name":"test_api_call","description":null,"retain_repo_versions":null,"remote":null,"autopublish":false,"manifest":"PULP_MANIFEST"}]}'
headers:
Access-Control-Expose-Headers:
- Correlation-ID
Expand All @@ -23,19 +23,19 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '544'
- '663'
Content-Type:
- application/json
Correlation-ID:
- 237688f19c1e47889fd6f82921fa2838
- 1428c250545f420191bd84957f6654cb
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Thu, 11 May 2023 09:10:56 GMT
- Wed, 15 Jan 2025 12:05:19 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.14.1
- nginx/1.22.1
Vary:
- Accept
X-Content-Type-Options:
Expand Down
100 changes: 100 additions & 0 deletions tests/fixtures/api_call-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
interactions:
- request:
body: '{"description": "This is a repository for testing purpose."}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '60'
Content-Type:
- application/json
User-Agent:
- Squeezer/0.0.18-dev
method: PATCH
uri: http://pulp.example.org/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/
response:
body:
string: '{"task":"/pulp/api/v3/tasks/019469da-9227-7d18-bb6d-2e9de6491108/"}'
headers:
Access-Control-Expose-Headers:
- Correlation-ID
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '67'
Content-Type:
- application/json
Correlation-ID:
- 24b9eba7860e448ca1c074eb2d944390
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 15 Jan 2025 12:05:19 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.22.1
Vary:
- Accept
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 202
message: Accepted
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Correlation-ID:
- 24b9eba7860e448ca1c074eb2d944390
User-Agent:
- Squeezer/0.0.18-dev
method: GET
uri: http://pulp.example.org/pulp/api/v3/tasks/019469da-9227-7d18-bb6d-2e9de6491108/
response:
body:
string: '{"pulp_href":"/pulp/api/v3/tasks/019469da-9227-7d18-bb6d-2e9de6491108/","prn":"prn:core.task:019469da-9227-7d18-bb6d-2e9de6491108","pulp_created":"2025-01-15T12:05:19.527741Z","pulp_last_updated":"2025-01-15T12:05:19.527752Z","state":"completed","name":"pulpcore.app.tasks.base.general_update","logging_cid":"24b9eba7860e448ca1c074eb2d944390","created_by":"/pulp/api/v3/users/1/","unblocked_at":"2025-01-15T12:05:19.534772Z","started_at":"2025-01-15T12:05:19.535327Z","finished_at":"2025-01-15T12:05:19.538602Z","error":null,"worker":null,"parent_task":null,"child_tasks":[],"task_group":null,"progress_reports":[],"created_resources":[],"reserved_resources_record":["prn:file.filerepository:019469da-8f49-76d0-9021-41eaef3f831d","shared:prn:core.domain:019464c8-76fe-7e95-8cca-95f89a4b4718"]}'
headers:
Access-Control-Expose-Headers:
- Correlation-ID
Allow:
- GET, PATCH, DELETE, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '793'
Content-Type:
- application/json
Correlation-ID:
- 24b9eba7860e448ca1c074eb2d944390
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 15 Jan 2025 12:05:19 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.22.1
Vary:
- Accept
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 200
message: OK
version: 1
49 changes: 49 additions & 0 deletions tests/fixtures/api_call-4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- Squeezer/0.0.18-dev
method: GET
uri: http://pulp.example.org/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/
response:
body:
string: '{"pulp_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/","prn":"prn:file.filerepository:019469da-8f49-76d0-9021-41eaef3f831d","pulp_created":"2025-01-15T12:05:18.794070Z","pulp_last_updated":"2025-01-15T12:05:19.537548Z","versions_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/file/file/019469da-8f49-76d0-9021-41eaef3f831d/versions/0/","name":"test_api_call","description":"This
is a repository for testing purpose.","retain_repo_versions":null,"remote":null,"autopublish":false,"manifest":"PULP_MANIFEST"}'
headers:
Access-Control-Expose-Headers:
- Correlation-ID
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '650'
Content-Type:
- application/json
Correlation-ID:
- cf43c9150e7646cf875fd64168d17117
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 15 Jan 2025 12:05:20 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.22.1
Vary:
- Accept
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 200
message: OK
version: 1
Loading
Loading