Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass in ENV to workstation #3

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cloud-workstation"
version = "0.1.3"
version = "0.1.4"
requires-python = ">=3.8"
readme = "README.md"
description = ""
Expand Down
11 changes: 11 additions & 0 deletions src/workstation/cli/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def common_options(func): # noqa: D103
type=str,
metavar="<str>",
)
@click.option(
"--envs",
"-e",
"envs",
damienrj marked this conversation as resolved.
Show resolved Hide resolved
type=(str, str),
multiple=True,
help="Environment variables to set at runtime.",
metavar="<key value>",
)
@click.pass_context
def create(
context: click.Context,
Expand All @@ -190,6 +199,7 @@ def create(
project: Optional[str],
proxy: Optional[str],
no_proxy: Optional[str],
envs: tuple,
damienrj marked this conversation as resolved.
Show resolved Hide resolved
**kwargs,
):
"""Create a workstation."""
Expand Down Expand Up @@ -227,6 +237,7 @@ def create(
location=location,
proxy=proxy,
no_proxy=no_proxy,
envs=envs,
)

config_manager.write_ssh_config(
Expand Down
11 changes: 10 additions & 1 deletion src/workstation/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple

from google.api_core.exceptions import AlreadyExists
from google.api_core.operation import Operation
Expand Down Expand Up @@ -107,6 +107,7 @@ def create_workstation(
user: str,
proxy: Optional[str] = None,
no_proxy: Optional[str] = None,
envs: Optional[Tuple] = None,
damienrj marked this conversation as resolved.
Show resolved Hide resolved
) -> Workstation:
"""
Create a new workstation with the specified configuration.
Expand Down Expand Up @@ -151,6 +152,14 @@ def create_workstation(
env["no_proxy"] = no_proxy
env["NO_PROXY"] = no_proxy

if envs:
user_envs = dict(envs)
# ensure that no duplicate keys are added to env
for key, value in user_envs.items():
if key not in env:
env[key] = value
damienrj marked this conversation as resolved.
Show resolved Hide resolved


request = workstations_v1beta.CreateWorkstationRequest(
parent=f"projects/{project}/locations/{location}/workstationClusters/{cluster}/workstationConfigs/{config}",
workstation_id=name,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
from click.testing import CliRunner

from workstation.cli import crud


Expand Down Expand Up @@ -119,3 +118,6 @@ def test_list(mock_get_gcloud_config, mock_check_gcloud_auth, mock_list_workstat
"]\n"
)
assert result.output == expected_json_output



Loading