Skip to content

Commit

Permalink
Merge pull request #119 from natefoo/multi-tusd
Browse files Browse the repository at this point in the history
Support running multiple tusds and controlling the value of hooks-http
  • Loading branch information
natefoo authored Feb 6, 2024
2 parents c8874f4 + 97edefd commit 0edec49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion gravity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class TusdSettings(BaseModel):
upload_dir: str = Field(description="""
Directory to store uploads in.
Must match ``tus_upload_store`` setting in ``galaxy:`` section.
""")
hooks_http: str = Field(default="/api/upload/hooks", description="""
Value of tusd -hooks-httpd option
the default of is suitable for using tusd for Galaxy uploads and should not be changed unless you are using tusd for
other purposes such as Pulsar staging.
The value of galaxy_infrastructure_url is automatically prepended if the option starts with a `/`
""")
hooks_enabled_events: str = Field(default="pre-create", description="""
Comma-separated string of enabled tusd hooks.
Expand Down Expand Up @@ -377,7 +385,7 @@ class Settings(BaseSettings):
gx_it_proxy: GxItProxySettings = Field(default={}, description="Configuration for gx-it-proxy.")
# The default value for tusd is a little awkward, but is a convenient way to ensure that if
# a user enables tusd that they most also set upload_dir, and yet have the default be valid.
tusd: TusdSettings = Field(default={'upload_dir': ''}, description="""
tusd: Union[List[TusdSettings], TusdSettings] = Field(default={'upload_dir': ''}, description="""
Configuration for tusd server (https://github.com/tus/tusd).
The ``tusd`` binary must be installed manually and made available on PATH (e.g in galaxy's .venv/bin directory).
""")
Expand Down
9 changes: 6 additions & 3 deletions gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,20 @@ def _validate_settings(cls, v, values):
class GalaxyTUSDService(Service):
_service_type = "tusd"
service_name = "tusd"
_service_list_allowed = True
_graceful_method = GracefulMethod.NONE
_command_template = "{settings[tusd_path]} -host={settings[host]} -port={settings[port]}" \
" -upload-dir={settings[upload_dir]}" \
" -hooks-http={app_config[galaxy_infrastructure_url]}/api/upload/hooks" \
" -hooks-http={settings[hooks_http]}" \
" -hooks-http-forward-headers=X-Api-Key,Cookie {settings[extra_args]}" \
" -hooks-enabled-events {settings[hooks_enabled_events]}"

@validator("settings")
def _validate_settings(cls, v, values):
if not values["config"].app_config["galaxy_infrastructure_url"]:
gravity.io.exception("To run tusd syou need to set galaxy_infrastructure_url in the galaxy section of galaxy.yml")
if v["hooks_http"].startswith("/"):
if not values["config"].app_config["galaxy_infrastructure_url"]:
gravity.io.exception("To run tusd you need to set galaxy_infrastructure_url in the galaxy section of galaxy.yml")
v["hooks_http"] = f'{values["config"].app_config["galaxy_infrastructure_url"]}{v["hooks_http"]}'
return v


Expand Down

0 comments on commit 0edec49

Please sign in to comment.