Skip to content

Commit

Permalink
Merge pull request #100 from natefoo/path-based-gxit-1.0
Browse files Browse the repository at this point in the history
[1.x] Added configuration of gx-it-proxy to support path-based proxying
  • Loading branch information
natefoo authored Mar 13, 2023
2 parents 85515cb + 6e23421 commit 24ce6ac
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
matrix:
python-version: ['3.7', '3.10']
galaxy-branch: ['release_22.01', 'dev']
exclude:
# this results in lengthy and expensive numpy wheel builds
- python-version: '3.10'
galaxy-branch: 'release_22.01'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
Expand Down
9 changes: 8 additions & 1 deletion gravity/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
if "XDG_CONFIG_HOME" in os.environ:
DEFAULT_STATE_DIR = os.path.join(os.environ["XDG_CONFIG_HOME"], "galaxy-gravity")

OPTIONAL_APP_KEYS = (
"interactivetools_map",
"interactivetools_base_path",
"interactivetools_prefix",
"galaxy_url_prefix",
)


@contextlib.contextmanager
def config_manager(config_file=None, state_dir=None):
Expand Down Expand Up @@ -158,7 +165,7 @@ def __load_config(self, gravity_config_dict, app_config):
}

# some things should only be included if set
for app_key in ("interactivetools_map", "galaxy_url_prefix"):
for app_key in OPTIONAL_APP_KEYS:
if app_key in app_config:
app_config_dict[app_key] = app_config[app_key]

Expand Down
8 changes: 7 additions & 1 deletion gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,22 @@ class GalaxyGxItProxyService(Service):
"forward_ip": "--forwardIP {settings[forward_ip]}",
"forward_port": "--forwardPort {settings[forward_port]}",
"reverse_proxy": "--reverseProxy",
"proxy_path_prefix": "--proxyPathPrefix {settings[proxy_path_prefix]}",
}
_command_template = "{virtualenv_bin}npx gx-it-proxy --ip {settings[ip]} --port {settings[port]}" \
" --sessions {settings[sessions]} {command_arguments[verbose]}" \
" {command_arguments[forward_ip]} {command_arguments[forward_port]}" \
" {command_arguments[reverse_proxy]}"
" {command_arguments[reverse_proxy]} {command_arguments[proxy_path_prefix]}"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# override from Galaxy config if set
self.settings["sessions"] = self.config.app_config.get("interactivetools_map", self.settings["sessions"])
# this can only be set in Galaxy config
it_base_path = self.config.app_config.get("interactivetools_base_path", "/")
it_base_path = "/" + f"/{it_base_path.strip('/')}/".lstrip("/")
it_prefix = self.config.app_config.get("interactivetools_prefix", "interactivetool")
self.settings["proxy_path_prefix"] = f"{it_base_path}{it_prefix}/access/interactivetoolentrypoint"

@validator("settings")
def _validate_settings(cls, v, values):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ line-length = 160

[tool.pytest.ini_options]
norecursedirs = "tests/galaxy.git/* tests/galaxy_venv"
timeout = 300
19 changes: 18 additions & 1 deletion tests/test_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,24 @@ def test_gxit_handler(default_config_manager, galaxy_yml, gxit_config, process_m
assert gxit_config_path.exists()
gxit_port = gxit_config["gravity"]["gx_it_proxy"]["port"]
sessions = "database/interactivetools_map.sqlite"
assert f'npx gx-it-proxy --ip localhost --port {gxit_port} --sessions {sessions}' in gxit_config_path.read_text()
gxit_config_contents = gxit_config_path.read_text()
assert f'npx gx-it-proxy --ip localhost --port {gxit_port} --sessions {sessions}' in gxit_config_contents
assert '--proxyPathPrefix /interactivetool/access/interactivetoolentrypoint' in gxit_config_contents


@pytest.mark.parametrize('process_manager_name', ['supervisor', 'systemd'])
def test_gxit_handler_path_prefix(default_config_manager, galaxy_yml, gxit_config, process_manager_name):
state_dir = default_config_manager.state_dir
gxit_base_path = gxit_config["galaxy"]["interactivetools_base_path"] = "/foo/"
gxit_prefix = gxit_config["galaxy"]["interactivetools_prefix"] = "bar"
galaxy_yml.write(json.dumps(gxit_config))
default_config_manager.load_config_file(str(galaxy_yml))
with process_manager.process_manager(config_manager=default_config_manager) as pm:
pm.update()
gxit_config_path = service_conf_path(state_dir, process_manager_name, 'gx-it-proxy')
assert gxit_config_path.exists()
proxy_path_prefix = f'{gxit_base_path}{gxit_prefix}/access/interactivetoolentrypoint'
assert f'--proxyPathPrefix {proxy_path_prefix}' in gxit_config_path.read_text()


@pytest.mark.parametrize('process_manager_name', ['supervisor', 'systemd'])
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ commands =
deps =
lint: flake8
test: pytest
test: pytest-timeout
test: coverage
test: requests
passenv =
Expand Down

0 comments on commit 24ce6ac

Please sign in to comment.