-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ add secrets functions to repository
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 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,3 @@ | ||
from .create_secret import create_secret | ||
from .delete_secret import delete_secret | ||
from .read_secret import read_secret |
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,21 @@ | ||
from uuid import UUID | ||
|
||
from models import get_supabase_client | ||
from utils import build_secret_unique_name | ||
|
||
|
||
def create_secret( | ||
user_id: UUID, brain_id: UUID, secret_name: str, secret_value | ||
) -> UUID | None: | ||
supabase_client = get_supabase_client() | ||
response = supabase_client.rpc( | ||
"insert_secret", | ||
{ | ||
"name": build_secret_unique_name( | ||
user_id=user_id, brain_id=brain_id, secret_name=secret_name | ||
), | ||
"secret": secret_value, | ||
}, | ||
).execute() | ||
|
||
return response.data |
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,18 @@ | ||
from uuid import UUID | ||
|
||
from models import get_supabase_client | ||
from utils import build_secret_unique_name | ||
|
||
|
||
def delete_secret(user_id: UUID, brain_id: UUID, secret_name: str) -> bool: | ||
supabase_client = get_supabase_client() | ||
response = supabase_client.rpc( | ||
"delete_secret", | ||
{ | ||
"name": build_secret_unique_name( | ||
user_id=user_id, brain_id=brain_id, secret_name=secret_name | ||
), | ||
}, | ||
).execute() | ||
|
||
return response.data |
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,20 @@ | ||
from uuid import UUID | ||
|
||
from models import get_supabase_client | ||
from utils import build_secret_unique_name | ||
|
||
|
||
def read_secret( | ||
user_id: UUID, brain_id: UUID, secret_name: str, secret_value | ||
) -> UUID | None: | ||
supabase_client = get_supabase_client() | ||
response = supabase_client.rpc( | ||
"read_secret", | ||
{ | ||
"secret_name": build_secret_unique_name( | ||
user_id=user_id, brain_id=brain_id, secret_name=secret_name | ||
), | ||
}, | ||
).execute() | ||
|
||
return response.data |
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 @@ | ||
from uuid import UUID | ||
|
||
|
||
def build_secret_unique_name(user_id: UUID, brain_id: UUID, secret_name: str): | ||
return f"{user_id}-{brain_id}-{secret_name}" |