Skip to content

Commit

Permalink
updated env artifact generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdmoore committed Dec 18, 2023
1 parent 868e061 commit 7da4a2a
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 499 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,46 @@ jobs:

- name: Run tests
run: deno task test
env:
AWS_DYN_TABLE_MEGA: ${{ vars.AWS_DYN_TABLE_MEGA }}
AWS_POLLY_BUCKET: ${{ vars.AWS_POLLY_BUCKET }}
AWS_POLLY_PREFIX: ${{ vars.AWS_POLLY_PREFIX }}
AWS_REGION: ${{ vars.AWS_REGION }}
JWT_KEY_EXT: ${{ vars.JWT_KEY_EXT }}
JWT_KEY_OPS_PRIVATE: ${{ vars.JWT_KEY_OPS_PRIVATE }}
JWT_KEY_OPS_PUBLIC: ${{ vars.JWT_KEY_OPS_PUBLIC }}
RSA_KEY_E: ${{ vars.RSA_KEY_E }} # AQAB
env:
AES_GCM_K: ${{ secrets.AES_GCM_K }}
AIRTABLE_BASE: ${{ secrets.AIRTABLE_BASE }}
AIRTABLE_TABLE: ${{ secrets.AIRTABLE_TABLE }}
AIRTABLE_TOKEN: ${{ secrets.AIRTABLE_TOKEN }}
AWS_DYN_TABLE_MEGA: ${{ vars.AWS_DYN_TABLE_MEGA }}
AWS_DYN_TABLE_SESSION: ${{ secrets.AWS_DYN_TABLE_SESSION }}
AWS_KEY: ${{ secrets.AWS_KEY }}
AWS_POLLY_BUCKET: ${{ vars.AWS_POLLY_BUCKET }}
AWS_POLLY_PREFIX: ${{ vars.AWS_POLLY_PREFIX }}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_SECRET: ${{ secrets.AWS_SECRET }}
CLOUDFLARE_ACCOUNT: ${{ secrets.CLOUDFLARE_ACCOUNT }}
CLOUDFLARE_FEEDCITY_ACCESS_KEY: ${{ secrets.CLOUDFLARE_FEEDCITY_ACCESS_KEY }}
CLOUDFLARE_FEEDCITY_ACCESS_SECRET: ${{ secrets.CLOUDFLARE_FEEDCITY_ACCESS_SECRET }}
CLOUDFLARE_FEEDCITY_TOKEN: ${{ secrets.CLOUDFLARE_FEEDCITY_TOKEN }}
CLOUDFLARE_ZONEID: ${{ secrets.CLOUDFLARE_ZONEID }}
JWT_KEY_ALG: ${{ secrets.JWT_KEY_ALG }}
JWT_KEY_CRV: ${{ secrets.JWT_KEY_CRV }}
JWT_KEY_D_PRIVATE: ${{ secrets.JWT_KEY_D_PRIVATE }}
JWT_KEY_EXT: ${{ vars.JWT_KEY_EXT }}
JWT_KEY_ID: ${{ secrets.JWT_KEY_ID }}
JWT_KEY_KTY: ${{ secrets.JWT_KEY_KTY }}
JWT_KEY_OPS_PRIVATE: ${{ vars.JWT_KEY_OPS_PRIVATE }}
JWT_KEY_OPS_PUBLIC: ${{ vars.JWT_KEY_OPS_PUBLIC }}
JWT_KEY_X: ${{ secrets.JWT_KEY_X }}
JWT_KEY_Y: ${{ secrets.JWT_KEY_Y }}
OPENAI_ORGID: ${{ secrets.OPENAI_ORGID }}
OPENAI_PROD_KEY: ${{ secrets.OPENAI_PROD_KEY }}
OPENAI_TEST_KEY: ${{ secrets.OPENAI_TEST_KEY }}
RSA_KEY_E: ${{ secrets.RSA_KEY_E }}
RSA_KEY_N: ${{ secrets.RSA_KEY_N }}
RSA_KEY_PRIVATE_D: ${{ secrets.RSA_KEY_PRIVATE_D }}
RSA_KEY_PRIVATE_DP: ${{ secrets.RSA_KEY_PRIVATE_DP }}
RSA_KEY_PRIVATE_DQ: ${{ secrets.RSA_KEY_PRIVATE_DQ }}
RSA_KEY_PRIVATE_P: ${{ secrets.RSA_KEY_PRIVATE_P }}
RSA_KEY_PRIVATE_Q: ${{ secrets.RSA_KEY_PRIVATE_Q }}
RSA_KEY_PRIVATE_QI: ${{ secrets.RSA_KEY_PRIVATE_QI }}
RSA_KEY_PRIVATE_QI: ${{ secrets.RSA_KEY_PRIVATE_QI }}
STRIPE_ACCT_ID: ${{ secrets.STRIPE_ACCT_ID }}
STRIPE_PUBLISHED_TOKEN: ${{ secrets.STRIPE_PUBLISHED_TOKEN }}
STRIPE_SECRET_TOKEN: ${{ secrets.STRIPE_SECRET_TOKEN }}
STRIPE_TEST_PUBLISHED_TOKEN: ${{ secrets.STRIPE_TEST_PUBLISHED_TOKEN }}
STRIPE_TEST_SECRET_TOKEN: ${{ secrets.STRIPE_TEST_SECRET_TOKEN }}
759 changes: 330 additions & 429 deletions deno.lock

Large diffs are not rendered by default.

127 changes: 86 additions & 41 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,41 +1,86 @@
# rename as .env
AES_GCM_K=EXAMPLE_VALUE__1
AIRTABLE_BASE=EXAMPLE_VALUE__2
AIRTABLE_TABLE=EXAMPLE_VALUE__3
AIRTABLE_TOKEN=EXAMPLE_VALUE__4
AWS_DYN_TABLE_MEGA=EXAMPLE_VALUE__5
AWS_DYN_TABLE_SESSION=EXAMPLE_VALUE__6
AWS_KEY=EXAMPLE_VALUE__7
AWS_POLLY_BUCKET=EXAMPLE_VALUE__8
AWS_POLLY_PREFIX=EXAMPLE_VALUE__9
AWS_REGION=EXAMPLE_VALUE__10
AWS_SECRET=EXAMPLE_VALUE__11
CLOUDFLARE_ACCOUNT=EXAMPLE_VALUE__12
CLOUDFLARE_FEEDCITY_ACCESS_KEY=EXAMPLE_VALUE__13
CLOUDFLARE_FEEDCITY_ACCESS_SECRET=EXAMPLE_VALUE__14
CLOUDFLARE_FEEDCITY_TOKEN=EXAMPLE_VALUE__15
JWT_KEY_ALG=EXAMPLE_VALUE__16
JWT_KEY_CRV=EXAMPLE_VALUE__17
JWT_KEY_D_PRIVATE=EXAMPLE_VALUE__18
JWT_KEY_EXT=EXAMPLE_VALUE__19
JWT_KEY_ID=EXAMPLE_VALUE__20
JWT_KEY_KTY=EXAMPLE_VALUE__21
JWT_KEY_OPS_PRIVATE=EXAMPLE_VALUE__22
JWT_KEY_OPS_PUBLIC=EXAMPLE_VALUE__23
JWT_KEY_X=EXAMPLE_VALUE__24
JWT_KEY_Y=EXAMPLE_VALUE__25
OPENAI_ORGID=EXAMPLE_VALUE__26
OPENAI_PROD_KEY=EXAMPLE_VALUE__27
OPENAI_TEST_KEY=EXAMPLE_VALUE__28
RSA_KEY_E=EXAMPLE_VALUE__29
RSA_KEY_N=EXAMPLE_VALUE__30
RSA_KEY_PRIVATE_D=EXAMPLE_VALUE__31
RSA_KEY_PRIVATE_DP=EXAMPLE_VALUE__32
RSA_KEY_PRIVATE_DQ=EXAMPLE_VALUE__33
RSA_KEY_PRIVATE_P=EXAMPLE_VALUE__34
RSA_KEY_PRIVATE_Q=EXAMPLE_VALUE__35
RSA_KEY_PRIVATE_QI=EXAMPLE_VALUE__36
STRIPE_PUBLISHED_TOKEN=EXAMPLE_VALUE__37
STRIPE_SECRET_TOKEN=EXAMPLE_VALUE__38
STRIPE_TEST_PUBLISHED_TOKEN=EXAMPLE_VALUE__39
STRIPE_TEST_SECRET_TOKEN=EXAMPLE_VALUE__40
# duplicate as new file = /.env
#
#
# AIRTABLE
# Almost Helpful links
# https://airtable.com/BASE/TABLE/viwpnTY4IlG3WaCow
# https://airtable.com/BASE/api/docs#curl/introductio
# https://airtable.com/create/tokens
AIRTABLE_BASE="EXAMPLE_VALUE__"
AIRTABLE_TABLE="EXAMPLE_VALUE__"
AIRTABLE_TOKEN="EXAMPLE_VALUE__"


# AWS
# Almost Helpful Commands
# $> aws dynamodb list-tables
# $> aws s3 ls
AWS_DYN_TABLE_MEGA="EXAMPLE_VALUE__"
AWS_DYN_TABLE_SESSION="EXAMPLE_VALUE__"
AWS_POLLY_BUCKET="EXAMPLE_VALUE__"
AWS_POLLY_PREFIX="EXAMPLE_VALUE__"
AWS_REGION="EXAMPLE_VALUE__"
AWS_KEY="EXAMPLE_VALUE__"
AWS_SECRET="EXAMPLE_VALUE__"


## CLOUDFLARE
# Helpful Links for My Account
# https://dash.cloudflare.com/ACCOUNT/DOMAINNAME
CLOUDFLARE_ACCOUNT="EXAMPLE_VALUE__"
CLOUDFLARE_ZONEID="EXAMPLE_VALUE__"
CLOUDFLARE_FEEDCITY_TOKEN="EXAMPLE_VALUE__" # TokenName: FeedsCityToken#2023.12.14
CLOUDFLARE_FEEDCITY_ACCESS_KEY="EXAMPLE_VALUE__"
CLOUDFLARE_FEEDCITY_ACCESS_SECRET="EXAMPLE_VALUE__"

## OPENAI
# Helpful Links for My Account
# https://platform.openai.com/account/organization
# https://platform.openai.com/api-keys
OPENAI_ORGID="EXAMPLE_VALUE__"
OPENAI_PROD_KEY="EXAMPLE_VALUE__" # KeyName: ProdKey#2023.12.14
OPENAI_TEST_KEY="EXAMPLE_VALUE__" # KeyName: TestKey#2023.12.14


# STRIPE
# Helpful Link
# https://dashboard.stripe.com/test/apikeys
STRIPE_PUBLISHED_TOKEN="EXAMPLE_VALUE__"
STRIPE_SECRET_TOKEN="EXAMPLE_VALUE__"
STRIPE_TEST_PUBLISHED_TOKEN="EXAMPLE_VALUE__"
STRIPE_TEST_SECRET_TOKEN="EXAMPLE_VALUE__"
STRIPE_ACCT_ID="EXAMPLE_VALUE__"

# PRIVATE KEY VALUES GENERATED BY UTILS/KEYS
#
## AES
# $> deno run utils/keys/gen-aes-gcm.ts
AES_GCM_K="EXAMPLE_VALUE__"
#
#
## JWT
# $> deno run utils/keys/gen-ecdsa.ts
JWT_KEY_ALG="EXAMPLE_VALUE__"
JWT_KEY_CRV="EXAMPLE_VALUE__"
JWT_KEY_D_PRIVATE="EXAMPLE_VALUE__"
JWT_KEY_EXT="EXAMPLE_VALUE__"
JWT_KEY_ID="EXAMPLE_VALUE__"
JWT_KEY_KTY="EXAMPLE_VALUE__"
JWT_KEY_OPS_PRIVATE="EXAMPLE_VALUE__"
JWT_KEY_OPS_PUBLIC="EXAMPLE_VALUE__"
JWT_KEY_X="EXAMPLE_VALUE__"
JWT_KEY_Y="EXAMPLE_VALUE__"
#
#
#
## RSA
#
# $> deno run utils/keys/gen-rsa.ts
RSA_KEY_E="EXAMPLE_VALUE__"
RSA_KEY_N="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_D="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_DP="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_DQ="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_P="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_Q="EXAMPLE_VALUE__"
RSA_KEY_PRIVATE_QI="EXAMPLE_VALUE__"
18 changes: 10 additions & 8 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ import * as $$2 from "./islands/compositionForm.tsx";
import * as $$3 from "./islands/heroicon-menu.tsx";
import * as $$4 from "./islands/hooks/useFocusedButtons.tsx";
import * as $$5 from "./islands/navbar.tsx";
import * as $$6 from "./islands/public-about-hero.tsx";
import * as $$7 from "./islands/public-navbar.tsx";
import * as $$8 from "./islands/public-signup.tsx";
import * as $$9 from "./islands/textArea-previewable.tsx";
import * as $$6 from "./islands/preview.tsx";
import * as $$7 from "./islands/public-about-hero.tsx";
import * as $$8 from "./islands/public-navbar.tsx";
import * as $$9 from "./islands/public-signup.tsx";
import * as $$10 from "./islands/textArea-previewable.tsx";

const manifest = {
routes: {
Expand Down Expand Up @@ -115,10 +116,11 @@ const manifest = {
"./islands/heroicon-menu.tsx": $$3,
"./islands/hooks/useFocusedButtons.tsx": $$4,
"./islands/navbar.tsx": $$5,
"./islands/public-about-hero.tsx": $$6,
"./islands/public-navbar.tsx": $$7,
"./islands/public-signup.tsx": $$8,
"./islands/textArea-previewable.tsx": $$9,
"./islands/preview.tsx": $$6,
"./islands/public-about-hero.tsx": $$7,
"./islands/public-navbar.tsx": $$8,
"./islands/public-signup.tsx": $$9,
"./islands/textArea-previewable.tsx": $$10,
},
baseUrl: import.meta.url,
};
Expand Down
2 changes: 1 addition & 1 deletion routes/api/[tokType]-[token]/[outputFmt]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Status } from "$std/http/http_status.ts";
import NavPanels from "$components/navigation/panels.tsx";

export const config: RouteConfig = {
routeOverride: "/api/:tokType(u|t)-:token/:outputFmt(json|html|atom|rss)",
routeOverride: "/api/:tokType(u|t)-:token/:outputFmt(json|html|atom|rss|ast)",
};

const H1 = (
Expand Down
26 changes: 18 additions & 8 deletions utils/env/genExample.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#!/usr/bin/env deno run ./utils/env/genExample.ts -A
import { parse } from "$std/dotenv/mod.ts";
// import { parse } from "$std/dotenv/mod.ts";
import * as path from "$std/path/mod.ts";

const u = new URL(import.meta.url);
const filePath = path.resolve(u.pathname, "../../../.env");
// console.log({filePath});

const realEnvText = await Deno.readTextFile(filePath);
const ENVS = parse(realEnvText);
// const ENVS = parse(realEnvText);

console.log("# rename as .env");
Object.entries(ENVS)
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
.forEach(([k, _], i) => {
console.log(`${k}=EXAMPLE_VALUE__${i + 1}`);
});
// console.log("# rename as .env");
// Object.entries(ENVS)
// .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
// .forEach(([k, _], i) => {
// console.log(`${k}=EXAMPLE_VALUE__${i + 1}`);
// });

// console.log("\n\n\n");

console.log(realEnvText
.replace(/=[\w._+-]+/g, `="EXAMPLE_VALUE__"`)
.replace(/="[\w._+-]+"/g, `="EXAMPLE_VALUE__"`)
.replace(/='[\w._+-]+'/g, `="EXAMPLE_VALUE__"`)
);

console.log('Always double-check the data to not expose secrets before checking in an example')
34 changes: 34 additions & 0 deletions utils/env/genYamlData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env deno run ./utils/env/genExample.ts -A
import { parse } from "$std/dotenv/mod.ts";
import * as path from "$std/path/mod.ts";

const u = new URL(import.meta.url);
const filePath = path.resolve(u.pathname, "../../../.env");
// console.log({filePath});

const realEnvText = await Deno.readTextFile(filePath);
const ENVS = parse(realEnvText);

console.log('Copy paste this to the env: section of deno.yml \n\n\n')

const vars = {
AWS_DYN_TABLE_MEGA: true,
AWS_POLLY_BUCKET: true,
AWS_POLLY_PREFIX: true,
AWS_REGION: true,
JWT_KEY_EXT: true,
JWT_KEY_OPS_PRIVATE: true,
JWT_KEY_OPS_PUBLIC: true,
}

Object.entries(ENVS)
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
.forEach(([key, _]) => {
if(key in vars) {
console.log(`${key}: \${{ vars.${key} }}`)
} else {
console.log(`${key}: \${{ secrets.${key} }}`)
}
});

console.log('\n\n\n')
6 changes: 6 additions & 0 deletions utils/keys/gen-aes-gcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ const key = await window.crypto.subtle.generateKey(
export const aesGcmJWK = await crypto.subtle.exportKey("jwk", key);

console.log("const aesGcmJKW = ", JSON.stringify(aesGcmJWK, null, 2));

console.log('\n\nCopy paste this section into the .env file\n\n\n')
console.log(`## AES
# $> deno run utils/keys/gen-aes-gcm.ts
AES_GCM_K=${aesGcmJWK.k}
`)
24 changes: 22 additions & 2 deletions utils/keys/gen-ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const keypair = await crypto.subtle.generateKey(

const kid = Date.now();


const privJwkKey = await crypto.subtle.exportKey("jwk", keypair.privateKey)
const pubJwkKey = await crypto.subtle.exportKey("jwk", keypair.publicKey)

console.log(
"export const privateECDSA = ",
JSON.stringify(
{
kid,
...await crypto.subtle.exportKey("jwk", keypair.privateKey),
...privJwkKey
},
null,
2,
Expand All @@ -25,9 +29,25 @@ console.log(
JSON.stringify(
{
kid,
...await crypto.subtle.exportKey("jwk", keypair.publicKey),
...pubJwkKey
},
null,
2,
),
);


console.log('\n\nCopy paste this section into the .env file\n\n\n')
console.log(`## JWT
# $> deno run utils/keys/gen-ecdsa.ts
JWT_KEY_ALG=${privJwkKey.alg}
JWT_KEY_CRV=${privJwkKey.crv}
JWT_KEY_D_PRIVATE=${privJwkKey.d}
JWT_KEY_EXT=${privJwkKey.ext}
JWT_KEY_ID=${kid}
JWT_KEY_KTY=${privJwkKey.kty}
JWT_KEY_OPS_PRIVATE=${privJwkKey.key_ops}
JWT_KEY_OPS_PUBLIC=${pubJwkKey.key_ops}
JWT_KEY_X=${privJwkKey.x}
JWT_KEY_Y=${privJwkKey.y}
`)
14 changes: 14 additions & 0 deletions utils/keys/gen-rsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ export const privateRSA = await crypto.subtle.exportKey(

console.log("const publicRSA = ", JSON.stringify(publicRSA, null, 2));
console.log("const privateRSA = ", JSON.stringify(privateRSA, null, 2));

console.log('\n\nCopy paste this section into the .env file\n\n\n')
console.log(`## RSA
#
# $> deno run utils/keys/gen-rsa.ts
RSA_KEY_E=${privateRSA.e}
RSA_KEY_N="${privateRSA.n}"
RSA_KEY_PRIVATE_D="${privateRSA.d}"
RSA_KEY_PRIVATE_DP="${privateRSA.dp}"
RSA_KEY_PRIVATE_DQ="${privateRSA.dq}"
RSA_KEY_PRIVATE_P="${privateRSA.p}"
RSA_KEY_PRIVATE_Q="${privateRSA.q}"
RSA_KEY_PRIVATE_QI="${privateRSA.qi}"
`)

1 comment on commit 7da4a2a

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 7da4a2a Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

UNCAUGHT_EXCEPTION

Uncaught (in promise) undefined

Please sign in to comment.