Dev Paragiri commited on
Commit
62862ac
1 Parent(s): aabd9f2
Files changed (6) hide show
  1. .gitignore +35 -0
  2. Dockerfile +11 -0
  3. authcheck.py +17 -0
  4. main.py +96 -0
  5. requirements.txt +29 -0
  6. schema.py +10 -0
.gitignore ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ *.pyc
3
+ __pycache__/
4
+ *.pyo
5
+ *.pyd
6
+
7
+ # Virtual environments
8
+ venv/
9
+ env/
10
+ env.bak/
11
+ env1/
12
+ env2/
13
+
14
+ # IDEs and editors
15
+ .idea/
16
+ .vscode/
17
+ *.sublime-project
18
+ *.sublime-workspace
19
+
20
+ # Logs and databases
21
+ *.log
22
+ *.sqlite3
23
+ *.db
24
+
25
+ # Compiled files
26
+ *.pyc
27
+ *.pyo
28
+ *.pyd
29
+ *.so
30
+ *.dll
31
+ *.exe
32
+
33
+ # Miscellaneous
34
+ .DS_Store
35
+ Thumbs.db
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
authcheck.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def auth_check(token):
2
+ if not token:
3
+ return {"status": 0, "message": f"Auth Token Missing"}
4
+
5
+ if token:
6
+ parts = token.split()
7
+ if len(parts) == 2 and parts[0].lower() == "bearer":
8
+ token = parts[1]
9
+ # You now have the Bearer token, and you can perform any necessary authentication or authorization checks.
10
+ if token == "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9":
11
+ return {"status": 1, "response": f"Bearer token: {token}"}
12
+ else:
13
+ return {"status": 0, "response": f"Invalid Token"}
14
+ else:
15
+ return {"status": 2, "response": f"Invalid Authorization header format"}
16
+ else:
17
+ return {"status": 2, "response": f"Token Missing"}
main.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI, Header, status
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from supabase import create_client, Client
5
+ from decouple import config
6
+ from schema import WalletSchema
7
+ from pydantic import BaseModel
8
+ from authcheck import auth_check
9
+
10
+
11
+ url = os.environ.get('SUPABASE_URL')
12
+ key = os.environ.get('SUPABASE_KEY')
13
+
14
+ app = FastAPI()
15
+ supabase: Client = create_client(url, key)
16
+
17
+ origins = ["*"]
18
+
19
+ app.add_middleware(
20
+ CORSMiddleware,
21
+ allow_origins=origins,
22
+ allow_credentials=True,
23
+ allow_methods=["*"], # Allow all methods or be specific e.g., ["GET", "POST"]
24
+ allow_headers=["*"], # Allow all headers or be specific e.g., ["Content-Type"]
25
+ )
26
+
27
+
28
+ @app.get("/")
29
+ async def read_root():
30
+ return {"message": "Welcome to hushh's Wallet API"}
31
+
32
+
33
+
34
+ @app.get("/wallet/")
35
+ async def get_wallet(id: str = Header(None), authentication: str = Header(None)):
36
+ """
37
+ Use this endpoint to get wallet card information!
38
+
39
+ Authorization token : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
40
+ """
41
+
42
+ # Checking for authentication
43
+ valid_auth = auth_check(authentication)
44
+ if valid_auth.get("status") != 1:
45
+ return valid_auth
46
+
47
+
48
+ try:
49
+ wallets = supabase.table('wallets').select('*').eq('id',id).execute()
50
+ return wallets
51
+
52
+ except:
53
+ return {"message": f"An unexpected error occured for the specified ID '{id}'."}
54
+
55
+ class WalletSchema(BaseModel):
56
+ id: int
57
+ brand_name: str
58
+ bg_image: str
59
+ logo: str
60
+ font_color: str
61
+ bg_color: str
62
+
63
+ @app.post("/add_wallet/", status_code=status.HTTP_201_CREATED)
64
+ async def add_wallet(wallet: WalletSchema, authentication: str = Header(None)):
65
+ """
66
+ Use this endpoint to add wallet cards!
67
+
68
+ Authorization token : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
69
+ """
70
+
71
+ # Checking for authentication
72
+ valid_auth = auth_check(authentication)
73
+ if valid_auth.get("status") != 1:
74
+ return valid_auth
75
+
76
+ try:
77
+ wallet = supabase.table('wallets').insert({
78
+ "id": wallet.id,
79
+ "brand_name": wallet.brand_name,
80
+ "bg_image": wallet.bg_image,
81
+ "logo": wallet.logo,
82
+ "font_color": wallet.font_color,
83
+ "bg_color": wallet.bg_color
84
+ }).execute()
85
+
86
+ return wallet
87
+
88
+ except:
89
+ return {"message": f"An unexpected error occured for the specified ID '{id}'."}
90
+
91
+
92
+
93
+
94
+ if __name__ == "__main__":
95
+ import uvicorn
96
+ uvicorn.run(app, host="0.0.0.0", port=8000)
requirements.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.6.0
2
+ anyio==4.2.0
3
+ certifi==2023.11.17
4
+ click==8.1.7
5
+ deprecation==2.1.0
6
+ exceptiongroup==1.2.0
7
+ fastapi==0.109.0
8
+ gotrue==2.1.0
9
+ h11==0.14.0
10
+ httpcore==1.0.2
11
+ httpx==0.25.2
12
+ idna==3.6
13
+ packaging==23.2
14
+ postgrest==0.15.0
15
+ pydantic==2.5.3
16
+ pydantic_core==2.14.6
17
+ python-dateutil==2.8.2
18
+ python-decouple==3.8
19
+ realtime==1.0.2
20
+ six==1.16.0
21
+ sniffio==1.3.0
22
+ starlette==0.35.1
23
+ storage3==0.7.0
24
+ StrEnum==0.4.15
25
+ supabase==2.3.4
26
+ supafunc==0.3.3
27
+ typing_extensions==4.9.0
28
+ uvicorn==0.27.0
29
+ websockets==11.0.3
schema.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class WalletSchema(BaseModel):
5
+ id: int
6
+ brand_name: str
7
+ bg_image: str
8
+ logo: str
9
+ font_color: str
10
+ bg_color: str