Last active
December 8, 2017 13:59
-
-
Save aereal/506fb70b33e37fd9d7b525f5ff2cecd9 to your computer and use it in GitHub Desktop.
validates against environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'json-schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bundler/setup' unless defined?(Bundler) | |
require 'json' | |
require 'json-schema' | |
schema = JSON.parse(DATA.read) | |
begin | |
JSON::Validator.validate!(schema, ENV.to_h) | |
rescue JSON::Schema::ValidationError => error | |
warn error.message | |
exit 1 | |
end | |
__END__ | |
{ | |
"title": "Schema of some script's environment variables", | |
"$schema": "http://json-schema.org/draft-06/schema#", | |
"type": "object", | |
"properties": { | |
"DEBUG": { | |
"type": "string", | |
"enum": [ | |
"1", | |
"0" | |
] | |
}, | |
"LOGLEVEL": { | |
"type": "string", | |
"enum": [ | |
"0", "1", "2", "3", "4", "5", "6", "7" | |
] | |
}, | |
"PLACK_ENV": { | |
"type": "string", | |
"enum": [ | |
"development", "test", "production" | |
] | |
}, | |
"PATH": { | |
"type": "string", | |
"pattern": "[^:]+(:[^:]+)*" | |
} | |
}, | |
"required": [ | |
"PLACK_ENV" | |
] | |
} |
Author
aereal
commented
Dec 8, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment