All Projects → fastruby → dotenv_validator

fastruby / dotenv_validator

Licence: MIT license
This gem check if required env variables are present and its format using the .env and .env.sample files from Dotenv.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to dotenv validator

ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (-45.45%)
Mutual labels:  dotenv, env
webpack-dotenv-plugin
Use dotenv with webpack.
Stars: ✭ 53 (+60.61%)
Mutual labels:  dotenv, env
php-env
A small and fast .env loader for PHP
Stars: ✭ 19 (-42.42%)
Mutual labels:  dotenv, env
envfile
Parse and write environment files with Node.js
Stars: ✭ 42 (+27.27%)
Mutual labels:  dotenv, env
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (+6.06%)
Mutual labels:  dotenv, env
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+118.18%)
Mutual labels:  dotenv, env
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (-6.06%)
Mutual labels:  dotenv, env
checkdotenv
Verify environment variables presence for Node JS.
Stars: ✭ 12 (-63.64%)
Mutual labels:  dotenv, env
env-diff
Env-diff is a lightweight library which sync your .env files with .env.dist by composer scripts, hooks or manual running
Stars: ✭ 24 (-27.27%)
Mutual labels:  env
envman
Manage your .env configuration easily
Stars: ✭ 20 (-39.39%)
Mutual labels:  env
microservice-template
📖 Nest.js based microservice repository template
Stars: ✭ 131 (+296.97%)
Mutual labels:  env
dart environment config
Environment specific config generator for Dart and Flutter applications during CI/CD builds
Stars: ✭ 87 (+163.64%)
Mutual labels:  dotenv
envclasses
envclasses is a library to map fields on dataclass object to environment variables.
Stars: ✭ 26 (-21.21%)
Mutual labels:  env
betterconf
Minimalistic Python library for your configs.
Stars: ✭ 35 (+6.06%)
Mutual labels:  env
dotenv
Load .env files in crystal
Stars: ✭ 16 (-51.52%)
Mutual labels:  dotenv
EnvReportBC
List of repositories administered by Environmental Reporting BC (www.gov.bc.ca/environmental-reporting-bc)
Stars: ✭ 17 (-48.48%)
Mutual labels:  env
django-confy
A comfy config for Django
Stars: ✭ 25 (-24.24%)
Mutual labels:  env
k8s-env-gen
Kubernetes environment generator makes docker env files compatible with kubernetes
Stars: ✭ 19 (-42.42%)
Mutual labels:  env
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (+0%)
Mutual labels:  dotenv
workbench
A hierarchical environment manager for bash, written in bash.
Stars: ✭ 17 (-48.48%)
Mutual labels:  env

Dotenv Validator

Gem Version Matrix Testing + Lint codecov Docs Contributor Covenant

This gem validates .env variables. You can configure validation rules by adding the appropriate comments to the .env.sample file.

Installation

Add the gem to your Gemfile:

gem "dotenv_validator"

Call DotenvValidator.check! in an initializer:

echo "DotenvValidator.check!" > "config/initializers/1_dotenv_validator.rb"

Note the 1_ in the name so it's executed before any other initializer, since initializers are run in alphabetical order.

You can use DotenvValidator.check without the ! to show warnings instead of raising an exception.

Updating

Simply run:

bundle update dotenv_validator

Configuring env variable

In your .env.sample file, you can add comments to tell DotenvValidator how to validate the variable:

MY_REQUIRED_VAR=value #required
THIS_IS_AN_OPTIONAL_INT=123 #format=int
THIS_IS_A_REQUIRED_EMAIL=123 #required,format=email

Formats

  • int or integer or Integer
  • float or Float (note that all integers are floats too)
  • str or string or String (accepts anything)
  • email (checks value against /[\w@]+@[\w@]+\.[\w@]+/)
  • url (checks value against /https?:\/\/.+/)
  • bool or boolean or Boolean (checks value against true or false, case sensitive)
  • uuid or UUID (checks value against /\A[\da-f]{32}\z/i or /\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i)
  • any other value acts as a regexp!

Regexp format

If you have a complex format, you can use a regexp for validation:

MY_WEIRD_ENV_VAR=123_ABC #required,format=\d{3}_\w{3}

In the above example, \d{3}_\w{3} is converted to a regexp and the value is checked against it.

If you use docker-compose, read this

Docker Compose automatically reads .env files present in the project's root when running docker-compose up. What this means is that, if you use dotenv_validator in an app you run using Docker Compose, you might get exceptions or warnings about your variables being in the wrong format even though they're right. The reason is that, when running docker-compose up, docker-compose parses the .env file before the Rails application starts. It reads each line as is with a really simple parser (no quotes, comments and trailing spaces handling).

Then, since docker-compose already set the environment variables, the Dotenv gem won't override them. It parses the file as we'd expect, but it won't change env variables that are already set.

For more information check this page from their docs.

The workaround is to rename your .env file when using docker. Here you'll find all naming options acceptable for dotenv and that Docker will not automatically parse.

If renaming is not an option, then you need to remove any comments or trailing whitespaces from your .env file:

SMTP_PORT=25         #format=int

needs to become:

SMTP_PORT=25

TL;DR

Rename your .env file according to this table

or

Remove all comments and trailing whitespaces

Contributing

Want to make your first contribution to this project? Get started with some of our good first issues!

Bug reports and pull requests are welcome on GitHub at https://github.com/fastruby/dotenv_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

When Submitting a Pull Request:

  • If your PR closes any open GitHub issues, please include Closes #XXXX in your comment

  • Please include a summary of the change and which issue is fixed or which feature is introduced.

  • If changes to the behavior are made, clearly describe what changes.

  • If changes to the UI are made, please include screenshots of the before and after.

Sponsorship

FastRuby.io | Rails Upgrade Services

dotenv_validator is maintained and funded by FastRuby.io. The names and logos for FastRuby.io are trademarks of The Lean Software Boutique LLC.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].