LoginSignup
16
9

More than 1 year has passed since last update.

.envを1Passwordから生成する

Last updated at Posted at 2023-02-02

1passwordに保存したシークレットな情報を利用して、.envに吐き出すまでのメモ

準備

1password CLIをインストール

% brew install --cask 1password/tap/1password-cli

# signinしておく
% op signin

手順

1passwordにシークレットな情報を保存

% SECRET_TITLE="awesome-app-env"
% op item create --category=login --title=$SECRET_TITLE
% op item edit $SECRET_TITLE MY_SECRET_TOKEN="SECRET_XXXXXXXX"
% op item edit $SECRET_TITLE MY_SECRET_API_KEY="SECRET_XXXXXXXX"

アプリを見るとこうなってる
image.png

.env.template生成

% op item get --format json $SECRET_TITLE | \
  jq -r '.fields[] | select(.value) | (.label) + "=\"" + (.reference) + "\""' > \
 .env.template

こんなのが生成される

.env.template
MY_SECRET_TOKEN="op://Private/awesome-app-env/Section_lujpp2wyyprr3gxxxxxxxxx/MY_SECRET_TOKEN"
MY_SECRET_API_KEY="op://Private/awesome-app-env/Section_lujpp2wyyprr3gxxxxxxxxx/MY_SECRET_API_KEY"

.envに書き出し

% op inject -i .env.template -o .env
16
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
9