Skip to content

Commit

Permalink
fix some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yigithan Karabulut committed Jul 21, 2024
1 parent 6b83774 commit 6c04bcd
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 83 deletions.
26 changes: 14 additions & 12 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: user search boş gönderilmiycek, form validation. avatar eklenmeden istek atılınca erroru handlela. gameplayde updategame token kaldır. friends ->>><<<<
# ------ Common Storages Credentials ------
REDIS_HOST=redis
REDIS_PORT=6379
Expand All @@ -8,11 +9,12 @@ RABBITMQ_DEFAULT_PASS=guest
RABBITMQ_DEFAULT_VHOST=/
RABBITMQ_QUEUE_NAME=mail-service

FRONTEND_URL="http://127.0.0.1:808"
FRONTEND_URL="https://127.0.0.1:443"
NGINX_SSL_CN="127.0.0.1:443"

# Apigateway TODO: update apigateway cors and allowed hosts settings
ApiGateway_SECRET_KEY="MySecretKey-ApiGateway-123-ABC-456-DEF"
ApiGateway_DEBUG=True
ApiGateway_DEBUG=False

# Gameservice
GameService_SECRET_KEY="MySecretKey-GameService-123-ABC-456-DEF"
Expand All @@ -25,16 +27,16 @@ GameService_DB_PORT=5432

# Authservice TODO: update authservice cors and allowed hosts settings
AuthService_SECRET_KEY="MySecretKey-AuthService-123-ABC-456-DEF"
AuthService_DEBUG=True
INTRA_REDIRECT_URL='https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-dc37cfd139ab23e08bf900d921dfd5e1aaa6d5d5884b8f2d701707e575cc6b36&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fauth%2Fintra%2Fcallback&response_type=code'
AuthService_DEBUG=False
INTRA_REDIRECT_URL='https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-dc37cfd139ab23e08bf900d921dfd5e1aaa6d5d5884b8f2d701707e575cc6b36&redirect_uri=https%3A%2F%2F127.0.0.1%3A443%2Fapi%2Fauth%2Fintra%2Fcallback&response_type=code'
INTRA_UID='u-s4t2ud-dc37cfd139ab23e08bf900d921dfd5e1aaa6d5d5884b8f2d701707e575cc6b36'
INTRA_SECRET='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'
INTRA_API_URL="https://api.intra.42.fr"
INTRA_CALLBACK_URL="http://localhost:8000/auth/intra/callback"
INTRA_CALLBACK_URL="https://127.0.0.1:443/api/auth/intra/callback"

# Bucketservice
BucketService_SECRET_KEY="MySecretKey-BucketService-123-ABC-456-DEF"
BucketService_DEBUG=True
BucketService_DEBUG=False
BucketService_DB_NAME=bucketpostgres
BucketService_DB_USER=yigit
BucketService_DB_PASSWORD=yigit
Expand All @@ -43,7 +45,7 @@ BucketService_DB_PORT=5432

# Friendservice
FriendService_SECRET_KEY="MySecretKey-FriendService-123-ABC-456-DEF"
FriendService_DEBUG=True
FriendService_DEBUG=False
FriendService_DB_NAME=friendpostgres
FriendService_DB_USER=yigit
FriendService_DB_PASSWORD=yigit
Expand All @@ -52,11 +54,11 @@ FriendService_DB_PORT=5432

# Gameplayservice
GamePlayService_SECRET_KEY="MySecretKey-GameplayService-123-ABC-456-DEF"
GamePlayService_DEBUG=True
GamePlayService_DEBUG=False

# TODO: Mailservice rabbitmq/host/port/debug/secrkey and smtp server needs to be updated
MailService_SECRET_KEY="MySecretKey-MailService-123-ABC-456-DEF"
MailService_DEBUG=True
MailService_DEBUG=False
MailService_EMAIL_HOST=smtp.gmail.com
MailService_EMAIL_PORT=587
MailService_EMAIL_USE_TLS=True
Expand All @@ -65,13 +67,13 @@ MailService_EMAIL_HOST_PASSWORD=aowjdppvonjvayng

# Statusservice
StatusService_SECRET_KEY="MySecretKey-StatusService-123-ABC-456-DEF"
StatusService_DEBUG=True
StatusService_DEBUG=False

# UserManagemen
UserManagement_SECRET_KEY="MySecretKey-UserManagement-123-ABC-456-DEF"
UserManagement_DEBUG=True
UserManagement_DEBUG=False
UserManagement_DB_NAME=userpostgres
UserManagement_DB_USER=yigit
UserManagement_DB_PASSWORD=yigit
UserManagement_DB_HOST=userpostgres
UserManagement_DB_PORT=5432
UserManagement_DB_PORT=5432
1 change: 1 addition & 0 deletions apigateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ RUN pip3 install --upgrade pip

RUN pip3 install -r requirements.txt

EXPOSE 8000

CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
2 changes: 1 addition & 1 deletion apigateway/apigateway/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG')

ALLOWED_HOSTS = ['35.242.209.3', 'localhost', '127.0.0.1', '0.0.0.0', 'apigateway', 'usermanagement', 'authservice', 'gameservice', 'friendservice', 'statusservice', 'gameplayservice', '[::1]']
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down
4 changes: 2 additions & 2 deletions apigateway/src/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
if request.path in self.paths_to_exclude:
return None

if request.path.startswith('/user/email_verify'):
if request.path.startswith('/user/email_verify') or request.path.startswith('/user/reset-password') or request.path.startswith('/user/pwd/change'):
return None

token = request.headers.get('Authorization')
Expand All @@ -35,4 +35,4 @@ def process_view(self, request, view_func, view_args, view_kwargs):
return JsonResponse({'error': err_msg}, status=status)

request.user_id = response.json().get('user_id')
return None
return None
22 changes: 9 additions & 13 deletions apigateway/src/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging

import requests
from django.conf import settings
from django.http import HttpResponseRedirect
Expand All @@ -12,8 +11,7 @@ class APIGatewayView(APIView):

def operations(self, request, path):
headers = dict(request.headers)
if request.path.startswith('/user/email_verify'):
headers['Content-Type'] = 'application/json'
if request.path.startswith('/user/email_verify') or request.path.startswith('/user/reset-password') or request.path.startswith('/user/pwd/change'):
return pass_request_to_destination_service(request, path, headers)
if not (settings.EXCLUDED_ROUTES and request.path in settings.EXCLUDED_ROUTES):
headers['id'] = str(request.user_id)
Expand Down Expand Up @@ -41,10 +39,17 @@ def pass_request_to_destination_service(request, path, headers):
return Response({'error': 'Invalid path'}, status=status.HTTP_404_NOT_FOUND)

full_url = f"{base_url}/{path}"
logging.error("--++++++++ full_url: %s", full_url)
params = request.query_params
if params:
full_url += f"?{params.urlencode()}"
method = request.method.lower()
if path.startswith('user/email_verify') or path.startswith('user/reset-password'):
logging.error("---------------------<>>>>>>>>>>>>>>>>> ")
response = requests.get(full_url)
json_response = response.json()
if 'redirect_url' in json_response:
return HttpResponseRedirect(json_response['redirect_url'])
try:
response = requests.request(method, full_url, headers=headers, json=request.data)
except requests.exceptions.RequestException as e:
Expand All @@ -56,15 +61,6 @@ def pass_request_to_destination_service(request, path, headers):
if 'redirect_url' in json_response:
return HttpResponseRedirect(json_response['redirect_url'])

if path.startswith('user/email_verify') and response.status_code == 200:
try:
json_response = response.json()
if 'redirect_url' in json_response:
return HttpResponseRedirect(json_response['redirect_url'])
except Exception as e:
logging.error(f"Error in request: {e}")
return Response({'error': 'Internal server error'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

if response.headers.get('content-type') == 'application/json':
return Response(response.json(), status=response.status_code)
return Response(response.content, status=response.status_code)
Expand All @@ -74,4 +70,4 @@ def get_service_url(path):
for route, url in settings.SERVICE_ROUTES.items():
if path.startswith(route):
return url
return None
return None
1 change: 1 addition & 0 deletions authservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ RUN pip3 install --upgrade pip

RUN pip3 install -r requirements.txt

EXPOSE 8001

CMD [ "python3", "manage.py", "runserver", "0.0.0.0:8001"]
2 changes: 1 addition & 1 deletion authservice/authservice/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG')

ALLOWED_HOSTS = ['35.242.209.3', 'localhost', '127.0.0.1', '0.0.0.0', 'authservice', 'apigateway', 'usermanagement', 'gameservice', 'friendservice', 'statusservice', 'gameplayservice']
ALLOWED_HOSTS = ['*']

INTRA_REDIRECT_URL = os.environ.get('INTRA_REDIRECT_URL')
INTRA_UID = os.environ.get('INTRA_UID')
Expand Down
1 change: 1 addition & 0 deletions bucketservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY start.sh /app/start.sh

RUN chmod +x /app/start.sh

EXPOSE 8014

ENTRYPOINT ["sh", "./start.sh"]

Expand Down
Binary file added bucketservice/media/images/author.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 50 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ version: '3.8'
services:
frontend:
container_name: frontend
build: ./frontend
build:
context: ./frontend
dockerfile: Dockerfile
args:
- NGINX_SSL_CN=${NGINX_SSL_CN}
depends_on:
- apigateway
- bucketservice
Expand All @@ -14,6 +18,8 @@ services:
- ./frontend/nginx.conf:/etc/nginx/nginx.conf
ports:
- "443:443"
networks:
- frontend

apigateway:
container_name: apigateway
Expand All @@ -24,12 +30,13 @@ services:
- usermanagement
environment:
- SECRET_KEY=${ApiGateway_SECRET_KEY}
- DEBUG=True
- DEBUG=${ApiGateway_DEBUG}
- FRONTEND_URL=${FRONTEND_URL}
volumes:
- ./apigateway:/app
ports:
- "8000:8000"
networks:
- backend
- frontend

authservice:
container_name: authservice
Expand All @@ -45,8 +52,8 @@ services:
- FRONTEND_URL=${FRONTEND_URL}
volumes:
- ./authservice:/app
ports:
- "8001:8001"
networks:
- backend

bucketservice:
container_name: bucketservice
Expand All @@ -63,8 +70,9 @@ services:
- DB_PORT=${BucketService_DB_PORT}
volumes:
- ./bucketservice:/app
ports:
- "8014:8014"
networks:
- backend
- frontend

friendservice:
container_name: friendservice
Expand All @@ -81,8 +89,8 @@ services:
- DB_PORT=${FriendService_DB_PORT}
volumes:
- ./friendservice:/app
ports:
- "8012:8012"
networks:
- backend

gameplayservice:
container_name: gameplayservice
Expand All @@ -96,8 +104,9 @@ services:
- REDIS_PORT=${REDIS_PORT}
volumes:
- ./gameplayservice:/app
ports:
- "8011:8011"
networks:
- backend
- frontend

gameservice:
container_name: gameservice
Expand All @@ -114,8 +123,8 @@ services:
- DB_PORT=${GameService_DB_PORT}
volumes:
- ./gameservice:/app
ports:
- "8010:8010"
networks:
- backend

mailservice:
container_name: mailservice
Expand All @@ -139,8 +148,8 @@ services:
- EMAIL_HOST_PASSWORD=${MailService_EMAIL_HOST_PASSWORD}
volumes:
- ./mailservice:/app
ports:
- "8005:8005"
networks:
- backend

statusservice:
container_name: statusservice
Expand All @@ -152,8 +161,9 @@ services:
- REDIS_PORT=${REDIS_PORT}
volumes:
- ./statusservice:/app
ports:
- "8020:8020"
networks:
- backend
- frontend

usermanagement:
container_name: usermanagement
Expand All @@ -177,8 +187,9 @@ services:
- RABBITMQ_QUEUE_NAME=${RABBITMQ_QUEUE_NAME}
volumes:
- ./usermanagement:/app
ports:
- "8004:8004"
networks:
- backend
- frontend

rabbitmq:
container_name: rabbitmq
Expand All @@ -193,13 +204,17 @@ services:
test: ["CMD", "rabbitmqctl", "node_health_check"]
interval: 30s
timeout: 10s
retries: 5
retries: 5
networks:
- backend

redis:
container_name: redis
image: redis:6.2.5
ports:
- "6379:${REDIS_PORT}"
networks:
- backend

userpostgres:
container_name: userpostgres
Expand All @@ -210,6 +225,8 @@ services:
POSTGRES_DB: ${UserManagement_DB_NAME}
ports:
- "5432:${UserManagement_DB_PORT}"
networks:
- backend

gamepostgres:
container_name: gamepostgres
Expand All @@ -220,6 +237,8 @@ services:
POSTGRES_DB: ${GameService_DB_NAME}
ports:
- "5433:${GameService_DB_PORT}"
networks:
- backend

friendspostgres:
container_name: friendspostgres
Expand All @@ -230,6 +249,8 @@ services:
POSTGRES_DB: ${FriendService_DB_NAME}
ports:
- "5434:${FriendService_DB_PORT}"
networks:
- backend

bucketpostgres:
container_name: bucketpostgres
Expand All @@ -240,4 +261,12 @@ services:
POSTGRES_DB: ${BucketService_DB_NAME}
ports:
- "5435:${BucketService_DB_PORT}"
networks:
- backend


networks:
backend:
driver: bridge
frontend:
driver: bridge
1 change: 1 addition & 0 deletions friendservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY start.sh /app/start.sh

RUN chmod +x /app/start.sh

EXPOSE 8012

ENTRYPOINT ["sh", "./start.sh"]

Expand Down
Loading

0 comments on commit 6c04bcd

Please sign in to comment.