25.04 API and certificates

I’m making efforts to modernise the arensb/ansible-truenas Ansible collection, and whilst battling the pre 25.04 websocket doco (gah), trying to work out what fields are acceptable to the certificate.query order-by argument, I read that the 25.04 API doco is better.

I just spun up a VM, and yes, they’re nicer, but am I blind, or are most of the normal certificate API calls missing/gone?!?

All I see is:

Well, this post got me nowhere :rofl:

What are you trying to do, that you don’t see a way to do with the new API?

We are in the process of migrating to new docs framework and not all endpoints have been moved (this will be complete).

All query methods take the same arguments. The general method to query is covered in the Query Methods section in the Table of Contents.

From the standpoint of the shell middleware client (midclt) they take two positional arguments: (1) array of filters to apply to the query and (2) a JSON object specifying the query-options.

midclt call certificate.query '[]' '{"order_by": ["cert_name"]}' for example.

I just merged a commit to improve the docs here:

So it will appear like this:

Hi @dan, I thought I was clear – certificate.query is clearly missing (from the doco anyway). So that was my first issue. The second is what fields are valid to supply to order_by, based on the different API calls (because of course, different valid options to order_by will vary based on the call).

It looks like @awalkerix addressed the issue either way.

So, for example, trying to certificate.query using order_by not_after doesn’t work. cert-name does.

FYI we have an API documentation site here: https://api.truenas.com/

The 25.10 version will be updated weekly based on current development status.

2 Likes

If you look at the documentation for certificate query:
https://api.truenas.com/v25.10.0/api_methods_certificate.query.html

you can see the entry fields in the “Return value” section. These are the valid choices for order_by and select query-options. They are also the field names that can be used for query-filters.

Ok, so this is my point.

Looking at said doco, there is a return value of expired. API calls fail with KeyError:

truenas2504% midclt call certificate.query '[]' '{"order_by": ["expired"]}'  
'expired'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/middlewared/api/base/server/ws_handler/rpc.py", line 323, in process_method_call
    result = await method.call(app, params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/api/base/server/method.py", line 40, in call
    result = await self.middleware.call_with_audit(self.name, self.serviceobj, methodobj, params, app)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 883, in call_with_audit
    result = await self._call(method, serviceobj, methodobj, params, app=app,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 692, in _call
    return await methodobj(*prepared_call.args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 48, in nf
    res = await f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 174, in nf
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/service/crud_service.py", line 243, in query
    result = await self.middleware.call(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 977, in call
    return await self._call(
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 692, in _call
    return await methodobj(*prepared_call.args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 174, in nf
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/datastore/read.py", line 128, in query
    order_by[i] = self._get_col(table, order, prefix)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/datastore/schema.py", line 23, in _get_col
    raise KeyError(name)
KeyError: 'expired'

Same for, for example, until.

Okay. That looks like an actual bug in the certificate plugin. Please file a jira bug report.

1 Like

I filed a bug ticket regarding the query method Jira

(NAS-135885)

Nice one, thanks. I had been busy all week.

Seems like I don’t have permission to view that Jira specifically though – “You don’t have access to this work item”