1.0.0 ā¢ Published 11 months ago
1p-env v1.0.0
1Password .env Generator
Quickly and easily generate your .env file from credentials stored in 1Password.
About
This script is designed to be used with the 1Password CLI. The generator will ask you a few questions about the item you want to use, and then generate formatted .env key/value pairs for you.
Requirements
To use this package, the 1Password CLI must be installed on your device and logged in.
Running the script
To run the script simply enter npx 1p-env
in your terminal.
Example CLI output:
? What is the item's name? env_variables
? What vault is this item in? Dev
? What section is this item in? demo-app
? How would you like the output? 1Password reference values
ā Entries found! Copy the following value(s) into your env file:
DB_URL="op://Dev/env_variables/demo-app/DB_URL"
DB_USER="op://Dev/env_variables/demo-app/DB_USER"
Documentation
In order for the script to run correctly, it expects that an item is created in 1Password with the following:
- Sections are used to group each of your app's credentials.
- Password fields are used to store credentials, with the label of each field named after the environment variable you want to create.
Example Setup
CLI Guide
When running the CLI, you will be asked the following questions:
- "What is the item's name?" - This is the name of the item in 1Password that contains your credentials.
- "What vault is the item in?" - This is the vault that the item is stored in.
- "What section is this item in?" - This is the name of the section in the item that contains the credentials.
- "How would you like the output?" - This is the format of the output. Currently, there are two options:
- Actual values: This will output the actual values of the credentials. (e.g.,
DB_USER=admin
) - 1Password reference values: This will output the 1Password reference values of the credentials. (e.g.,
DB_USER="op://<vault>/<item_name>/<section>/DB_USER"
). To run your app when using this format in your.env
, prefix your app's run command withop run --no-masking --env-file=".env" --
. For example, for a Next.js Application you would runop run --no-masking --env-file=".env" -- npm run dev
. Make sure to replace.env
with the name of your .env file. See more on the official 1Password developer docs here.
- Actual values: This will output the actual values of the credentials. (e.g.,
Notes
This is an open-source tool and is not affiliated with 1Password.
1.0.0
11 months ago