Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/fastapi_cloud_cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...")
Expand Down
95 changes: 0 additions & 95 deletions tests/test_cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down