Skip to content

Commit a2ea548

Browse files
committed
misc: pass enable_ssh to EnvironmentConfig
Also add these arguments to `start` and `restart` commands
1 parent 6d33fc5 commit a2ea548

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

composer_local_dev/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,24 @@ def create(
387387
@cli.command()
388388
@optional_environment
389389
@option_port
390+
@option_enable_ssh
391+
@option_ssh_port
390392
@verbose_mode
391393
@debug_mode
392394
@errors.catch_exceptions()
393395
def start(
394396
environment: Optional[str],
395397
web_server_port: Optional[int],
398+
enable_ssh: Optional[bool],
399+
ssh_port: Optional[int],
396400
verbose: bool,
397401
debug: bool,
398402
):
399403
"""Start Composer environment."""
400404
utils.setup_logging(verbose, debug)
401405
env_path = files.resolve_environment_path(environment)
402406
env = composer_environment.Environment.load_from_config(
403-
env_path, web_server_port
407+
env_path, web_server_port,enable_ssh,ssh_port
404408
)
405409
console.get_console().print(f"Starting {env.name} composer environment...")
406410
env.start()
@@ -427,12 +431,16 @@ def stop(environment: Optional[str], verbose: bool, debug: bool):
427431
@cli.command()
428432
@optional_environment
429433
@option_port
434+
@option_enable_ssh
435+
@option_ssh_port
430436
@verbose_mode
431437
@debug_mode
432438
@errors.catch_exceptions()
433439
def restart(
434440
environment: Optional[str],
435441
web_server_port: Optional[int],
442+
enable_ssh: Optional[bool],
443+
ssh_port: Optional[int],
436444
verbose: bool,
437445
debug: bool,
438446
):
@@ -445,7 +453,7 @@ def restart(
445453
utils.setup_logging(verbose, debug)
446454
env_path = files.resolve_environment_path(environment)
447455
env = composer_environment.Environment.load_from_config(
448-
env_path, web_server_port
456+
env_path, web_server_port,enable_ssh,ssh_port
449457
)
450458
env.restart()
451459

composer_local_dev/environment.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def __init__(
362362
self,
363363
env_dir_path: pathlib.Path,
364364
port: Optional[int],
365+
enable_ssh: Optional[bool] = None,
365366
ssh_port: Optional[int] = None,
366367
):
367368
self.env_dir_path = env_dir_path
@@ -390,7 +391,11 @@ def __init__(
390391

391392
# Backwards compatibility: don't fail on missing enable_ssh
392393
if "enable_ssh" in self.config:
393-
self.enable_ssh = self.get_str_param("enable_ssh")
394+
self.enable_ssh = (
395+
enable_ssh
396+
if enable_ssh is not None
397+
else self.get_str_param("enable_ssh")
398+
)
394399
self.ssh_port = (
395400
ssh_port
396401
if ssh_port is not None
@@ -574,10 +579,11 @@ def load_from_config(
574579
cls,
575580
env_dir_path: pathlib.Path,
576581
port: Optional[int],
582+
enable_ssh: Optional[bool] = None,
577583
ssh_port: Optional[int] = None,
578584
):
579585
"""Create local environment using 'config.json' configuration file."""
580-
config = EnvironmentConfig(env_dir_path, port, ssh_port)
586+
config = EnvironmentConfig(env_dir_path, port, enable_ssh, ssh_port)
581587
environment_vars = load_environment_variables(env_dir_path)
582588
Environment.assert_valid_environment_configuration(
583589
config, environment_vars

tests/unit/test_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ def mocked_resolve_env(self, env_path):
182182
) as mock_check:
183183
yield mock_check
184184

185-
def assert_env_loaded(self, mocked_env, env_path, port=None):
186-
mocked_env.load_from_config.assert_called_with(env_path, port)
185+
def assert_env_loaded(self, mocked_env, env_path, port=None, enable_ssh=False, ssh_port=None):
186+
mocked_env.load_from_config.assert_called_with(env_path, port, enable_ssh, ssh_port)
187187

188-
def assert_run_command(self, command, mocked_env, env_path, port=None):
188+
def assert_run_command(self, command, mocked_env, env_path, port=None, enable_ssh=False, ssh_port=None):
189189
run_composer_and_assert_exit_code(
190190
command,
191191
exit_code=0,
192192
)
193-
self.assert_env_loaded(mocked_env, env_path, port)
193+
self.assert_env_loaded(mocked_env, env_path, port, enable_ssh, ssh_port)
194194

195195
@pytest.mark.parametrize("command", ["start", "restart"])
196196
def test_start_command(

0 commit comments

Comments
 (0)