{"id":14985643,"url":"https://github.com/nsweeting/exenv","last_synced_at":"2025-04-11T22:04:40.380Z","repository":{"id":54713998,"uuid":"138930506","full_name":"nsweeting/exenv","owner":"nsweeting","description":"Exenv makes loading environment variables from external sources easy.","archived":false,"fork":false,"pushed_at":"2021-02-02T19:35:30.000Z","size":39,"stargazers_count":37,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-25T20:43:01.457Z","etag":null,"topics":["config","dotenv","elixir","env","environment-variables","secrets","yaml","yml"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsweeting.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-27T20:37:47.000Z","updated_at":"2023-12-27T17:20:20.000Z","dependencies_parsed_at":"2022-08-14T00:40:41.516Z","dependency_job_id":null,"html_url":"https://github.com/nsweeting/exenv","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fexenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fexenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fexenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fexenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsweeting","download_url":"https://codeload.github.com/nsweeting/exenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239785314,"owners_count":19696754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","dotenv","elixir","env","environment-variables","secrets","yaml","yml"],"created_at":"2024-09-24T14:11:25.111Z","updated_at":"2025-02-20T05:32:09.365Z","avatar_url":"https://github.com/nsweeting.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exenv\n\n[![Build Status](https://travis-ci.org/nsweeting/exenv.svg?branch=master)](https://travis-ci.org/nsweeting/exenv)\n[![Exenv Version](https://img.shields.io/hexpm/v/exenv.svg)](https://hex.pm/packages/exenv)\n\nExenv provides an adapter-based solution to loading environment variables from\nexternal sources.\n\nIt comes with the following adapter:\n\n* `Exenv.Adapters.Dotenv` (load from .env files)\n\nBut has support from external adapters as well:\n\n* [Exenv.Adapters.Yaml](https://github.com/nsweeting/exenv_yaml) (load from .yml files)\n\n## Installation\n\nThis package can be installed by adding `exenv` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:exenv, \"~\u003e 0.3\"}\n  ]\nend\n```\n\n## Documentation\n\nPlease see [HexDocs](https://hexdocs.pm/exenv/Exenv.html#content) for additional\ndocumentation. This readme provides a brief overview, but it is recommended that\nthe docs are used.\n\n## Getting Started\n\nIf all you want is to load a `.env` file on application start - then you're already\ndone! Out of the box, `Exenv` is configured to start itself with the `Exenv.Adapters.Dotenv`\nadapter configured with sane defaults. This means autoloading on application start - with\nthe `.env` file required to be within your projects root directory.\n\n## Configuration\n\nIf you need finer grained control of things, `Exenv` provides extensive config mechansims.\n\nWe can pass configuration options to `Exenv` from application config.\n\n```elixir\nconfig :exenv, [\n  adapters: [\n    {Exenv.Adapters.Dotenv, [file: \"path/to/.env\"]}\n  ]\n]\n```\n\nYou can also run `Exenv` via your own supervision tree. In this case, you must instruct\n`Exenv` not to start itself.\n\n```elixir\nconfig :exenv, start_on_application: false\n```\n\nWhich allows you to add `Exenv` to your own application.\n\n```elixir\ndefmodule MySupervisor do\n  use Supervisor\n\n  def start_link(opts) do\n    Supervisor.start_link(__MODULE__, :ok, opts)\n  end\n\n  def init(:ok) do\n    children = [\n      {Exenv, [adapters: [{Exenv.Adapters.Dotenv, [file: \"path/to/.env\"]}]]}\n    ]\n\n    Supervisor.init(children, strategy: :one_for_one)\n  end\nend\n```\n\nOptions passed to the `child_spec/1` callback take precedence over any application\nconfig.\n\nBy default, all adapters will autoload their environment vars when `Exenv` starts up.\nYou can override this behaviour on a per-adapter basis, by simply passing the\n`autoload: false` key within your adapter config.\n\n```elixir\n[\n  adapters: [\n    {Exenv.Adapters.Dotenv, [autoload: false, file: \"path/to/.env\"]}\n  ]\n]\n```\n\nYou must then manually load all env vars from your defined adapters:\n\n```elixir\nExenv.load()\n```\n\n## Runtime path evaluation\n\nAny location where you pass a file path you can choose to instead pass an mfa\nwhich will be run and should evaluate to a proper file path. This allows for easier\nruntime setup of files.\n\n```elixir\nconfig :exenv, [\n  adapters: [\n    {Exenv.Adapters.Dotenv, [file: {MyApp, :get_dotenv, []}]}\n  ]\n]\n```\n\n## Encryption\n\nExenv has secrets encryption out of the box. Support will depend on the whether\nthe adapter provides it. Using secrets encryption allows you to keep an encrypted\nversion of your secrets checked into your repository. As long as the master key\nis accessible, these secrets can then be decrypted.\n\nTo get started with secrets encryption, first generate a master key.\n\n```bash\nmix exenv.master_key /config/master.key\n```\n\nThis will generate a new master key at `/config/master.key`. You can then encrypt\nyour secrets file.\n\n```bash\nmix exenv.encrypt /config/master.key /config/.env\n```\n\nThis will encrypt the contents of `/config/.env` using `/config/master.key`. A new\nfile will then be generated at `/config/.env.enc` with your encrypted secrets.\n\nYou must then provide the proper options to your adapters to enable encryption.\n\n```elixir\n{Exenv.Adapters.Dotenv, [file: \"path/to/.env.enc\", encryption: true]}\n```\n\nThe above will attempt to decrypt `\"path/to/.env.enc\"` using the contents of the\n`\"MASTER_KEY\"` env var. Alternatively, you can also provide a direct path to the\nmaster key file.\n\n```elixir\n{Exenv.Adapters.Dotenv, [file: \"path/to/.env.enc\", encryption: [master_key: \"path/to/master.key\"]]}\n```\n\nTo edit your secrets, you just need to decrypt the original encrypted secrets, and\nrencrypt the edited file.\n\n```bash\nmix exenv.decrypt /config/master.key /config/.env.enc\n\n## Add to file\n\nmix exenv.encrypt /config/master.key /config/.env\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fexenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsweeting%2Fexenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fexenv/lists"}