Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
83 stars 66 forks source link

[bug] az iot dps certificate list returns nothing, except with explicit json output #530

Closed Delapouite closed 2 years ago

Delapouite commented 2 years ago

Hi

Describe the bug

While attempting to list the certificates of an IotHub DPS I own, I was surprised that the command did not return anything, despite the fact that I was clearly able to obtain this list through the Azure Portal.

But, it turns out that by simply adding -o json, the CLI is suddently able to display the certificates! So my guess is that there's something wrong with the default "table" output.

To Reproduce

Targeting an IotHub DPS with certificates.

  1. az iot dps certificate list --dps-name=myDPS -g myRG

This command does not print anything after execution

  1. az iot dps certificate list --dps-name=myDPS -g myRG -o json

The same command but with an explicit JSON output does print the certificates array.

Expected behavior

The az iot dps certificate list --dps-name=myDPS -g myRG should display an ASCII table of certificates, like any other commands.

Environment

Thanks!

vilit1 commented 2 years ago

Hi

I cannot reproduce your issue - is there an output flag you have set as a default? Do other CLI commands also give you nothing by default?

If I run:

Other output formats: https://docs.microsoft.com/en-us/cli/azure/format-output-azure-cli

So by default, the json should be returned. You may have set something with az config set or in your environment variables as described here: https://docs.microsoft.com/en-us/cli/azure/format-output-azure-cli#set-the-default-output-format https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration#cli-configuration-values-and-environment-variables

digimaun commented 2 years ago

@vilit1 I think @Delapouite is expecting the table output to work, which you were able to reproduce the issue of no output with table format.

vilit1 commented 2 years ago

oh ok - will look into that

vilit1 commented 2 years ago

Found some useful JMES querying:

to have a table output with the current certificate list (and some values), run az iot dps certificate list --dps-name myDPS --query "value[*].{Name:name, ResourceGroup:resourceGroup, Created:properties.created, Subject:properties.subject, Thumbprint:properties.thumbprint, IsVerified:properties.isVerified}" -o table

I am going to add these transforms into the code so you don't have to write out the jmes queries every time.

digimaun commented 2 years ago

Azure CLI 2.38.0 released today should have the table output fix. If after trying it, you have additional feedback, let us know and we can re-open this issue.