Skip to content

Add support for excluding a list of parameters from an API response #163

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pearl1594
Copy link
Contributor

This PR address ##149, it adds an exclude parameter to remove fields from the response

For example, without the exclude parameter, the listAccounts response looks like:

$ ./cmk -p pd-env list accounts name=admin
{
  "account": [
    {
      "accounttype": 1,
      "apikeyaccess": "INHERIT",
      "backupavailable": "Unlimited",
      "backuplimit": "Unlimited",
      "backupstorageavailable": "Unlimited",
      "backupstoragelimit": "Unlimited",
      "backupstoragetotal": 0,
      "backuptotal": 0,
      "bucketavailable": "Unlimited",
      "bucketlimit": "Unlimited",
      "buckettotal": 0,
      "cpuavailable": "Unlimited",
      "cpulimit": "Unlimited",
      "cputotal": 4,
      "domain": "ROOT",
      "domainid": "db0704ab-5827-11f0-804a-1e0052000469",
      "domainpath": "ROOT",
      "groups": [],
      "id": "24e85a59-5828-11f0-804a-1e0052000469",
      "ipavailable": "Unlimited",
      "iplimit": "Unlimited",
      "iptotal": 1,
      "isdefault": true,
      "memoryavailable": "Unlimited",
      "memorylimit": "Unlimited",
      "memorytotal": 4096,
      "name": "admin",
      "networkavailable": "Unlimited",
      "networklimit": "Unlimited",
      "networktotal": 1,
      "objectstorageavailable": "Unlimited",
      "objectstoragelimit": "Unlimited",
      "objectstoragetotal": 0,
      "primarystorageavailable": "Unlimited",
      "primarystoragelimit": "Unlimited",
      "primarystoragetotal": 16,
      "projectavailable": "Unlimited",
      "projectlimit": "Unlimited",
      "projecttotal": 0,
      "receivedbytes": 1346690740,
      "roleid": "fff4ee8f-5827-11f0-804a-1e0052000469",
      "rolename": "Root Admin",
      "roletype": "Admin",
      "secondarystorageavailable": "Unlimited",
      "secondarystoragelimit": "Unlimited",
      "secondarystoragetotal": 0,
      "sentbytes": 35867842,
      "snapshotavailable": "Unlimited",
      "snapshotlimit": "Unlimited",
      "snapshottotal": 0,
      "state": "enabled",
      "templateavailable": "Unlimited",
      "templatelimit": "Unlimited",
      "templatetotal": 0,
      "user": [
        {
          "account": "admin",
          "accountid": "24e85a59-5828-11f0-804a-1e0052000469",
          "accounttype": 1,
          "apikey": "LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q",
          "created": "2025-07-03T16:09:48+0000",
          "domain": "ROOT",
          "domainid": "db0704ab-5827-11f0-804a-1e0052000469",
          "firstname": "admin",
          "id": "24e902f0-5828-11f0-804a-1e0052000469",
          "is2faenabled": false,
          "is2famandated": false,
          "iscallerchilddomain": false,
          "isdefault": true,
          "lastname": "cloud",
          "roleid": "fff4ee8f-5827-11f0-804a-1e0052000469",
          "rolename": "Root Admin",
          "roletype": "Admin",
          "state": "enabled",
          "username": "admin",
          "usersource": "native"
        },
        {
          "account": "admin",
          "accountid": "24e85a59-5828-11f0-804a-1e0052000469",
          "accounttype": 1,
          "apikey": "U7qz8y6CjK1ECQsOuRLT7XaIfaWF3QuB4VJBHvDOBfQjyzsVvhWgDhMkHveJzu1Bb7oFnYKG4CZAfdHLpnim6w",
          "created": "2025-07-09T17:26:05+0000",
          "domain": "ROOT",
          "domainid": "db0704ab-5827-11f0-804a-1e0052000469",
          "email": "kubeadmin",
          "firstname": "admin",
          "id": "8ea65043-7df2-4906-8953-641a7e25a5cf",
          "is2faenabled": false,
          "is2famandated": false,
          "iscallerchilddomain": false,
          "isdefault": false,
          "lastname": "kubeadmin",
          "roleid": "fff4ee8f-5827-11f0-804a-1e0052000469",
          "rolename": "Root Admin",
          "roletype": "Admin",
          "state": "enabled",
          "username": "admin-kubeadmin",
          "usersource": "native"
        }
      ],
      "vmavailable": "Unlimited",
      "vmlimit": "Unlimited",
      "vmrunning": 2,
      "vmstopped": 0,
      "vmtotal": 2,
      "volumeavailable": "Unlimited",
      "volumelimit": "Unlimited",
      "volumetotal": 2,
      "vpcavailable": "Unlimited",
      "vpclimit": "Unlimited",
      "vpctotal": 0
    }
  ],
  "count": 1
}

With this patch, if user wants to remove user field from the response, they could do so using the exclude param:

$ ./cmk -p pd-env list accounts name=admin exclude=user
{
  "account": [
    {
      "accounttype": 1,
      "apikeyaccess": "INHERIT",
      "backupavailable": "Unlimited",
      "backuplimit": "Unlimited",
      "backupstorageavailable": "Unlimited",
      "backupstoragelimit": "Unlimited",
      "backupstoragetotal": 0,
      "backuptotal": 0,
      "bucketavailable": "Unlimited",
      "bucketlimit": "Unlimited",
      "buckettotal": 0,
      "cpuavailable": "Unlimited",
      "cpulimit": "Unlimited",
      "cputotal": 4,
      "domain": "ROOT",
      "domainid": "db0704ab-5827-11f0-804a-1e0052000469",
      "domainpath": "ROOT",
      "groups": [],
      "id": "24e85a59-5828-11f0-804a-1e0052000469",
      "ipavailable": "Unlimited",
      "iplimit": "Unlimited",
      "iptotal": 1,
      "isdefault": true,
      "memoryavailable": "Unlimited",
      "memorylimit": "Unlimited",
      "memorytotal": 4096,
      "name": "admin",
      "networkavailable": "Unlimited",
      "networklimit": "Unlimited",
      "networktotal": 1,
      "objectstorageavailable": "Unlimited",
      "objectstoragelimit": "Unlimited",
      "objectstoragetotal": 0,
      "primarystorageavailable": "Unlimited",
      "primarystoragelimit": "Unlimited",
      "primarystoragetotal": 16,
      "projectavailable": "Unlimited",
      "projectlimit": "Unlimited",
      "projecttotal": 0,
      "receivedbytes": 1346706148,
      "roleid": "fff4ee8f-5827-11f0-804a-1e0052000469",
      "rolename": "Root Admin",
      "roletype": "Admin",
      "secondarystorageavailable": "Unlimited",
      "secondarystoragelimit": "Unlimited",
      "secondarystoragetotal": 0,
      "sentbytes": 35872906,
      "snapshotavailable": "Unlimited",
      "snapshotlimit": "Unlimited",
      "snapshottotal": 0,
      "state": "enabled",
      "templateavailable": "Unlimited",
      "templatelimit": "Unlimited",
      "templatetotal": 0,
      "vmavailable": "Unlimited",
      "vmlimit": "Unlimited",
      "vmrunning": 2,
      "vmstopped": 0,
      "vmtotal": 2,
      "volumeavailable": "Unlimited",
      "volumelimit": "Unlimited",
      "volumetotal": 2,
      "vpcavailable": "Unlimited",
      "vpclimit": "Unlimited",
      "vpctotal": 0
    }
  ],
  "count": 1
}

@Pearl1594 Pearl1594 requested review from shwstppr and nvazquez July 22, 2025 13:58
@Pearl1594 Pearl1594 linked an issue Jul 22, 2025 that may be closed by this pull request
@shwstppr shwstppr added this to the 6.5.0 milestone Jul 24, 2025
Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

(test) 🐱 > list zones exclude=zonetoken,id
{
  "count": 2,
  "zone": [
    {
      "allocationstate": "Enabled",
      "allowuserspecifyvrmtu": false,
      "asnrange": "",
      "dhcpprovider": "VirtualRouter",
      "dns1": "10.147.28.6",
      "guestcidraddress": "10.1.1.0/24",
      "hasannotations": false,
      "internaldns1": "10.147.28.6",
      "ismultiarch": false,
      "isnsxenabled": false,
      "localstorageenabled": false,
      "name": "zim1",
      "networktype": "Advanced",
      "routedmodeenabled": true,
      "routerprivateinterfacemaxmtu": 1500,
      "routerpublicinterfacemaxmtu": 1500,
      "securitygroupsenabled": false,
      "tags": [],
      "type": "Core"
    },
    {
      "allocationstate": "Enabled",
      "allowuserspecifyvrmtu": false,
      "asnrange": "",
      "dhcpprovider": "VirtualRouter",
      "dns1": "10.147.29.6",
      "guestcidraddress": "10.1.2.0/24",
      "hasannotations": false,
      "internaldns1": "10.147.29.6",
      "ismultiarch": false,
      "isnsxenabled": false,
      "localstorageenabled": false,
      "name": "zim2",
      "networktype": "Advanced",
      "routedmodeenabled": true,
      "routerprivateinterfacemaxmtu": 1500,
      "routerpublicinterfacemaxmtu": 1500,
      "securitygroupsenabled": false,
      "tags": [],
      "type": "Core"
    }
  ]
}

Others can comment if the parameter name can be improved. Though this works too

@shwstppr
Copy link
Contributor

shwstppr commented Aug 1, 2025

@Pearl1594 can we name the new param - filterexclude?

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 this pull request may close these issues.

Reverse parameter filtering
2 participants