Skip to content

Instantly share code, notes, and snippets.

@osterman
Last active July 7, 2020 19:01
Show Gist options
  • Save osterman/55990419540378da8b47ba5e2cbdbc41 to your computer and use it in GitHub Desktop.
Save osterman/55990419540378da8b47ba5e2cbdbc41 to your computer and use it in GitHub Desktop.
Export 1Password Secrets as Environment Variables
# Download `op` (one password cli) here https://app-updates.agilebits.com/product_history/CLI
# Secret to fetch by name from 1password
SECRET=${SECRET:-${1:-"Example Developer Secrets"}}
# Your 1Password organization
ORG=${ORG:-${2:-cloudposse}}
EMAIL=${EMAIL:-${3:-erik@cloudposse.com}}
# configure 1password (you only need to do this once)
[ -f ~/.op/config ] || op signin $ORG $EMAIL
# export 1password session env
eval $(op signin $ORG)
# export secrets as envs; note we encode the value using @json so it's shell safe
op get item "${SECRET}" | \
jq -r '.details.sections[].fields | select (. != null) | flatten | .[] | "export " + .t + "=" + (.v | @json)'
@osterman
Copy link
Author

osterman commented Jul 7, 2020

Use this script by running something like:

eval $(1password-env.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment