-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: serverless function
get_user_tasks
init
- Loading branch information
Showing
4 changed files
with
270 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,64 @@ | ||
name: Deploy Serverless Function | ||
|
||
on: | ||
push: | ||
branches: | ||
- chore/serverless-function | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
|
||
|
||
steps: | ||
- uses: "actions/checkout@v4" | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install and configure Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: 1.5.1 | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: Export requirements.txt from Poetry | ||
run: poetry export --without-hashes --format=requirements.txt > requirements.txt | ||
|
||
- id: 'auth' | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
workload_identity_provider: ${{ secrets.GOOGLE_WIP }} | ||
service_account: ${{ secrets.GOOGLE_SA }} | ||
|
||
- name: "Set up Cloud SDK" | ||
uses: "google-github-actions/setup-gcloud@v1" | ||
with: | ||
version: ">= 474.0.0" | ||
|
||
- name: "Use gcloud CLI" | ||
run: "gcloud info" | ||
|
||
- name: "Deploy get_user_tasks function" | ||
run: | | ||
gcloud functions deploy get_user_tasks \ | ||
--project=autotx-423210 \ | ||
--gen2 \ | ||
--source=autotx/serverless_functions/get_user_tasks.py | ||
--runtime=python310 \ | ||
--region=us-central1 \ | ||
--trigger-http \ | ||
--allow-unauthenticated \ | ||
--entry-point=get_user_tasks \ | ||
--set-env-vars SUPABASE_URL="${{ secrets.DEV_SUPABASE_URL }}",SUPABASE_SERVICE_ROLE_KEY="${{ secrets.DEV_SUPABASE_SERVICE_ROLE_KEY }} |
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,42 @@ | ||
from fastapi import HTTPException | ||
from flask import Request | ||
from flask.typing import ResponseReturnValue | ||
import functions_framework | ||
from autotx import db | ||
from autotx.server import authorize_app_and_user | ||
|
||
|
||
@functions_framework.http | ||
def get_user_tasks(request: Request) -> ResponseReturnValue: | ||
if request.method != "GET": | ||
return "Method not allowed" | ||
|
||
try: | ||
(app, app_user) = authorize_app_and_user( | ||
request.authorization, request.args["userDid"] | ||
) | ||
tasks = db.TasksRepository(app_id=app.id).get_from_user(app_user.id) | ||
user_tasks = [ | ||
{ | ||
"id": task.id, | ||
"prompt": task.prompt, | ||
"address": task.address, | ||
"chain_id": task.chain_id, | ||
"intents": task.intents, | ||
} | ||
for task in tasks | ||
] | ||
user_submitted_transactions = [ | ||
batch | ||
for batch in db.get_submitted_transactions_from_user(app.id, app_user.id) | ||
] | ||
|
||
return { | ||
"tasks": user_tasks, | ||
"submitted_transactions": user_submitted_transactions, | ||
} | ||
except HTTPException as e: | ||
return {"status": e.status_code, "message": e.detail} | ||
except Exception as e: | ||
print(e) | ||
return {"status": 500, "message": "Internal error"} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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