Skip to content

Commit

Permalink
feat: use env variables and secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjibansg committed Nov 8, 2023
1 parent 004f6b3 commit 0b58268
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
paths:
- 'api/**'

env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
DUCKDB_POOL_SIZE: ${{ variables.DUCKDB_POOL_SIZE }}

jobs:
deploy:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
paths:
- 'client/**'

env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
DUCKDB_POOL_SIZE: ${{ variables.DUCKDB_POOL_SIZE }}

jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Test

on: [push]

env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
DUCKDB_POOL_SIZE: ${{ variables.DUCKDB_POOL_SIZE }}

jobs:
Pytest:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_client_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Cypress Test

on: [push]

env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
DUCKDB_POOL_SIZE: ${{ variables.DUCKDB_POOL_SIZE }}

jobs:
electron-run:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_client_unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Vitest

on: [push]

env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
DUCKDB_POOL_SIZE: ${{ variables.DUCKDB_POOL_SIZE }}

jobs:
unit-test:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion api/components/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import jwt
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
Expand All @@ -9,7 +11,8 @@
############################################################
def verify_token(token: str = Depends(oauth2_scheme)):
try:
payload = jwt.decode(token, "key", algorithms=["HS256"])
payload = jwt.decode(token, os.environ.get("SESSION_SECRET"),
algorithms=["HS256"])
return payload
except jwt.exceptions.DecodeError:
raise HTTPException(
Expand Down
4 changes: 3 additions & 1 deletion api/components/duckdb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

import duckdb
from fastapi import HTTPException
from loguru import logger

# Pool size is default at 5 for maintaining
# 5 concurrent DuckDB connection objects
POOL_SIZE = 5
POOL_SIZE = os.environ.get("DUCKDB_POOL_SIZE")



Expand Down
5 changes: 3 additions & 2 deletions api/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from uuid import uuid4

import jwt
Expand Down Expand Up @@ -50,7 +51,7 @@ def test_validate_binary():
def test_add_schema():
with TestClient(app) as client:
payload = {"user_id": str(uuid4()).replace('-', '_')}
token = jwt.encode(payload, "key", algorithm="HS256")
token = jwt.encode(payload,os.environ.get("SESSION_SECRET"), algorithm="HS256")
schema = '''
{
"table": "test",
Expand Down Expand Up @@ -80,7 +81,7 @@ def test_add_schema():
def test_parse_to_substrait():
with TestClient(app) as client:
payload = {"user_id": str(uuid4())}
token = jwt.encode(payload, "key", algorithm="HS256")
token = jwt.encode(payload, os.environ.get("SESSION_SECRET"), algorithm="HS256")

response = client.post(
"/route/parse/",
Expand Down
2 changes: 1 addition & 1 deletion client/src/assets/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function generateToken(user_id) {
const payload = {
user_id: user_id,
};
const secret = new TextEncoder().encode("key");
const secret = new TextEncoder().encode(process.env.SESSION_SECRET);
const token = await new jose.SignJWT(payload)
.setProtectedHeader({ alg: "HS256" })
.sign(secret);
Expand Down

0 comments on commit 0b58268

Please sign in to comment.