-
Notifications
You must be signed in to change notification settings - Fork 59
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
Showing
8 changed files
with
168 additions
and
20 deletions.
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,7 @@ | ||
|
||
from abc import abstractmethod | ||
|
||
class BaseDAO: | ||
@abstractmethod | ||
def get_client(): | ||
... |
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,41 @@ | ||
|
||
import json | ||
from dao.BaseDAO import BaseDAO | ||
from db.supabase.client import get_client | ||
from models.authorization import Authorization | ||
from supabase.client import Client, create_client | ||
|
||
class AuthorizationDAO(BaseDAO): | ||
client: Client | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.client = get_client() | ||
|
||
def exists(self, installation_id: str) -> bool: | ||
try: | ||
authorization = self.client.table("github_app_authorization")\ | ||
.select('*', count="exact")\ | ||
.eq('installation_id', installation_id) \ | ||
.execute() | ||
|
||
return bool(authorization.count) | ||
|
||
except Exception as e: | ||
print("Error: ", e) | ||
return {"message": "User creation failed"} | ||
|
||
def create(self, data: Authorization): | ||
print('supabase github_app_authorization creation', data.model_dump()) | ||
try: | ||
authorization = self.client.from_("github_app_authorization")\ | ||
.insert(data.model_dump())\ | ||
.execute() | ||
if authorization: | ||
return True, {"message": "User created successfully"} | ||
else: | ||
return False, {"message": "User creation failed"} | ||
except Exception as e: | ||
print("Error: ", e) | ||
return {"message": "User creation failed"} | ||
|
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,9 @@ | ||
from supabase.client import Client, create_client | ||
from uilts.env import get_env_variable | ||
|
||
supabase_url = get_env_variable("SUPABASE_URL") | ||
supabase_key = get_env_variable("SUPABASE_SERVICE_KEY") | ||
|
||
def get_client(): | ||
supabase: Client = create_client(supabase_url, supabase_key) | ||
return supabase |
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
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,25 @@ | ||
from datetime import datetime | ||
import json | ||
from pydantic import BaseModel, field_serializer | ||
from typing import Any, Dict | ||
|
||
class Authorization(BaseModel): | ||
token: str | ||
installation_id: str | ||
code: str | ||
created_at: datetime | ||
expires_at: datetime | ||
|
||
permissions: Dict | ||
|
||
@field_serializer('created_at') | ||
def serialize_created_at(self, created_at: datetime): | ||
return created_at.isoformat() | ||
|
||
@field_serializer('expires_at') | ||
def serialize_expires_at(self, expires_at: datetime): | ||
return expires_at.isoformat() | ||
|
||
@field_serializer('permissions') | ||
def serialize_permissions(self, permissions: Dict): | ||
return json.dumps(permissions) |
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
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 |
---|---|---|
|
@@ -13,4 +13,6 @@ python-multipart | |
httpx[socks] | ||
load_dotenv | ||
supabase | ||
boto3>=1.26.79 | ||
boto3>=1.34.84 | ||
jwt | ||
pydantic>=2.7.0 |
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