Skip to content

Commit

Permalink
Ignore wrangler console info under proxy env when run secret generate…
Browse files Browse the repository at this point in the history
… script (#185)
  • Loading branch information
byn9826 authored Oct 25, 2024
1 parent 13c1b9f commit 70de877
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions server/src/scripts/generate-secret.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function arrayBufferToBase64 (buffer) {
).toString('base64')
}

function getWranglerResponse (cmd) {
const response = execSync(cmd).toString()
return response.replace(
"Proxy environment variables detected. We'll use your proxy for fetch requests.",
'',
)
}

const PRIVATE_KEY_FILE = 'jwt_private_key.pem'
const PUBLIC_KEY_FILE = 'jwt_public_key.pem'
const NODE_PRIVATE_KEY_FILE = 'node_jwt_private_key.pem'
Expand Down Expand Up @@ -101,16 +109,16 @@ async function generateRSAKeyPair () {
} else {
const condition = isProd ? '' : '--local'

const [hasSessionSecret] = JSON.parse(execSync(`wrangler kv key list --prefix=sessionSecret --binding=KV ${condition}`).toString())
const [hasSessionSecret] = JSON.parse(getWranglerResponse(`wrangler kv key list --prefix=sessionSecret --binding=KV ${condition}`))
if (!hasSessionSecret) {
execSync(`wrangler kv key put sessionSecret ${sessionSecret} --binding=KV ${condition}`)
}

const [hasPublicKey] = JSON.parse(execSync(`wrangler kv key list --prefix=jwtPublicSecret --binding=KV ${condition}`).toString())
const [hasPrivateKey] = JSON.parse(execSync(`wrangler kv key list --prefix=jwtPrivateSecret --binding=KV ${condition}`).toString())
const [hasPublicKey] = JSON.parse(getWranglerResponse(`wrangler kv key list --prefix=jwtPublicSecret --binding=KV ${condition}`))
const [hasPrivateKey] = JSON.parse(getWranglerResponse(`wrangler kv key list --prefix=jwtPrivateSecret --binding=KV ${condition}`))
if (hasPublicKey && hasPrivateKey) {
const currentPublicKey = execSync(`wrangler kv key get jwtPublicSecret --binding=KV ${condition}`).toString()
const currentPrivateKey = execSync(`wrangler kv key get jwtPrivateSecret --binding=KV ${condition}`).toString()
const currentPublicKey = getWranglerResponse(`wrangler kv key get jwtPublicSecret --binding=KV ${condition}`)
const currentPrivateKey = getWranglerResponse(`wrangler kv key get jwtPrivateSecret --binding=KV ${condition}`)

fs.writeFileSync(
PUBLIC_KEY_FILE,
Expand Down

0 comments on commit 70de877

Please sign in to comment.