From 97edefd445f9cdd141e43d655eb47bbec5173a27 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 5 Feb 2024 14:51:17 -0500 Subject: [PATCH] Support running multiple tusds and controlling the value of hooks-http --- gravity/settings.py | 10 +++++++++- gravity/state.py | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gravity/settings.py b/gravity/settings.py index eeab02f..618a3bf 100644 --- a/gravity/settings.py +++ b/gravity/settings.py @@ -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. @@ -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). """) diff --git a/gravity/state.py b/gravity/state.py index 80765d3..b71183a 100644 --- a/gravity/state.py +++ b/gravity/state.py @@ -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