Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for environment variable validations #546

Merged
merged 7 commits into from
Aug 14, 2024

Conversation

DannyBen
Copy link
Owner

@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
Owner 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
Owner 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.

schemas/strings.json Outdated Show resolved Hide resolved
Co-authored-by: Maisa Unbelievable <EmilyGraceSeville7cfg@gmail.com>
@DannyBen DannyBen merged commit 6f3ed4a into master Aug 14, 2024
8 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants