fix(chalice): fixed spot refresh logic for EE (#2595)

This commit is contained in:
Kraiem Taha Yassine 2024-09-17 20:03:44 +02:00 committed by GitHub
parent c56a2c2d25
commit 018bf9c0be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

1
ee/api/.gitignore vendored
View file

@ -273,7 +273,6 @@ Pipfile.lock
/chalicelib/core/usability_testing/
/NOTES.md
/chalicelib/core/db_request_handler.py
/routers/subs/spot.py
/chalicelib/utils/or_cache/
/routers/subs/health.py
/chalicelib/core/spot.py

View file

@ -95,7 +95,6 @@ rm -rf ./orpy.py
rm -rf ./chalicelib/core/usability_testing/
rm -rf ./chalicelib/core/db_request_handler.py
rm -rf ./chalicelib/core/db_request_handler.py
rm -rf ./routers/subs/spot.py
rm -rf ./chalicelib/utils/or_cache
rm -rf ./routers/subs/health.py
rm -rf ./chalicelib/core/spot.py

View file

@ -0,0 +1,32 @@
from fastapi import Depends
from starlette.responses import JSONResponse, Response
import schemas
from chalicelib.core import spot, webhook
from or_dependencies import OR_context
from routers.base import get_routers
public_app, app, app_apikey = get_routers(prefix="/spot", tags=["spot"])
COOKIE_PATH = "/api/spot/refresh"
@app.get('/logout')
def logout_spot(response: Response, context: schemas.CurrentContext = Depends(OR_context)):
spot.logout(user_id=context.user_id)
response.delete_cookie(key="spotRefreshToken", path=COOKIE_PATH)
return {"data": "success"}
@app.get('/refresh')
def refresh_spot_login(response: JSONResponse, context: schemas.CurrentContext = Depends(OR_context)):
r = spot.refresh(user_id=context.user_id, tenant_id=context.tenant_id)
content = {"jwt": r.get("jwt")}
response.set_cookie(key="spotRefreshToken", value=r.get("refreshToken"), path=COOKIE_PATH,
max_age=r.pop("refreshTokenMaxAge"), secure=True, httponly=True)
return content
@app.get('/integrations/slack/channels', tags=["integrations"])
def get_slack_channels(context: schemas.CurrentContext = Depends(OR_context)):
return {"data": webhook.get_by_type(tenant_id=context.tenant_id, webhook_type=schemas.WebhookType.SLACK)}