Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
access rails 5.2 encrypted credentials from a script outside the rails app
#First of all, require all of rails (maybe it doesn't need to be all, but for now it is)
require 'rails/all'
#then i need to slightly overwrite a rails method:
def encrypted(path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY")
config_path: path,
key_path: key_path,
env_key: env_key,
raise_if_missing_key: nil
# Then, load the credentials into a YAML object:
credentials = YAML.load(encrypted(File.expand_path("config/credentials.yml.enc"), key_path: File.expand_path("config/master.key")).read)
#Finally, read my credentials:
mail.password = credentials['smtp_password']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.