Skip to content

Commit e2c874b

Browse files
authored
chore(repo): Add 1Password CLI script (#6168)
1 parent 9487346 commit e2c874b

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

.changeset/odd-doors-sneeze.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,9 @@ Before you begin writing tests, you should already have:
2424

2525
You'll only need to follow these instructions once when you setup the integration test suite.
2626

27-
1. Navigate to the `integration` folder:
28-
```shell
29-
cd integration
30-
```
31-
1. Make local duplicates of the sample files. They'll be automatically ignored by git:
32-
```shell
33-
cp .env.local.sample .env.local
34-
cp .keys.json.sample .keys.json
35-
```
36-
1. Open Clerk's 1Password and search for **JS SDKs integration tests**. Inside the secure note you'll find the secret keys that should go into `.env.local` and `.keys.json`. Copy them over.
27+
1. Make sure you have the [1Password CLI installed](https://developer.1password.com/docs/cli/get-started/) and have access to Clerk's "Shared" vault. You will also need to [enable the 1Password desktop app integration](https://developer.1password.com/docs/cli/get-started/#step-2-turn-on-the-1password-desktop-app-integration).
28+
29+
1. Run `pnpm integration:secrets`.
3730

3831
1. Generate the required session keys by running the following command in the `./certs` directory: `mkcert -cert-file sessions.pem -key-file sessions-key.pem "example.com" "*.example.com"`.
3932

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"format": "prettier --write .",
1616
"format:check": "prettier --cache --check .",
1717
"preinstall": "npx only-allow pnpm",
18+
"integration:secrets": "node ./scripts/1password-keys.mjs",
1819
"lint": "node ./scripts/lint.mjs",
1920
"lint:attw": "FORCE_COLOR=1 turbo lint:attw",
2021
"lint:fix": "FORCE_COLOR=1 turbo lint -- --fix",

scripts/1password-keys.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
import { writeFile } from 'node:fs/promises';
4+
import { join } from 'node:path';
5+
import { $ } from 'zx';
6+
7+
const is1PasswordInstalled = await $`op --version`.then(res => res.exitCode === 0).catch(() => false);
8+
9+
if (!is1PasswordInstalled) {
10+
console.error('1Password CLI is not installed. Install it with `brew install 1password-cli`.');
11+
process.exit(1);
12+
}
13+
14+
const envItem = await $`op read 'op://Shared/JS SDKs integration tests/add more/.env.local'`
15+
.then(res => {
16+
if (res.exitCode === 0) {
17+
return res.stdout;
18+
}
19+
20+
return null;
21+
})
22+
.catch(err => {
23+
return null;
24+
});
25+
26+
const keysItem = await $`op read 'op://Shared/JS SDKs integration tests/add more/.keys.json'`
27+
.then(res => {
28+
if (res.exitCode === 0) {
29+
return res.stdout;
30+
}
31+
32+
return null;
33+
})
34+
.catch(err => {
35+
return null;
36+
});
37+
38+
if (!envItem || !keysItem) {
39+
console.error(
40+
'Failed to read from 1Password. Have you enabled the 1Password CLI in your 1Password settings? See https://developer.1password.com/docs/cli/get-started/#step-2-turn-on-the-1password-desktop-app-integration for more information.',
41+
);
42+
process.exit(1);
43+
}
44+
45+
await writeFile(join(process.cwd(), 'integration', '.env.local'), envItem);
46+
await writeFile(join(process.cwd(), 'integration', '.keys.json'), keysItem);
47+
48+
console.log('Keys and env written to .keys.json and .env.local');

0 commit comments

Comments
 (0)