Skip to content

Commit f3d7cf8

Browse files
committed
Add Access 1Password Credential From CLI as a Workflow TIL
1 parent 72089e1 commit f3d7cf8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1413 TILs and counting..._
13+
_1414 TILs and counting..._
1414

1515
---
1616

@@ -1638,6 +1638,7 @@ _1413 TILs and counting..._
16381638
### Workflow
16391639

16401640
- [Add Subtitles To Existing Mux Video Asset](workflow/add-subtitles-to-existing-mux-video-asset.md)
1641+
- [Access 1Password Credential From CLI](workflow/access-1password-credential-from-cli.md)
16411642
- [Change Window Name In iTerm](workflow/change-window-name-in-iterm.md)
16421643
- [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md)
16431644
- [Create A Local Sanity Dataset Backup](workflow/create-a-local-sanity-dataset-backup.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Access 1Password Credential From CLI
2+
3+
With the `op` CLI, I can store things like API keys and secrets in my 1Password
4+
vault and then access them from the command line. This assumes I've already
5+
installed the CLI (`brew install 1password-cli`) and connected it to the
6+
1Password app via the _Developer_ settings.
7+
8+
The `op item get` command takes a credential name and returns all the details
9+
for the entry with that _Title_. Here is how I can access my _Anthropic Claude
10+
API Key_ details.
11+
12+
```bash
13+
$ op item get "Anthropic Claude API Key"
14+
```
15+
16+
With the `--field` flag, I can grab a specific field, such as the `credential`,
17+
from that entry.
18+
19+
```bash
20+
$ op item get "Anthropic Claude API Key" --field credential
21+
sk-ant-api03-abc......xyz
22+
```
23+
24+
A command like this can be embedded in other commands as a way of referencing
25+
secrets without explicitly entering them into your shell history.
26+
27+
```bash
28+
$ curl https://api -H "x-api-key: $(op item get "Anthropic Claude API Key" --field credential)" ...
29+
```

0 commit comments

Comments
 (0)