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

Removed unnecesary env variables #31

Merged
merged 1 commit into from
May 6, 2024
Merged
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
35 changes: 15 additions & 20 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
DEBUG=False
SECRET_KEY=django-insecure-#-z
ALLOWED_HOSTS=*
# Add new sites by separating them with a comma
CSRF_TRUSTED_ORIGINS=http://localhost:8002,http://127.0.0.1:8002
DEBUG=True
SECRET_KEY=your-secret-key
DB_ENGINE=django.db.backends.postgresql
DB_NAME=postgres
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=db
DB_PORT=5432
REDIS_URL=redis://redis:6379/0
HOST_URL=http://localhost:8002
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
DISCORD_REDIRECT_URI=http://localhost:8002/accounts/discord/callback
STEAM_API_KEY=
STEAM_REDIRECT_URI=http://localhost:8002/accounts/steam/callback
RCON_HOST=
RCON_PORT=27015
RCON_PASSWORD=
SERVER_PASSWORD=change_me
SERVER_PORT=27015
POSTGRES_DB=cs2_db
POSTGRES_USER=cs2_user
POSTGRES_PASSWORD=cs2_password
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=redis_password
DISCORD_CLIENT_ID=discord_client_id
DISCORD_CLIENT_SECRET=discord_client_secret
STEAM_API_KEY=some_steam_api_key
CSRF_TRUSTED_ORIGINS=http://localhost:8002
CORS_ALLOW_ALL_ORIGINS=True
SECURE_SSL_REDIRECT=False
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ COPY --from=builder /code /app

# Copy the source code
COPY src /app/
COPY scripts /app/scripts


# Change ownership to the dedicated user
RUN chown -R fastapiuser:fastapi /app
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ services:
db:
image: postgres:15.1
container_name: cs2_battle_bot_db
environment:
- POSTGRES_DB=cs2_db
- POSTGRES_USER=cs2_user
- POSTGRES_PASSWORD=cs2_password
env_file:
- .env
restart: unless-stopped
ports:
- "5435:5432"
Expand All @@ -33,6 +31,7 @@ services:
redis:
image: "redis:alpine"
container_name: cs2_battle_bot_redis
command: redis-server --requirepass ${REDIS_PASSWORD}
restart: unless-stopped
expose:
- "6379:6379"
Expand Down
4 changes: 0 additions & 4 deletions nginx/Dockerfile

This file was deleted.

19 changes: 0 additions & 19 deletions nginx/nginx.conf

This file was deleted.

294 changes: 147 additions & 147 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cs2-battle-bot-api"
version = "0.0.33"
version = "0.0.34"
description = ""
authors = ["Adrian Ciolek <[email protected]>"]
readme = "README.md"
Expand Down
25 changes: 21 additions & 4 deletions src/accounts/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.urls import reverse_lazy, reverse
import httpx
from rest_framework.authentication import TokenAuthentication
from rest_framework_api_key.models import APIKey
Expand Down Expand Up @@ -33,8 +34,19 @@ def __init__(
"""Initialize the SteamAuthService."""
self.auth_url = "https://steamcommunity.com/openid/login"

def get_login_url(self):
return f"{self.auth_url}?openid.ns=http://specs.openid.net/auth/2.0&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.return_to={settings.STEAM_REDIRECT_URI}&openid.realm={settings.HOST_URL}/"
def get_login_url(self, request):
steam_callback_relative_url = reverse('steam_callback')
steam_callback_full_url = request.build_absolute_uri(steam_callback_relative_url)
openid_realm = request.build_absolute_uri()
# remove from url /accounts/steam/
openid_realm = openid_realm[:-15]
return (f""
f"{self.auth_url}?openid.ns=http://specs.openid.net/auth/2.0"
f"&openid.identity=http://specs.openid.net/auth/2.0/identifier_select"
f"&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select"
f"&openid.mode=checkid_setup"
f"&openid.return_to={steam_callback_full_url}"
f"&openid.realm={openid_realm}")

@staticmethod
def get_steamid_from_url(url: str) -> str:
Expand Down Expand Up @@ -162,8 +174,13 @@ def __init__(self) -> None:
self.auth_url = "https://discord.com/api/oauth2/authorize"
self.token_url = "https://discord.com/api/oauth2/token"

def get_login_url(self):
return f"{self.auth_url}?client_id={settings.DISCORD_CLIENT_ID}&response_type=code&redirect_uri={settings.DISCORD_REDIRECT_URI}&scope=identify+email"
def get_login_url(self, request):
redirect_url = request.build_absolute_uri(reverse_lazy("discord_callback"))
return (f""
f"{self.auth_url}?client_id={settings.DISCORD_CLIENT_ID}"
f"&response_type=code"
f"&redirect_uri={redirect_url}"
f"&scope=identify+email")

def exchange_code(self, code: str) -> dict:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def redirect_to_discord(request):
discord_auth = DiscordAuthService()
return redirect(discord_auth.get_login_url())
return redirect(discord_auth.get_login_url(request=request))


def discord_callback(request):
Expand Down Expand Up @@ -60,7 +60,7 @@ def redirect_to_steam(request):
if not dc_user:
return redirect("/accounts/discord/")
steam_auth = SteamAuthService()
return redirect(steam_auth.get_login_url())
return redirect(steam_auth.get_login_url(request=request))


def steam_callback(request):
Expand Down
29 changes: 9 additions & 20 deletions src/cs2_battle_bot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pathlib import Path

import toml
from rest_framework.authentication import TokenAuthentication

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -37,9 +36,10 @@
"CSRF_TRUSTED_ORIGINS", "http://localhost:8002"
).split(",")

SECURE_SSL_REDIRECT = os.environ.get("SECURE_SSL_REDIRECT", "False") == "True"
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

SECURE_SSL_REDIRECT = os.environ.get("SECURE_SSL_REDIRECT", "True") == "True"
# ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = tuple(os.environ.get("SECURE_PROXY_SSL_HEADER", "").split(',')) if os.environ.get(
"SECURE_PROXY_SSL_HEADER") else None
# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -69,7 +69,7 @@
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
#'accounts.auth.BearerTokenAuthentication',
# 'accounts.auth.BearerTokenAuthentication',
],
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
Expand Down Expand Up @@ -126,9 +126,9 @@
DATABASES = {
"default": {
"ENGINE": os.environ.get("DB_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("DB_NAME", BASE_DIR / "db.sqlite3"),
"USER": os.environ.get("DB_USER", "user"),
"PASSWORD": os.environ.get("DB_PASSWORD", "password"),
"NAME": os.environ.get("POSTGRES_DB", BASE_DIR / "db.sqlite3"),
"USER": os.environ.get("POSTGRES_USER", "user"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", "password"),
"HOST": os.environ.get("DB_HOST", "localhost"),
"PORT": os.environ.get("DB_PORT", "5432"),
},
Expand All @@ -137,7 +137,7 @@
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ.get("REDIS_URL", "redis://127.0.0.1:6379/1"),
"LOCATION": f"redis://:{os.environ.get('REDIS_PASSWORD')}@{os.environ.get('REDIS_HOST')}:{os.environ.get('REDIS_PORT')}/{os.environ.get('REDIS_DB')}",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
Expand Down Expand Up @@ -181,21 +181,10 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

HOST_URL = os.environ.get("HOST_URL", "http://localhost:8002")

DISCORD_CLIENT_ID = os.environ.get("DISCORD_CLIENT_ID", "id")
DISCORD_CLIENT_SECRET = os.environ.get("DISCORD_CLIENT_SECRET", "secret")
DISCORD_REDIRECT_URI = os.environ.get("DISCORD_REDIRECT_URI", "uri")

STEAM_API_KEY = os.environ.get("STEAM_API_KEY", "key")
STEAM_REDIRECT_URI = os.environ.get("STEAM_REDIRECT_URI", "uri")

RCON_HOST = os.environ.get("RCON_HOST", "localhost")
RCON_PORT = os.environ.get("RCON_PORT", 27015)
RCON_PASSWORD = os.environ.get("RCON_PASSWORD", "password")
SERVER_PORT = os.environ.get("SERVER_PORT", 27015)
SERVER_PASSWORD = os.environ.get("SERVER_PASSWORD", "changeme")
API_KEY = os.environ.get("API_KEY", "key")

AUTH_USER_MODEL = "accounts.User" # new

Expand Down
3 changes: 0 additions & 3 deletions src/matches/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import math

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Q
from prefix_id import PrefixIDField
from rest_framework.authtoken.models import Token
from rest_framework.reverse import reverse_lazy

from players.models import Team

Expand Down