anchore / anchore-cli

Simple command-line client to the Anchore Engine service
Apache License 2.0
114 stars 54 forks source link

Produce hints when JSON fails validation #46

Closed alfredodeza closed 4 years ago

alfredodeza commented 4 years ago

Fixes: #31

Example output with no keys in JSON file:

$ anchore-cli policy add foo.json
Detail: 'id' is a required property
Hint: The "id" key is not present in the JSON file, make sure it exists:

    {
        "id": <value>
        ...
    }

And with "id" and nothing else:

$ anchore-cli policy add foo.json
Detail: 'version' is a required property
Hint: The "version" key is not present in the JSON file, make sure it exists:

    {
        "version": <value>
        ...
    }

I would prefer to have the keys and errors coming in from the validation endpoint rather than to have to extract the information like this. When/if that happens we can clean this up and remove the utility (or expand it to use the richer validation information)

zhill commented 4 years ago

I would prefer to have the keys and errors coming in from the validation endpoint rather than to have to extract the information like this. When/if that happens we can clean this up and remove the utility (or expand it to use the richer validation information)

I agree. The backend could be much richer with the detail information, but this is an improvement.

zhill commented 4 years ago

Tracking the service api issue in anchore/anchore-engine#330. Thanks for opening that, @alfredodeza !