hqdncw / vault-autopilot

HashiCorp Vault management made easy. Define your desired state, automate the rest.
https://hqdncw.github.io/vault-autopilot/
MIT License
2 stars 0 forks source link

Improve error messages for static/runtime validations #7

Open hqdncw opened 11 months ago

hqdncw commented 11 months ago

Currently, the vault-autopilot CLI does not offer user-friendly error messages when it encounters problems with configuration or manifest files. Specifically, the error messages do not provide enough information about the location of the problem within the files, making it challenging for users to quickly diagnose and address the root cause of the problem.

For example, consider the following manifest file:

kind: "Issuer"
spec:
  name: "root-2024"
  secretEngine: "pki"
  certificate:
    commonName: "example.com Root Authority"

When applying this manifest file using the vault-autopilot apply, the error message displayed is not intuitive for users:

$ vault-autopilot -c config.yaml apply -f manifest.yaml
Error: Invalid manifest file: Failed to validate '../local/test.yaml': [{'type': 'missing', 'loc': ('spec', 'certificate', 'type'), 'msg': 'Field is required', 'input': {'com
monName': 'example.com Root Authority'}}]

Proposed improvement

For instance, if there's an issue with a manifest file, the CLI could display a detailed error message listing the specific fields that are missing or incorrect, along with the exact lines in the file where the problems are located.

With the proposed improvements, the output of the command could look something like this:

$ vault-autopilot -c config.yaml apply -f manifest.yaml
Error: Invalid manifest file: Failed to validate 'manifest.yaml':
  * 'type' is a required field in 'csrParams' (at line 5, column 3)

Please correct the highlighted fields in your manifest file and try again.