diff --git a/src/fastapi_cloud_cli/commands/deploy.py b/src/fastapi_cloud_cli/commands/deploy.py index 22019c2..244e867 100644 --- a/src/fastapi_cloud_cli/commands/deploy.py +++ b/src/fastapi_cloud_cli/commands/deploy.py @@ -25,7 +25,6 @@ from fastapi_cloud_cli.utils.apps import AppConfig, get_app_config, write_app_config from fastapi_cloud_cli.utils.auth import is_logged_in from fastapi_cloud_cli.utils.cli import get_rich_toolkit, handle_http_errors -from fastapi_cloud_cli.utils.env import validate_environment_variable_name logger = logging.getLogger(__name__) @@ -229,12 +228,6 @@ def _get_apps(team_id: str) -> List[AppResponse]: return [AppResponse.model_validate(app) for app in data] -def _create_environment_variables(app_id: str, env_vars: Dict[str, str]) -> None: - with APIClient() as client: - response = client.patch(f"/apps/{app_id}/environment-variables/", json=env_vars) - response.raise_for_status() - - def _stream_build_logs(deployment_id: str) -> Generator[str, None, None]: with APIClient() as client: with client.stream( @@ -399,45 +392,6 @@ def _wait_for_deployment( last_message_changed_at = time.monotonic() # pragma: no cover -def _setup_environment_variables(toolkit: RichToolkit, app_id: str) -> None: - if not toolkit.confirm("Do you want to setup environment variables?", tag="env"): - return - - toolkit.print_line() - - env_vars = {} - - while True: - key = toolkit.input( - "Enter the environment variable name: [ENTER to skip]", required=False - ) - - if key.strip() == "": - break - - if not validate_environment_variable_name(key): - toolkit.print( - "[error]Invalid environment variable name.", - ) - - else: - value = toolkit.input( - "Enter the environment variable value:", password=True - ) - - env_vars[key] = value - - toolkit.print_line() - - toolkit.print_line() - - with toolkit.progress("Setting up environment variables...") as progress: - with handle_http_errors(progress): - _create_environment_variables(app_id, env_vars) - - progress.log("Environment variables set up successfully!") - - class SignupToWaitingList(BaseModel): email: EmailStr name: Optional[str] = None @@ -605,9 +559,6 @@ def deploy( logger.debug("No app config found, configuring new app") app_config = _configure_app(toolkit, path_to_deploy=path_to_deploy) toolkit.print_line() - - _setup_environment_variables(toolkit, app_config.app_id) - toolkit.print_line() else: logger.debug("Existing app config found, proceeding with deployment") toolkit.print("Deploying app...") diff --git a/tests/test_cli_deploy.py b/tests/test_cli_deploy.py index 712a011..d1d6ad8 100644 --- a/tests/test_cli_deploy.py +++ b/tests/test_cli_deploy.py @@ -386,8 +386,6 @@ def test_exits_successfully_when_deployment_is_done( Keys.ENTER, *"demo", Keys.ENTER, - Keys.RIGHT_ARROW, - Keys.ENTER, ] team_data = _get_random_team() @@ -642,8 +640,6 @@ def _deploy_without_waiting(respx_mock: respx.MockRouter, tmp_path: Path) -> Res Keys.ENTER, *"demo", Keys.ENTER, - Keys.RIGHT_ARROW, - Keys.ENTER, ] team_data = _get_random_team() @@ -730,97 +726,6 @@ def test_does_not_duplicate_entry_in_git_ignore( assert git_ignore_path.read_text() == ".fastapicloud\n" -@pytest.mark.respx(base_url=settings.base_api_url) -def test_creates_environment_variables_during_app_setup( - logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter -) -> None: - steps = [ - Keys.ENTER, # Setup and deploy - Keys.ENTER, # Select team - Keys.ENTER, # Create new app - *"demo", # App name - Keys.ENTER, - Keys.ENTER, # Setup environment variables (Yes) - *"API_KEY", # Environment variable name - Keys.ENTER, - *"secret123", # Environment variable value - Keys.ENTER, - Keys.ENTER, # Empty key to finish - Keys.CTRL_C, # Exit before deployment - ] - - team = _get_random_team() - app_data = _get_random_app(team_id=team["id"]) - - respx_mock.get("/teams/").mock(return_value=Response(200, json={"data": [team]})) - - respx_mock.post("/apps/", json={"name": "demo", "team_id": team["id"]}).mock( - return_value=Response(201, json=app_data) - ) - - env_vars_request = respx_mock.patch( - f"/apps/{app_data['id']}/environment-variables/", json={"API_KEY": "secret123"} - ).mock(return_value=Response(200)) - - with changing_dir(tmp_path), patch( - "rich_toolkit.container.getchar" - ) as mock_getchar: - mock_getchar.side_effect = steps - - result = runner.invoke(app, ["deploy"]) - - assert result.exit_code == 1 - assert env_vars_request.called - assert "Environment variables set up successfully!" in result.output - - -@pytest.mark.respx(base_url=settings.base_api_url) -def test_rejects_invalid_environment_variable_names( - logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter -) -> None: - steps = [ - Keys.ENTER, # Setup and deploy - Keys.ENTER, # Select team - Keys.ENTER, # Create new app - *"demo", # App name - Keys.ENTER, - Keys.ENTER, # Setup environment variables (Yes) - *"123-invalid", # Invalid environment variable name (starts with digit, contains hyphen) - Keys.ENTER, - *"VALID_KEY", # Valid environment variable name - Keys.ENTER, - *"value123", # Environment variable value - Keys.ENTER, - Keys.ENTER, # Empty key to finish - Keys.CTRL_C, # Exit before deployment - ] - - team = _get_random_team() - app_data = _get_random_app(team_id=team["id"]) - - respx_mock.get("/teams/").mock(return_value=Response(200, json={"data": [team]})) - - respx_mock.post("/apps/", json={"name": "demo", "team_id": team["id"]}).mock( - return_value=Response(201, json=app_data) - ) - - env_vars_request = respx_mock.patch( - f"/apps/{app_data['id']}/environment-variables/", json={"VALID_KEY": "value123"} - ).mock(return_value=Response(200)) - - with changing_dir(tmp_path), patch( - "rich_toolkit.container.getchar" - ) as mock_getchar: - mock_getchar.side_effect = steps - - result = runner.invoke(app, ["deploy"]) - - assert result.exit_code == 1 - assert env_vars_request.called - assert "Invalid environment variable name." in result.output - assert "Environment variables set up successfully!" in result.output - - @pytest.mark.respx(base_url=settings.base_api_url) def test_shows_error_for_invalid_waitlist_form_data( logged_out_cli: None, tmp_path: Path, respx_mock: respx.MockRouter