Skip to content

Commit

Permalink
Merge pull request ubiquity-os#70 from gentlementlegen/development
Browse files Browse the repository at this point in the history
chore: removed unnecessary secrets
  • Loading branch information
gentlementlegen authored Jul 9, 2024
2 parents 6fe8040 + afc9626 commit a790b9b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ jobs:

- uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: "3.57.0"
wranglerVersion: "3.63.1"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
WEBHOOK_PROXY_URL
WEBHOOK_SECRET
APP_ID
PRIVATE_KEY
APP_PRIVATE_KEY
WEBHOOK_SECRET
env:
WEBHOOK_PROXY_URL: ${{ secrets.WEBHOOK_PROXY_URL }}
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/bun-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
NODE_ENV: "test"
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}

jobs:
testing:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ The kernel is designed to:

## Environment Variables

- **`PRIVATE_KEY`**
- **`APP_PRIVATE_KEY`**
Obtain a private key from your GitHub App settings and convert it to the Public-Key Cryptography Standards #8 (PKCS#8) format. Use the following command to perform this conversion and append the result to your `.dev.vars` file:

```sh
echo "PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars
echo "APP_PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_APP_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars
```

**Note:** Replace `YOUR_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command.
**Note:** Replace `YOUR_APP_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command.

- **`WEBHOOK_SECRET`**
Set this value in both your GitHub App settings and here.
Expand Down Expand Up @@ -70,10 +70,10 @@ bun dev
5. **Manage Secrets:**

- Add (env) secrets using `npx wrangler secret put <KEY> --env dev`.
- For the private key, execute the following (replace `YOUR_PRIVATE_KEY.PEM` with the actual PEM file path):
- For the private key, execute the following (replace `YOUR_APP_PRIVATE_KEY.PEM` with the actual PEM file path):

```sh
echo $(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM) | npx wrangler secret put PRIVATE_KEY --env dev
echo $(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_APP_PRIVATE_KEY.PEM) | npx wrangler secret put APP_PRIVATE_KEY --env dev
```

6. **Deploy the Kernel:**
Expand Down
6 changes: 3 additions & 3 deletions src/github/github-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class GitHubEventHandler {
public onError: Webhooks<SimplifiedContext>["onError"];
public pluginChainState: CloudflareKv<PluginChainState>;

private _webhookSecret: string;
private _privateKey: string;
private _appId: number;
private readonly _webhookSecret: string;
private readonly _privateKey: string;
private readonly _appId: number;

constructor(options: Options) {
this._privateKey = options.privateKey;
Expand Down
8 changes: 6 additions & 2 deletions src/github/types/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Type as T, type Static } from "@sinclair/typebox";

export const envSchema = T.Object({ WEBHOOK_SECRET: T.String({ minLength: 1 }), APP_ID: T.String({ minLength: 1 }), PRIVATE_KEY: T.String({ minLength: 1 }) });
export const envSchema = T.Object({
WEBHOOK_SECRET: T.String({ minLength: 1 }),
APP_ID: T.String({ minLength: 1 }),
APP_PRIVATE_KEY: T.String({ minLength: 1 }),
});

export type Env = Static<typeof envSchema> & {
PLUGIN_CHAIN_STATE: KVNamespace;
Expand All @@ -12,7 +16,7 @@ declare global {
interface ProcessEnv {
APP_ID: string;
WEBHOOK_SECRET: string;
PRIVATE_KEY: string;
APP_PRIVATE_KEY: string;
}
}
}
2 changes: 1 addition & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
const eventHandler = new GitHubEventHandler({
webhookSecret: env.WEBHOOK_SECRET,
appId: env.APP_ID,
privateKey: env.PRIVATE_KEY,
privateKey: env.APP_PRIVATE_KEY,
pluginChainState: new CloudflareKv(env.PLUGIN_CHAIN_STATE),
});
bindHandlers(eventHandler);
Expand Down
4 changes: 2 additions & 2 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Worker tests", () => {
const res = await worker.fetch(req, {
WEBHOOK_SECRET: "",
APP_ID: "",
PRIVATE_KEY: "",
APP_PRIVATE_KEY: "",
PLUGIN_CHAIN_STATE: {} as KVNamespace,
});
expect(res.status).toEqual(500);
Expand All @@ -51,7 +51,7 @@ describe("Worker tests", () => {
const res = await worker.fetch(req, {
WEBHOOK_SECRET: "webhook-secret",
APP_ID: "app-id",
PRIVATE_KEY: "private-key",
APP_PRIVATE_KEY: "private-key",
PLUGIN_CHAIN_STATE: {} as KVNamespace,
});
expect(res.status).toEqual(200);
Expand Down

0 comments on commit a790b9b

Please sign in to comment.