Skip to content

Conversation

@DannyBen
Copy link
Member

@DannyBen DannyBen commented Aug 14, 2024

Adds support for using validate (custom validations) in environment variables.

Discovered in #545

Todo

  • Initial pilot
  • Confirmed implementation
  • Example
  • Tests
  • Update bashly YAML/JSON schema
  • Update strings JSON schema
  • Update bashly docs command
  • Specs pass
  • Rubocop pass
  • Update doc site

Sample bashly.yml

name: cli environment_variables: - name: release_dir help: Path to the releases folder default: release validate: dir_exists - name: log_dir help: Directory for storing log files default: "${RELEASE_DIR}/logs" validate: dir_exists
@DannyBen
Copy link
Member Author

@EmilyGraceSeville7cf - would you mind double checking my schema changes?

Copy link
Collaborator

@EmilyGraceSeville7cf EmilyGraceSeville7cf left a comment

Choose a reason for hiding this comment

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

LGTM 😄 I have some notes about changes, but they are not required to be applied.

"validate": {
"title": "validate",
"description": "A validation function for the current environment variable\nhttps://bashly.dannyb.co/configuration/environment-variable/#validate",
"type": "string",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"type": "string",
"type": "string",
"minLength": 1,
"pattern": "^\\s+|\\s+$"

I suggest adding more validations. I am not sure whether spacing matters, but I would prefer to have spacing checks done.

Copy link
Member Author

@DannyBen DannyBen Aug 14, 2024

Choose a reason for hiding this comment

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

Thank you. I applied the correction in the strings.json. As for the bashly.json, I am leaving it as is. Rationale:

  1. the bashly.json is generated from support/schema/bashly.yml
  2. the new validate in environment_variables is a copy-paste from the same function in args and flags
  3. I prefer these schemas to be a guide rather than being a complete lockdown on the exact requirements. Easier to maintain.

If you feel strongly otherwise, I might accept a separate PR with changes to bashly.yml rather than the JSON artifact.

Co-authored-by: Maisa Unbelievable <EmilyGraceSeville7cfg@gmail.com>
@DannyBen DannyBen merged commit 6f3ed4a into master Aug 14, 2024
@DannyBen DannyBen deleted the add/environment-variable-validation branch August 14, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants