reubenmiller / go-c8y-cli

go c8y cli tool for interacting with the Cumulocity IoT API
https://goc8ycli.netlify.app/
MIT License
36 stars 8 forks source link

Feature request, option to print response header #286

Closed PestusAtSAG closed 1 year ago

PestusAtSAG commented 1 year ago

For some more detailed analysis it would be create to have an option to print the response header options from the Server. Maybe following option could be introduced for all commands:

--withResponseHeader (Key, Value)

image

ButKor commented 1 year ago

The recently introduced output-templates could help you here. Just add --outputTemplate "{header:response.header}" to your request:

-> c8y inventory list --outputTemplate '{header:response.header}' -o json
{
  "header": {
    "Cache-Control": "no-cache,no-store,must-revalidate",
    "Connection": "keep-alive",
    "Content-Type": "application/vnd.com.nsn.cumulocity.managedobjectcollection+json;charset=UTF-8;ver=0.9",
    "Date": "Tue, 11 Jul 2023 10:26:49 GMT",
    "Expires": "-1",
    "Pragma": "no-cache",
    "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
    "Vary": "Accept-Encoding, User-Agent",
    "X-Content-Type-Options": "nosniff",
    "X-Frame-Options": "DENY",
    "X-Xss-Protection": "1; mode=block"
  }
}

Here's a link showing what's available in the response variable.

reubenmiller commented 1 year ago

This is also where building a custom extension would be useful for these common use-cases. I am planning on replacing all of the custom in-built views/templates with an extension (which is installed by default)...so maybe a generic template would be useful for that.

But you can just create your own extension and add a template to display the header information, e.g.

Let's assume you are creating an extension called "c8y-utils", it just provides small common/generic utilities.

You can add the following template to it:

file: templates/headers.jsonnet

{
    headers: response.header,
}

Then if you install the extension you can reference it in the --outputTemplate flag:

c8y devices list --outputTemplate utils::headers.jsonnet | jq
reubenmiller commented 1 year ago

Closing as it is already possible to do this using the --outputTemplate <template> global flag.