Skip to content

Commit

Permalink
Fix CI/CD (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Jun 15, 2024
1 parent f5a9b43 commit 08acfca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions .cspell.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ecies",
"eciespy",
"fastapi",
"pydantic",
"secp256k1",
"Spacefile",
"uvicorn",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
with:
access_token: ${{ secrets.ACCESS_TOKEN }}
project_id: ${{ secrets.PROJECT_ID }}
space_release: true
space_push: true
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ jobs:
cache: "poetry"

- run: poetry export -f requirements.txt -o requirements.txt --without=dev
- run: poetry install --only main

- uses: neobrains/space-pipe@v0.5
with:
access_token: ${{ secrets.ACCESS_TOKEN }}
project_id: ${{ secrets.PROJECT_ID }}
space_push: true
- run: poetry install
25 changes: 17 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from typing import Optional

from ecies import decrypt, encrypt
from fastapi import FastAPI, Form, HTTPException
from fastapi.responses import Response
from fastapi import FastAPI, Form, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel

app = FastAPI()


def resp_string(msg):
return Response(content=msg, media_type="plain/text")
class Error(BaseModel):
detail: str


@app.post("/")
@app.post("/", responses={400: {"model": Error}})
async def encrypt_decrypt(
prv: Optional[str] = Form(None),
pub: Optional[str] = Form(None),
Expand All @@ -22,12 +23,20 @@ async def encrypt_decrypt(
decrypted = decrypt(prv, bytes.fromhex(data))
return resp_string(decrypted)
except ValueError:
raise HTTPException(status_code=400, detail="Invalid private key")
return resp_error("Invalid private key or data")
elif pub and data:
try:
encrypted = encrypt(pub, data.encode())
return resp_string(encrypted.hex())
except ValueError:
raise HTTPException(status_code=400, detail="Invalid public key")
return resp_error("Invalid public key or data")
else:
raise HTTPException(status_code=400, detail="Invalid request")
return resp_error("Invalid request")


def resp_string(msg):
return Response(content=msg, media_type="plain/text")


def resp_error(msg):
return JSONResponse(content={"detail": msg}, status_code=400)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ authors = ["Weiliang Li <to.be.impressive@gmail.com>"]
description = ""
license = "MIT"
name = "eciespy-demo"
package-mode = false
version = "0.1.0"

[tool.poetry.dependencies]
Expand Down

0 comments on commit 08acfca

Please sign in to comment.