Skip to content

Commit

Permalink
added swiftclient to the start event
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-crkn committed Nov 7, 2024
1 parent f5bc5d7 commit 06100f4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions Azure_auth/jwt_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# load .env file
load_dotenv()
jwt_secret = os.getenv("EDITOR_SECRET_KEY")

#define a HTTPBearer to handle the token from client
client_token_scheme = HTTPBearer()
# JWT authentication function
Expand Down
4 changes: 1 addition & 3 deletions utils/get_manifest_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
logging.basicConfig(level=logging.INFO,handlers=[logging.StreamHandler()])
logger = logging.getLogger(__name__)

# Connect to Swift
conn = get_swift_connection()

async def get_manifest_conn(slug:str,request: Request):
"""
Retrieve file content from the specified Swift container by filename, and format JSON data.
Expand All @@ -34,6 +31,7 @@ async def get_manifest_conn(slug:str,request: Request):
try:
#Access Swift and Redis objects from the app's state
redis = request.app.state.redis
conn = request.app.state.conn
manifest_name = f'{slug}/manifest.json'
#Check Redis cache,if exists return from redis
if (cached_profile := await redis.get(f"manifest_{slug}")) is not None:
Expand Down
3 changes: 3 additions & 0 deletions utils/lifespan_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import redis.asyncio as aioredis
from fastapi import HTTPException
from swift_config.swift_config import get_swift_connection

#config logger
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -54,6 +55,8 @@ async def lifespan(app) -> AsyncGenerator[None,None]:
decode_responses=False

)
conn = get_swift_connection()
app.state.conn = conn

yield
except Exception as e:
Expand Down
5 changes: 1 addition & 4 deletions utils/upload_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
logging.basicConfig(level=logging.INFO,handlers=[logging.StreamHandler()])
logger = logging.getLogger(__name__)

# Connect to Swift
conn = get_swift_connection()

# Create an async context manager for acquiring and releasing a Redis lock
@asynccontextmanager
async def acquire_lock(redis_client: Redis, key: str, timeout: int = 30):
Expand All @@ -47,6 +44,7 @@ async def upload_manifest_backend(
swift_storage_url = request.app.state.swift_storage_url
"""
redis = request.app.state.redis
conn = request.app.state.conn


"""
Expand Down Expand Up @@ -131,7 +129,6 @@ async def upload_manifest_backend(
canvas_item['items'][0]['items'][0]['id'] = annotation_id
new_manifest_items.append(canvas_item)
#updated_canvas_content = json.dumps(canvas_item)

# Upload manifest to Swift
manifest['items'] = new_manifest_items
updated_manifest = json.dumps(manifest)
Expand Down

0 comments on commit 06100f4

Please sign in to comment.