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

api_call: can't set body.content_object value to null #181

Open
netsandbox opened this issue Jan 14, 2025 · 5 comments · May be fixed by #183
Open

api_call: can't set body.content_object value to null #181

netsandbox opened this issue Jan 14, 2025 · 5 comments · May be fixed by #183

Comments

@netsandbox
Copy link
Contributor

Regarding to https://pulpproject.org/pulpcore/restapi/#tag/Users:-Roles/operation/users_roles_create, if you want to create a user role which applies to all objects, you should set the content_object value to null.

Actually this does not work with the api_call module.

Example:

- name: Set user role
  pulp.squeezer.api_call:
    operation_id: users_roles_create
    parameters:
      auth_user_href: my_href
    body:
      role: rpm.viewer
      content_object: null

This example results in the following error:

The full traceback is:
  File "/tmp/ansible_pulp.squeezer.api_call_payload_lv522exd/ansible_pulp.squeezer.api_call_payload.zip/ansible_collections/pulp/squeezer/plugins/modules/api_call.py", line 72, in main
  File "/home/me/.local/lib/python3.10/site-packages/pulp_glue/common/context.py", line 473, in call
    raise PulpException(str(e))
fatal: [pulp-api-local]: FAILED! => changed=true 
  invocation:
    module_args:
      body:
        content_object: null
        role: rpm.viewer
      operation_id: users_roles_create
      parameters:
        auth_user_href: my_href
      password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      pulp_url: http://localhost:8080
      refresh_api_cache: false
      timeout: 10
      user_cert: null
      user_key: null
      username: admin
      validate_certs: false
  msg: |-
    Validation failed for 'users_roles_create':
      application/json: Required properties(s) '{'content_object'}' of 'body' missing.
      application/x-www-form-urlencoded: Required properties(s) '{'content_object'}' of 'body' missing.
      multipart/form-data: Required properties(s) '{'content_object'}' of 'body' missing.

I also tried different values for content_object, which all not work:

  • 'null'
  • "null"
  • "{{ None | to_json }}"

In the pulp cli help they say that you have to set a empty string for the object parameter, which actually works there:

$ pulp -p hblocal user role-assignment add --username user --role rpm.viewer --object=""
{
  "pulp_href": "redacted",
  "prn": "prn:core.userrole:redacted",
  "pulp_created": "2025-01-14T08:39:49.484327Z",
  "pulp_last_updated": "2025-01-14T08:39:49.484340Z",
  "role": "rpm.viewer",
  "content_object": null,
  "description": null,
  "permissions": [
    "rpm.view_rpmalternatecontentsource",
    "rpm.view_rpmdistribution",
    "rpm.view_rpmpublication",
    "rpm.view_rpmremote",
    "rpm.view_rpmrepository",
    "rpm.view_ulnremote"
  ],
  "domain": null
}

Versions:
pulp.squeezer: 0.0.17
pulp: 3.69.0
pulp-cli: 0.29.2
pulp-glue: 0.29.2

@mdellweg
Copy link
Member

I can see, where this comes from. Ansible eats the None before we have a chance to see it. And the api call module is a bit too generic to transform all empty strings to None. I don't now which special object to abuse for this.
You may need to look into writing that module.

@mdellweg
Copy link
Member

Maybe if we allowed to whole body to be passed as a json string. It doesn't sound like "ansible philosophy", but well...

mdellweg added a commit to mdellweg/squeezer that referenced this issue Jan 14, 2025
This helps providing actual 'null' values in the body.

Fixes pulp#181
@mdellweg mdellweg linked a pull request Jan 14, 2025 that will close this issue
@mdellweg
Copy link
Member

Can you try again with the attached PR?

@netsandbox
Copy link
Contributor Author

I integrated your changes and changed my task to:

- name: Set user role
  pulp.squeezer.api_call:
    operation_id: users_roles_create
    parameters:
      auth_user_href: "{{ auth_user_href }}"
    json_body: |
      {"role": "rpm.viewer", "content_object": null}

and get now the following error:

TASK [pulp_repos : Set user role] ******************************************************************************************************************************************************************
fatal: [pulp-api-local]: FAILED! => changed=true 
  msg: |-
    Validation failed for 'users_roles_create':
      application/json: Required properties(s) '{'content_object'}' of 'body' missing.
      application/x-www-form-urlencoded: Required properties(s) '{'content_object'}' of 'body' missing.
      multipart/form-data: Required properties(s) '{'content_object'}' of 'body' missing.

mdellweg added a commit to mdellweg/squeezer that referenced this issue Jan 15, 2025
This helps providing actual 'null' values in the body.

Fixes pulp#181
@mdellweg
Copy link
Member

I think I have fixed that now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants