Last active
July 7, 2020 19:01
-
-
Save osterman/55990419540378da8b47ba5e2cbdbc41 to your computer and use it in GitHub Desktop.
Export 1Password Secrets as Environment Variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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:[email protected]}} | |
# 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)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this script by running something like: