0.0
No commit activity in last 3 years
No release in over 3 years
When you are developing a new feature if your app have some environments like test, staging and production is easy to forget an environment variable in the middle of the process. Also when you migrate the app to another server is easy to forget an environment variable.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 9.0
~> 0.8
~> 11.3
~> 3.5
~> 0.45
~> 0.12

Runtime

~> 0.19.1
 Project Readme

Env-checker

Gem Version Dependency Status Build Status Coverage Status Code Climate license

Don't forget your environment variables when your app changes the environment. When you are developing a new feature if your app have some environments like test, staging and production is easy to forget an environment variable in the middle of the process. Also when you migrate the app to another server is easy to forget an environment variable.

You can define two variable lists:

  • required_variables: These variables are mandatory (Your app cannot run without these variables, like DATABASE_URL)
  • optional_variables: These variables are from secondary services (Your app can run without these variables, like some THRESHOLD)

By default EnvChecker checks the global environment and after the current or set environment.

All the missing variables are notified by default in the STDERR. When a required variable is missing the gem raises an error MissingKeysError and stops the application.

By convention all the environment variable names must be in up case, the gem internally parse the required_variables and optional_variables to up case.

Installation

Add this line to your application's Gemfile:

gem 'env-checker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install env-checker

Usage

Rails or Ruby standalone

Create a initializer to configure the gem and run the hook to check the environment variables. Example:

# config/initializers/env_checker.rb

require 'env_checker'

EnvChecker.configure do |config|
  config.slack_webhook_url = 'https://hooks.slack.com/services/.../.../.../'
  config.optional_variables = %w(MyOptVar1 MyOptVar2)
  config.required_variables = %w(MyReqVar1 MyReqVar2)

  # ENVIRONMENT
  # ===========
  # Default is:
  # environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
  #
  # Other possible value
  # config.environment = 'MyEnv'  

  # LOGGER
  # ======
  # Default is:
  #
  # config.logger = Logger.new(STDERR)
  #
  # Some possible settings:
  # config.logger = Rails.logger                        # Log with all your app's other messages
  # config.logger = Logger.new('log/env_checker.log')   # Use this file
  # config.logger = Logger.new('/dev/null')             # Don't log at all (on a Unix system)
end

Standalone and CLI usages

Check optional and required variables

Inline passing the variables with the shell:

$ env-checker check --optional MyOptVar1 MyOptVar2 --required MyReqVar1 MyReqVar2

Usage:
  env-checker check

Options:
  e, [--environment=ENVIRONMENT]
  cf, [--config-file=CONFIG_FILE]
  r, required, [--required-variables=one two three]
  o, optional, [--optional-variables=one two three]
  slack, [--slack-webhook-url=SLACK_WEBHOOK_URL]
          [--run=RUN]
  • All the parameters can be set by environment variables like:
$ export ENV_CHECKER_ENVIRONMENT=staging
$ export ENV_CHECKER_REQUIRED_VARIABLES=one two three
$ export ENV_CHECKER_OPTIONAL_VARIABLES=one two three
$ export ENV_CHECKER_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/.../.../.../
$ env-checker check
$ env-checker check --config_file sample_config.yml

Show help

$ env-checker help

Show version

$ env-checker version

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ryanfox1985/env-checker/issues and https://github.com/ryanfox1985/env-checker/pulls. 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.

License

The gem is available as open source under the terms of the MIT License.