-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c786cd
commit cc8dcfb
Showing
106 changed files
with
951 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "lambda_function.handler" ] |
Binary file added
BIN
+3.65 KB
Lambda_Functions/private_library/__pycache__/lambda_function.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
export num=1.0 | ||
docker build -t techfest-private-library:$num . | ||
docker tag techfest-private-library:$num 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-private-library:$num | ||
docker push 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-private-library:$num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import psycopg2 | ||
import json | ||
import boto3 | ||
import os | ||
|
||
def handler(event, context): | ||
|
||
if 'body' not in event: | ||
return { | ||
"statusCode": 400, | ||
"body": json.dumps("Invalid request") | ||
} | ||
|
||
body = json.loads(event['body']) | ||
|
||
if 'token' not in body: | ||
return { | ||
"statusCode": 400, | ||
"body": json.dumps("Invalid request") | ||
} | ||
|
||
token = body['token'] | ||
|
||
uid = get_uid(token) | ||
|
||
if not uid: | ||
return { | ||
"statusCode": 401, | ||
"body": json.dumps("Unauthorized") | ||
} | ||
|
||
a = get_private_audio(uid) | ||
|
||
key = os.getenv("AWS_ACCESS") | ||
secret = os.getenv("AWS_SECRET") | ||
|
||
s3 = boto3.client("s3", aws_access_key_id=key, aws_secret_access_key=secret, region_name="ap-south-1") | ||
newlist = [] | ||
for audio in a: | ||
s3key = audio['key'] + ".wav" | ||
s3url = s3.generate_presigned_url('get_object', Params={'Bucket': 'techfest-mp3', 'Key': s3key}, ExpiresIn=3600) | ||
audio['url'] = s3url | ||
newlist.append(audio) | ||
|
||
return { | ||
"statusCode": 200, | ||
"body": json.dumps(newlist) | ||
} | ||
|
||
def get_private_audio(uid): | ||
conn = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME'), | ||
user=os.getenv('DB_USER'), | ||
password=os.getenv('DB_PASSWORD'), | ||
host=os.getenv('DB_HOST'), | ||
port=os.getenv('DB_PORT'), | ||
sslmode='require' | ||
) | ||
|
||
cur = conn.cursor() | ||
|
||
cur.execute("SELECT * FROM audio WHERE uid=%s", (uid,)) | ||
|
||
rows = cur.fetchall() | ||
|
||
audio_public = [] | ||
for row in rows: | ||
audio_dict = {'id': row[0], 'uid': row[1], 'key': row[2], 'private': row[3], | ||
'name': row[4], 'genre': row[5], 'duration': row[6]} | ||
audio_public.append(audio_dict) | ||
|
||
conn.close() | ||
|
||
return audio_public | ||
|
||
|
||
def get_uid(token): | ||
try: | ||
# establish a connection | ||
connection = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME'), | ||
user=os.getenv('DB_USER'), | ||
password=os.getenv('DB_PASSWORD'), | ||
host=os.getenv('DB_HOST'), | ||
port=os.getenv('DB_PORT'), | ||
sslmode='require' | ||
) | ||
|
||
# create a cursor | ||
cursor = connection.cursor() | ||
|
||
# write your query | ||
query = "SELECT * FROM current_sign_in WHERE token = %s;" | ||
|
||
# execute the query | ||
cursor.execute(query, (token,)) | ||
|
||
# fetch all the matching records | ||
records = cursor.fetchall() | ||
|
||
# close the cursor and the connection | ||
cursor.close() | ||
connection.close() | ||
|
||
# check if any record exists | ||
if records: | ||
return records[0][0] # assuming uid column is the first one | ||
else: | ||
return False | ||
|
||
except (Exception, psycopg2.DatabaseError) as error: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
psycopg2-binary | ||
boto3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from lambda_function import handler | ||
import json | ||
|
||
event = {"body": json.dumps({"token": "8dbb50fe6974e5e3eb574b7f0b3b15defd3bfbf812db9140f461b2d63f406bf94d66c7c2a29ad3459a60b62c96cc631d723d5d5593942efa7ee0c0d80a31c9d051193d2980d28a332ad3cfefd01ec3924016cd4a125b0a6a99fa0b6dd9243fa12d09fffea776aeb5240ae16d6abce77131fc00533e382c6c90ea1eb4c6b650"})} | ||
context = None | ||
|
||
response = handler(event, context) | ||
print(json.loads(response["body"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "lambda_function.handler" ] |
Binary file added
BIN
+2.24 KB
Lambda_Functions/public_library/__pycache__/lambda_function.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
export num=1.0 | ||
docker build -t techfest-public-library:$num . | ||
docker tag techfest-public-library:$num 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-public-library:$num | ||
docker push 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-public-library:$num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import psycopg2 | ||
import json | ||
import os | ||
import boto3 | ||
|
||
def handler(event, context): | ||
a = get_public_audio() | ||
|
||
key = os.getenv("AWS_ACCESS") | ||
secret = os.getenv("AWS_SECRET") | ||
|
||
s3 = boto3.client("s3", aws_access_key_id=key, aws_secret_access_key=secret, region_name="ap-south-1") | ||
newlist = [] | ||
for audio in a: | ||
s3key = audio['key'] + ".wav" | ||
s3url = s3.generate_presigned_url('get_object', Params={'Bucket': 'techfest-mp3', 'Key': s3key}, ExpiresIn=3600) | ||
audio['url'] = s3url | ||
newlist.append(audio) | ||
|
||
return { | ||
"statusCode": 200, | ||
"body": json.dumps(newlist) | ||
} | ||
|
||
def get_public_audio(): | ||
conn = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME'), | ||
user=os.getenv('DB_USER'), | ||
password=os.getenv('DB_PASSWORD'), | ||
host=os.getenv('DB_HOST'), | ||
port=os.getenv('DB_PORT'), | ||
sslmode='require' | ||
) | ||
|
||
cur = conn.cursor() | ||
|
||
cur.execute("SELECT * FROM audio WHERE private=0") | ||
|
||
rows = cur.fetchall() | ||
|
||
audio_public = [] | ||
for row in rows: | ||
audio_dict = {'id': row[0], 'uid': row[1], 'key': row[2], 'private': row[3], | ||
'name': row[4], 'genre': row[5], 'duration': row[6]} | ||
audio_public.append(audio_dict) | ||
|
||
conn.close() | ||
|
||
return audio_public | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
psycopg2-binary | ||
boto3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from lambda_function import handler | ||
import json | ||
|
||
event = {} | ||
context = None | ||
|
||
response = handler(event, context) | ||
print(json.loads(response["body"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "lambda_function.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export num=1.1 | ||
docker build -t techfest-sign-in:$num . | ||
docker tag techfest-sign-in:$num 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-sign-in:$num | ||
docker push 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-sign-in:$num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import psycopg2 | ||
|
||
import psycopg2 | ||
import json | ||
import secrets | ||
import os | ||
|
||
def handler(event, context): | ||
|
||
if 'body' not in event: | ||
return { "statusCode": 400, "body": json.dumps("Bad request") } | ||
|
||
connection = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME'), | ||
user=os.getenv('DB_USER'), | ||
password=os.getenv('DB_PASSWORD'), | ||
host=os.getenv('DB_HOST'), | ||
port=os.getenv('DB_PORT'), | ||
sslmode='require' | ||
) | ||
cursor = connection.cursor() | ||
|
||
# Retrieve user data from the request body | ||
body = json.loads(event['body']) | ||
|
||
if 'email' not in body or 'password' not in body: | ||
return { "statusCode": 400, "body": json.dumps("Bad request") } | ||
|
||
email = body['email'] | ||
password = body['password'] | ||
|
||
# Check if the email and password exist in the "user" table | ||
cursor.execute("SELECT * FROM users WHERE email = %s AND password = %s", (email, password)) | ||
user = cursor.fetchone() | ||
|
||
if user is None: | ||
return { "statusCode": 400, "body": json.dumps("Invalid credentials") } | ||
|
||
uid = user[0] # Assuming the uid is the first column of the user table | ||
token = secrets.token_hex(256) | ||
|
||
# Insert the uid and token into the "current_sign_in" table | ||
cursor.execute("INSERT INTO current_sign_in (uid, token) VALUES (%s, %s)", (uid, token)) | ||
connection.commit() | ||
|
||
# Close the connection and the cursor | ||
cursor.close() | ||
connection.close() | ||
|
||
return { "statusCode": 200, "body": json.dumps({ "token": token }) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
psycopg2-binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "lambda_function.handler" ] |
Binary file added
BIN
+1.47 KB
Lambda_Functions/sign_out/__pycache__/lambda_function.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
export num=1.0 | ||
docker build -t techfest-signout:$num . | ||
docker tag techfest-signout:$num 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-signout:$num | ||
docker push 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-signout:$num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import psycopg2 | ||
import json | ||
import os | ||
|
||
def handler(event, context): | ||
|
||
if 'body' not in event: | ||
return { "statusCode": 400, "body": json.dumps("Bad request") } | ||
|
||
connection = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME'), | ||
user=os.getenv('DB_USER'), | ||
password=os.getenv('DB_PASSWORD'), | ||
host=os.getenv('DB_HOST'), | ||
port=os.getenv('DB_PORT'), | ||
sslmode='require' | ||
) | ||
cursor = connection.cursor() | ||
|
||
# Retrieve user data from the request body | ||
body = json.loads(event['body']) | ||
|
||
if 'token' not in body: | ||
return { "statusCode": 400, "body": json.dumps("Bad request") } | ||
|
||
token = body['token'] | ||
|
||
# delete record from current_sign_in where token = token | ||
cursor.execute(f"DELETE FROM current_sign_in WHERE token = '{token}'") | ||
|
||
connection.commit() | ||
cursor.close() | ||
connection.close() | ||
|
||
return { | ||
"statusCode": 200, | ||
"body": json.dumps("Logged out successfully") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
psycopg2-binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "lambda_function.handler" ] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
export num=1.1 | ||
docker build -t techfest-signup:$num . | ||
docker tag techfest-signup:$num 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-signup:$num | ||
docker push 020308349020.dkr.ecr.ap-south-1.amazonaws.com/techfest-signup:$num |
Oops, something went wrong.