{"id":15064623,"url":"https://github.com/phstc/param_store","last_synced_at":"2025-04-10T12:41:11.999Z","repository":{"id":33869535,"uuid":"163108012","full_name":"phstc/param_store","owner":"phstc","description":"Easy switch in between ENV, AWS Parameter Store, AWS Secrets Manager and EJSON","archived":false,"fork":false,"pushed_at":"2023-12-27T03:10:00.000Z","size":61,"stargazers_count":12,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:21:32.952Z","etag":null,"topics":["aws-ssm","environment-variables","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/phstc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-25T19:53:11.000Z","updated_at":"2024-05-11T11:03:47.000Z","dependencies_parsed_at":"2023-12-29T23:36:09.419Z","dependency_job_id":"b32468de-dd43-43b4-9094-2ae52d671ffe","html_url":"https://github.com/phstc/param_store","commit_stats":{"total_commits":59,"total_committers":1,"mean_commits":59.0,"dds":0.0,"last_synced_commit":"0c5cca31faa8e0e5ba95813b852aac522d286e53"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fparam_store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fparam_store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fparam_store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fparam_store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phstc","download_url":"https://codeload.github.com/phstc/param_store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217156,"owners_count":21066634,"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":["aws-ssm","environment-variables","ruby","ruby-on-rails"],"created_at":"2024-09-25T00:22:44.605Z","updated_at":"2025-04-10T12:41:11.972Z","avatar_url":"https://github.com/phstc.png","language":"Ruby","readme":"[![CircleCI](https://circleci.com/gh/phstc/param_store.svg?style=svg)](https://circleci.com/gh/phstc/param_store)\n\n# ParamStore\n\nThis gem goal is to \u003cstrike\u003eDRY some code I have been copying around for a while\u003c/strike\u003e make easy switching in between ENV, [AWS Parameter Store (SSM)](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html), [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) and [EJSON](https://github.com/Shopify/ejson) for retrieving parameters.\n\nThis gem is not a replacement for [dotenv](https://github.com/bkeepers/dotenv). I still use and recommend it in development, in case it is \"safe\" to save your keys in `.env` files.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'param_store'\n```\n\n## Usage\n\n### Configuring adapters\n\nAvailable adapters: `:env`, `:aws_ssm`, `:aws_secrets_manager` and `:ejson_wrapper`.\n\n```ruby\nParamStore.adapter = adapter\n```\n\n### Retrieving parameters\n\n```ruby\n# ParamStore.fetch is similar to Hash#fetch,\n# If the key is not found and there's no default given, it will raise a `KeyError`\nParamStore.fetch('name')\nParamStore.fetch('name', 'default value')\nParamStore.fetch('name') { 'default value' }\n```\n\n### Copying from any adapter to ENV\n\n```ruby\nParamStore.copy_to_env('name1', 'name2', 'name3')\n\nENV['name1'] # =\u003e value for name1\nENV['name2'] # =\u003e value for name2\nENV['name3'] # =\u003e value for name3\n```\n\n## Adapters\n\n### ENV\n\n```ruby\nParamStore.adapter :env\n```\n\n### AWS Parameter Store (SSM)\n\nAdd to your Gemfile:\n\n```ruby\ngem 'aws-sdk-ssm', '~\u003e 1'\n```\n\nConfigure the adapter:\n\n```ruby\nParamStore.adapter :aws_ssm, default_path: '/Prod/App/'\n```\n\n#### Retrieving parameters\n\n```ruby\nParamStore.fetch('name')\n# =\u003e get parameter name, if default_path /Prod/App/ get parameter /Prod/App/name\nParamStore.fetch('name', path: '/Prod/App/')\n# =\u003e get parameter /Prod/App/name\n```\n\n#### Copying from SSM adapter to ENV\n\n```ruby\nParamStore.copy_to_env('name1', 'name2', 'name3', path: '/Environment/Type of computer/Application/')\n# path overrides default_path\n\nENV['name1'] # =\u003e value for name1\nENV['name2'] # =\u003e value for name2\nENV['name3'] # =\u003e value for name3\n```\n\n#### SSM client\n\nBy default ParamStore will initiate `Aws::SSM::Client.new` without supplying any argument. If you want to control the initiation of the SSM client, you can define it by setting `ssm_client`.\n\n\n```ruby\nParamStore.ssm_client = Aws::SSM::Client.new(\n  region: region_name,\n  credentials: credentials,\n  # ...\n)\n```\n\n#### CLI\n\nA few useful [aws ssm](https://docs.aws.amazon.com/cli/latest/reference/ssm/index.html) commands:\n\n```sh\naws ssm get-parameters-by-path --path /Prod/ERP/SAP --with-decryption\naws ssm put-parameter --name /Prod/ERP/SAP --value ... --type SecureString\n```\n\n### Secrets Manager\n\nAdd to your Gemfile:\n\n```ruby\ngem 'aws-sdk-secretsmanager', '~\u003e 1'\n```\n\nConfigure the adapter:\n\n```ruby\nParamStore.adapter :aws_secrets_manager\n# ParaStore.fetch('secret_id')\n# =\u003e {\\n  \\\"password\\\":\\\"pwd\\\"\\n}\\n\n\nParamStore.adapter :aws_secrets_manager, default_secret_id: 'secret_id'\n# ParaStore.fetch('password')\n# =\u003e pwd\n```\n\n#### Retrieving parameters\n\n```ruby\nParamStore.fetch('secret_id')\nParamStore.fetch('password', secret_id: 'secret_id')\n```\n\n#### Copying from Secrets Manager adapter to ENV\n\n```ruby\nParamStore.copy_to_env('key1', 'key2', 'key3', secret_id: 'secret_id')\n# secret_id overrides default_secret_id\n\nENV['key1'] # =\u003e value for key1\nENV['key2'] # =\u003e value for key2\nENV['key3'] # =\u003e value for key3\n```\n\n### EJSON\n\nAdd to your Gemfile:\n\n```ruby\ngem 'ejson_wrapper', '~\u003e 0.3.1'\n```\n\nConfigure the adapter:\n\n```ruby\nParamStore.adapter(\n  :ejson_wrapper,\n  file_path: '...',\n  key_dir: '...',\n  private_key: '...',\n  use_kms: '...',\n  region: '...'\n)\n# see https://github.com/envato/ejson_wrapper#usage\n```\n\n#### Rails\n\nIf you are using ParamStore in prod and dotenv in dev:\n\n```ruby\n# config/application.rb\n# Bundler.require(*Rails.groups)\nif Rails.env.production?\n  ParamStore.adapter(:aws_ssm)\n  ParamStore.copy_to_env('DATABASE_URL', require_keys: true, path: '/Prod/MyApp/')\nelse\n  Dotenv::Railtie.load\nend\n```\n\n### Fail-fast\n\nYou can configure the required parameters for an app and fail at startup.\n\n```ruby\n# config/application.rb\n# Bundler.require(*Rails.groups)\nParamStore.require_keys!('key1', 'key2', 'key3')\n# this will raise an error if any key is missing\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/phstc/param_store. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ParamStore project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/phstc/param_store/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fparam_store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphstc%2Fparam_store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fparam_store/lists"}