Skip to content

Commit 726b97d

Browse files
committed
Add support for referencing secrets from 1Password
1 parent e730d23 commit 726b97d

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

.changeset/open-coins-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/cli': minor
3+
---
4+
5+
Add support for referencing secrets from 1Password using ${{ op://... }}.

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@
566566
"gitbook": "./cli.js",
567567
},
568568
"dependencies": {
569+
"@1password/op-js": "^0.1.13",
569570
"@gitbook/api": "*",
570571
"check-node-version": "^4.2.1",
571572
"chokidar": "^4.0.1",
@@ -622,6 +623,8 @@
622623
"@gitbook/openapi-parser": "^2.1.0",
623624
},
624625
"packages": {
626+
"@1password/op-js": ["@1password/op-js@0.1.13", "", { "dependencies": { "lookpath": "^1.2.2", "semver": "^7.6.2" } }, "sha512-ZZBLxVqywFdvIbLv2xWw2N1ImSi183rRKf90vV19KRMReNyLwuD0dv6IrKrIdrJU33IuV3Gz85Z4K2a1PJTBDg=="],
627+
625628
"@ampproject/remapping": ["@ampproject/remapping@2.3.0", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="],
626629

627630
"@apidevtools/json-schema-ref-parser": ["@apidevtools/json-schema-ref-parser@11.7.2", "", { "dependencies": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.15", "js-yaml": "^4.1.0" } }, "sha512-4gY54eEGEstClvEkGnwVkTkrx0sqwemEFG5OSRRn3tD91XH0+Q8XIkYIfo7IwEWPpJZwILb9GUXeShtplRc/eA=="],
@@ -1792,6 +1795,8 @@
17921795

17931796
"log-update": ["log-update@4.0.0", "", { "dependencies": { "ansi-escapes": "^4.3.0", "cli-cursor": "^3.1.0", "slice-ansi": "^4.0.0", "wrap-ansi": "^6.2.0" } }, "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg=="],
17941797

1798+
"lookpath": ["lookpath@1.2.3", "", { "bin": { "lookpath": "bin/lookpath.js" } }, "sha512-kthRVhf4kH4+HW3anM4UBHxsw/XFESf13euCEldhXr6GpBdmBoa7rDd7WO5G0Mhd4G5XtKTcEy8OR0iRZXpS3Q=="],
1799+
17951800
"loose-envify": ["loose-envify@1.4.0", "", { "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" }, "bin": { "loose-envify": "cli.js" } }, "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q=="],
17961801

17971802
"lower-case": ["lower-case@2.0.2", "", { "dependencies": { "tslib": "^2.0.3" } }, "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg=="],

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"prompts": "^2.4.2",
1616
"zod": "^3.25.42",
1717
"chokidar": "^4.0.1",
18-
"miniflare": "^3.20240925.0"
18+
"miniflare": "^3.20240925.0",
19+
"@1password/op-js": "^0.1.13"
1920
},
2021
"devDependencies": {
2122
"@gitbook/tsconfig": "*",

packages/cli/src/manifest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { z } from 'zod';
22
import * as fs from 'fs';
33
import * as yaml from 'js-yaml';
44
import * as path from 'path';
5+
import * as op from "@1password/op-js";
56

67
import * as api from '@gitbook/api';
78

@@ -215,7 +216,9 @@ async function validateIntegrationManifest(data: object): Promise<IntegrationMan
215216
function interpolateSecrets(secrets: { [key: string]: string }): { [key: string]: string } {
216217
return Object.keys(secrets).reduce(
217218
(acc, key) => {
218-
acc[key] = secrets[key].replace(/\${{\s*env.([\S]+)\s*}}/g, (_, envVar) => {
219+
acc[key] = secrets[key]
220+
// Handle environment variables, defined as `${{ env.VAR }}`
221+
.replace(/\${{\s*env.([\S]+)\s*}}/g, (_, envVar) => {
219222
const secretEnvVar = process.env[envVar];
220223
if (!secretEnvVar) {
221224
throw new Error(
@@ -224,6 +227,12 @@ function interpolateSecrets(secrets: { [key: string]: string }): { [key: string]
224227
}
225228

226229
return secretEnvVar;
230+
})
231+
232+
// Handle 1Password secrets, defined as `${{ op://<ref> }}`
233+
.replace(/\${{\s*op:\/\/([\S]+)\s*}}/g, (_, ref) => {
234+
const secret = op.read.parse(ref);
235+
return secret;
227236
});
228237
return acc;
229238
},

0 commit comments

Comments
 (0)