Skip to content

Commit

Permalink
added local_path shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
krokicki committed Oct 24, 2024
1 parent dfd590f commit 34c30d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions x2s3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from x2s3.utils import *
from x2s3 import registry
from x2s3.settings import get_settings
from x2s3.settings import get_settings, Target

def create_app(settings):

Expand Down Expand Up @@ -58,8 +58,20 @@ async def startup_event():
for proto in registry.available_protocols():
logger.trace(f"- {proto}")

# Configure targets
app.clients = {}

# Add local path client if configured
if app.settings.local_path:
local_target = Target(
name=app.settings.local_name,
client='file',
options={
'path': str(app.settings.local_path),
}
)
app.settings.targets += [local_target]

# Configure targets
for target_name in app.settings.get_target_map():
target_key = target_name.lower()
target_config = app.settings.get_target_config(target_key)
Expand Down
3 changes: 3 additions & 0 deletions x2s3/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Dict, Optional
from functools import cache

from pathlib import Path
from pydantic import HttpUrl, BaseModel
from pydantic_settings import (
BaseSettings,
Expand All @@ -27,6 +28,8 @@ class Settings(BaseSettings):
ui: bool = True
virtual_buckets: bool = False
base_url: Optional[HttpUrl] = None
local_path: Path = None
local_name: str = 'local'
targets: List[Target] = []
target_map: Dict[str, Target] = {}

Expand Down

0 comments on commit 34c30d7

Please sign in to comment.