Skip to content

Add support for environment variable validations - #546

Merged
DannyBen merged 7 commits into
masterfrom
add/environment-variable-validation
Aug 14, 2024
Merged

Add support for environment variable validations#546
DannyBen merged 7 commits into
masterfrom
add/environment-variable-validation

Conversation

@DannyBen

@DannyBenDannyBen commented Aug 14, 2024

Copy link
Copy Markdown
Member

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: clienvironment_variables:
- name: release_dirhelp: Path to the releases folderdefault: releasevalidate: dir_exists
- name: log_dirhelp: Directory for storing log filesdefault: "${RELEASE_DIR}/logs"validate: dir_exists

@DannyBen

Copy link
Copy Markdown
MemberAuthor

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

@EmilyGraceSeville7cfEmilyGraceSeville7cf left a comment

Copy link
Copy Markdown
Collaborator

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.

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

Copy link
Copy Markdown
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.

@DannyBenDannyBenAug 14, 2024

Copy link
Copy Markdown
MemberAuthor

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.

Comment threadschemas/strings.json Outdated
Co-authored-by: Maisa Unbelievable <EmilyGraceSeville7cfg@gmail.com>
@DannyBen
DannyBen merged commit 6f3ed4a into masterAug 14, 2024
@DannyBen
DannyBen deleted the add/environment-variable-validation branch August 14, 2024 14:28
Sign up for freeto 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

@DannyBen@EmilyGraceSeville7cf