Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Requirements, ability to run program locally #128

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONYS: run deps dev

venv:
virtualenv venv

requirements-dev.txt:
pip-compile requirements-dev.in > requirements-dev.txt

requirements.txt:
pip-compile requirements.in > requirements.txt

dev-deps: requirements-dev.txt
pip install -r requirements-dev.txt

deps: requirements.txt
pip install -r requirements.txt

dev: venv requirements-dev.txt requirements.txt deps dev-deps

run:
python3 app/main.py
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ This is to be replaced by Influx in the future, a more fleshed-out approach with
## Getting Started (local)
```py
# Requires >= Python3.8
python3 -m pip install -r requirements.txt
python3 index.py
make dev
```

## Deploying
Expand Down
28 changes: 14 additions & 14 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from jose import jwt
from requests_oauthlib import OAuth2Session
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

# Import data types
from app.models.user import DiscordModel, EthicsFormModel, UserModel, user_to_dict
from .models.user import DiscordModel, EthicsFormModel, UserModel, user_to_dict
from requests_oauthlib import OAuth2Session

# Import routes
from app.routes import admin, api, infra, stripe, wallet
from app.util.approve import Approve
from .routes import admin, api, infra, stripe, wallet
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select
from .util.approve import Approve

# Import middleware
from app.util.authentication import Authentication
from app.util.database import get_session, init_db
from app.util.discord import Discord
from .util.authentication import Authentication
from .util.database import get_session, init_db
from .util.discord import Discord

# Import error handling
from app.util.errors import Errors
from app.util.forms import Forms
from .util.errors import Errors
from .util.forms import Forms

# Import the page rendering library
from app.util.kennelish import Kennelish
from .util.kennelish import Kennelish

# Import options
from app.util.settings import Settings
from .util.settings import Settings

if Settings().telemetry.enable:
if Settings().telemetry and Settings().telemetry.enable:
import sentry_sdk
### TODO: TEMP
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "0"
Expand Down
5 changes: 2 additions & 3 deletions app/models/info.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import List, Optional

from pydantic import BaseModel

# Import data types
from app.models.user import PublicContact
from ..models.user import PublicContact
from pydantic import BaseModel


class InfoModel(BaseModel):
Expand Down
21 changes: 10 additions & 11 deletions app/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
from fastapi import APIRouter, Body, Cookie, Depends, Request, Response
from fastapi.templating import Jinja2Templates
from jose import jwt
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

from app.models.user import (
from ..models.user import (
UserModel,
UserModelMutable,
user_to_dict,
user_update_instance,
)
from app.util.approve import Approve
from app.util.authentication import Authentication
from app.util.database import get_session
from app.util.discord import Discord
from app.util.email import Email
from app.util.errors import Errors
from app.util.settings import Settings
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select
from ..util.approve import Approve
from ..util.authentication import Authentication
from ..util.database import get_session
from ..util.discord import Discord
from ..util.email import Email
from ..util.errors import Errors
from ..util.settings import Settings

logger = logging.getLogger(__name__)

Expand Down
15 changes: 7 additions & 8 deletions app/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from typing import Optional

from fastapi import APIRouter, Cookie, Depends, HTTPException, Request
from ..models.info import InfoModel
from ..models.user import PublicContact, UserModel, user_to_dict, user_update_instance
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

from app.models.info import InfoModel
from app.models.user import PublicContact, UserModel, user_to_dict, user_update_instance
from app.util.authentication import Authentication
from app.util.database import get_session
from app.util.errors import Errors
from app.util.forms import Forms, apply_fuzzy_parsing, transform_dict
from app.util.kennelish import Transformer
from ..util.authentication import Authentication
from ..util.database import get_session
from ..util.errors import Errors
from ..util.forms import Forms, apply_fuzzy_parsing, transform_dict
from ..util.kennelish import Transformer

logger = logging.getLogger(__name__)

Expand Down
34 changes: 20 additions & 14 deletions app/routes/infra.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import logging
from typing import Optional

from fastapi import APIRouter, Cookie, Depends, Request
from fastapi import APIRouter, Cookie, Depends, Request, HTTPException
from fastapi.responses import FileResponse
from fastapi.templating import Jinja2Templates
from pathlib import Path
from sqlmodel import Session, select

from app.models.info import InfoModel
from app.models.user import PublicContact, UserModel
from app.util.approve import Approve
from app.util.authentication import Authentication
from app.util.database import get_session
from app.util.discord import Discord
from app.util.email import Email
from app.util.errors import Errors
from app.util.limiter import RateLimiter
from app.util.settings import Settings
from ..models.info import InfoModel
from ..models.user import PublicContact, UserModel
from ..util.approve import Approve
from ..util.authentication import Authentication
from ..util.database import get_session
from ..util.discord import Discord
from ..util.email import Email
from ..util.errors import Errors
from ..util.limiter import RateLimiter
from ..util.settings import Settings

logger = logging.getLogger(__name__)

Expand All @@ -42,6 +43,7 @@ async def get_root():
],
)

ERR_VPN_CONFIG_NOT_FOUND = HTTPException(status_code=500, detail="HackUCF OpenVPN Config Not Found")

@router.get("/openvpn")
@Authentication.member
Expand All @@ -55,6 +57,10 @@ async def download_file(
"""
# Replace 'path/to/your/file.txt' with the actual path to your file
file_path = "../HackUCF.ovpn"
return FileResponse(
file_path, filename="HackUCF.ovpn", media_type="application/octet-stream"
)
if not Path(file_path).exists():
## Return 500 ISE
raise ERR_VPN_CONFIG_NOT_FOUND
else:
return FileResponse(
file_path, filename="HackUCF.ovpn", media_type="application/octet-stream"
)
13 changes: 6 additions & 7 deletions app/routes/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from fastapi import APIRouter, Cookie, Depends, HTTPException, Request
from fastapi.responses import RedirectResponse
from fastapi.templating import Jinja2Templates
from ..models.user import UserModel, user_to_dict
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

from app.models.user import UserModel, user_to_dict
from app.util.approve import Approve
from app.util.authentication import Authentication
from app.util.database import get_session
from app.util.errors import Errors
from app.util.settings import Settings
from ..util.approve import Approve
from ..util.authentication import Authentication
from ..util.database import get_session
from ..util.errors import Errors
from ..util.settings import Settings

templates = Jinja2Templates(directory="app/templates")

Expand Down
11 changes: 5 additions & 6 deletions app/routes/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import requests
from airpress import PKPass
from fastapi import APIRouter, Cookie, Depends, Request, Response
from ..models.info import InfoModel
from ..models.user import PublicContact, UserModel, user_to_dict
from sqlalchemy.orm import selectinload
from sqlmodel import select

from app.models.info import InfoModel
from app.models.user import PublicContact, UserModel, user_to_dict
from app.util.authentication import Authentication
from app.util.database import get_session
from app.util.errors import Errors
from ..util.authentication import Authentication
from ..util.database import get_session
from ..util.errors import Errors

router = APIRouter(
prefix="/wallet", tags=["API", "MobileWallet"], responses=Errors.basic_http()
Expand Down
13 changes: 6 additions & 7 deletions app/util/approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import os

from keycloak import KeycloakAdmin
from ..models.user import UserModel
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

from app.models.user import UserModel
from app.util.database import engine
from app.util.discord import Discord
from app.util.email import Email
from app.util.horsepass import HorsePass
from app.util.settings import Settings
from .database import engine
from .discord import Discord
from .email import Email
from .horsepass import HorsePass
from .settings import Settings

logger = logging.getLogger()

Expand Down
7 changes: 3 additions & 4 deletions app/util/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from fastapi import Request, status
from fastapi.responses import RedirectResponse
from jose import jwt

from app.models.user import UserModel
from ..models.user import UserModel

# Import options and errors
from app.util.errors import Errors
from app.util.settings import Settings
from .errors import Errors
from .settings import Settings


class Authentication:
Expand Down
3 changes: 1 addition & 2 deletions app/util/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from alembic.runtime import migration
from sqlmodel import Session, SQLModel, create_engine
from sqlmodel.pool import StaticPool

from app.util.settings import Settings
from .settings import Settings

DATABASE_URL = Settings().database.url
# TODO remove echo=True
Expand Down
3 changes: 1 addition & 2 deletions app/util/discord.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json

import requests

from app.util.settings import Settings
from .settings import Settings

headers = {
"Authorization": f"Bot {Settings().discord.bot_token.get_secret_value()}",
Expand Down
3 changes: 1 addition & 2 deletions app/util/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from email.mime.text import MIMEText

import commonmark

from app.util.settings import Settings
from .settings import Settings

email = Settings().email.email
password = Settings().email.password.get_secret_value()
Expand Down
Loading