Skip to content

Commit 1025017

Browse files
authored
Merge pull request #254 from jumpstarter-dev/client-config-alias
Rename ClientConfig.name to ClientConfig.alias
2 parents 18994d0 + 44176de commit 1025017

File tree

11 files changed

+48
-48
lines changed

11 files changed

+48
-48
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ build:
4343

4444
clean: clean-docs clean-venv clean-build clean-test
4545

46-
.PHONY: sync docs test test-jumpstarter test-packages build clean-test clean-docs clean-venv clean-build
46+
.PHONY: sync docs test test-packages build clean-test clean-docs clean-venv clean-build

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
)
3939

4040
UNSAFE_CLIENT_CONFIG = ClientConfigV1Alpha1(
41-
name=CLIENT_NAME,
41+
alias=CLIENT_NAME,
4242
metadata=ObjectMeta(namespace="default", name=CLIENT_NAME),
4343
endpoint=CLIENT_ENDPOINT,
4444
token=CLIENT_TOKEN,
4545
drivers=ClientConfigV1Alpha1Drivers(allow=[], unsafe=True),
4646
)
4747

4848
CLIENT_CONFIG = ClientConfigV1Alpha1(
49-
name=CLIENT_NAME,
49+
alias=CLIENT_NAME,
5050
metadata=ObjectMeta(namespace="default", name=CLIENT_NAME),
5151
endpoint=CLIENT_ENDPOINT,
5252
token=CLIENT_TOKEN,

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def delete_client(
5454
if ClientConfigV1Alpha1.exists(name) and (delete or click.confirm("Delete client configuration?")):
5555
# If this is the default, clear default
5656
user_config = UserConfigV1Alpha1.load_or_create()
57-
if user_config.config.current_client is not None and user_config.config.current_client.name == name:
57+
if user_config.config.current_client is not None and user_config.config.current_client.alias == name:
5858
user_config.config.current_client = None
5959
UserConfigV1Alpha1.save(user_config)
6060
# Delete the client config

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/delete_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
CLIENT_TOKEN = "dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz"
3030

3131
CLIENT_CONFIG = ClientConfigV1Alpha1(
32-
name=CLIENT_NAME,
32+
alias=CLIENT_NAME,
3333
metadata=ObjectMeta(namespace="default", name=CLIENT_NAME),
3434
endpoint=CLIENT_ENDPOINT,
3535
token=CLIENT_TOKEN,

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/import_res_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
DRIVER_NAME = "jumpstarter.Testing"
2424
# Create a test client config
2525
UNSAFE_CLIENT_CONFIG = ClientConfigV1Alpha1(
26-
name=CLIENT_NAME,
26+
alias=CLIENT_NAME,
2727
metadata=ObjectMeta(namespace="default", name=CLIENT_NAME),
2828
endpoint=CLIENT_ENDPOINT,
2929
token=CLIENT_TOKEN,
3030
drivers=ClientConfigV1Alpha1Drivers(allow=[], unsafe=True),
3131
)
3232
CLIENT_CONFIG = ClientConfigV1Alpha1(
33-
name=CLIENT_NAME,
33+
alias=CLIENT_NAME,
3434
metadata=ObjectMeta(namespace="default", name=CLIENT_NAME),
3535
endpoint=CLIENT_ENDPOINT,
3636
token=CLIENT_TOKEN,

packages/jumpstarter-cli-client/jumpstarter_cli_client/client_config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def create_client_config(
6565
raise click.ClickException(f"A client with the name '{alias}' already exists.")
6666

6767
config = ClientConfigV1Alpha1(
68-
name=alias,
68+
alias=alias,
6969
metadata=ObjectMeta(namespace=namespace, name=name),
7070
endpoint=endpoint,
7171
token=token,
@@ -85,12 +85,12 @@ def set_next_client(name: str):
8585
if (
8686
user_config is not None
8787
and user_config.config.current_client is not None
88-
and user_config.config.current_client.name == name
88+
and user_config.config.current_client.alias == name
8989
):
9090
for c in ClientConfigV1Alpha1.list():
91-
if c.name != name:
91+
if c.alias != name:
9292
# Use the next available client config
93-
user_config.use_client(c.name)
93+
user_config.use_client(c.alias)
9494
return
9595
# Otherwise, set client to none
9696
user_config.use_client(None)
@@ -110,16 +110,16 @@ def list_client_configs():
110110
current_name = None
111111
if UserConfigV1Alpha1.exists():
112112
current_client = UserConfigV1Alpha1.load().config.current_client
113-
current_name = current_client.name if current_client is not None else None
113+
current_name = current_client.alias if current_client is not None else None
114114

115115
configs = ClientConfigV1Alpha1.list()
116116

117117
columns = ["CURRENT", "NAME", "ENDPOINT", "PATH"]
118118

119119
def make_row(c: ClientConfigV1Alpha1):
120120
return {
121-
"CURRENT": "*" if current_name == c.name else "",
122-
"NAME": c.name,
121+
"CURRENT": "*" if current_name == c.alias else "",
122+
"NAME": c.alias,
123123
"ENDPOINT": c.endpoint,
124124
"PATH": str(c.path),
125125
}

packages/jumpstarter-kubernetes/jumpstarter_kubernetes/clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def get_client_config(self, name: str, allow: list[str], unsafe=False) ->
104104
endpoint = client.status.endpoint
105105
token = base64.b64decode(secret.data["token"]).decode("utf8")
106106
return ClientConfigV1Alpha1(
107-
name=name,
107+
alias=name,
108108
metadata=ObjectMeta(
109109
namespace=client.metadata.namespace,
110110
name=client.metadata.name,

packages/jumpstarter/jumpstarter/config/client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ClientConfigV1Alpha1Drivers(BaseModel):
3636
class ClientConfigV1Alpha1(BaseModel):
3737
CLIENT_CONFIGS_PATH: ClassVar[Path] = CONFIG_PATH / "clients"
3838

39-
name: str = Field(default="default", exclude=True)
39+
alias: str = Field(default="default", exclude=True)
4040
path: Path | None = Field(default=None, exclude=True)
4141

4242
apiVersion: Literal["jumpstarter.dev/v1alpha1"] = Field(default="jumpstarter.dev/v1alpha1")
@@ -124,7 +124,7 @@ async def lease_async(self, metadata_filter: MetadataFilter, lease_name: str | N
124124
def from_file(cls, path: os.PathLike):
125125
with open(path) as f:
126126
v = cls.model_validate(yaml.safe_load(f))
127-
v.name = os.path.basename(path).split(".")[0]
127+
v.alias = os.path.basename(path).split(".")[0]
128128
v.path = Path(path)
129129
return v
130130

@@ -157,14 +157,14 @@ def from_env(cls):
157157
)
158158

159159
@classmethod
160-
def _get_path(cls, name: str) -> Path:
161-
"""Get the regular path of a client config given a name."""
162-
return (cls.CLIENT_CONFIGS_PATH / name).with_suffix(".yaml")
160+
def _get_path(cls, alias: str) -> Path:
161+
"""Get the regular path of a client config given an alias."""
162+
return (cls.CLIENT_CONFIGS_PATH / alias).with_suffix(".yaml")
163163

164164
@classmethod
165-
def load(cls, name: str) -> Self:
166-
"""Load a client config by name."""
167-
path = cls._get_path(name)
165+
def load(cls, alias: str) -> Self:
166+
"""Load a client config by alias."""
167+
path = cls._get_path(alias)
168168
if path.exists() is False:
169169
raise FileNotFoundError(f"Client config '{path}' does not exist.")
170170
return cls.from_file(path)
@@ -176,7 +176,7 @@ def save(cls, config: Self, path: Optional[os.PathLike] = None):
176176
if path is None:
177177
cls.ensure_exists()
178178
# Set the config path before saving
179-
config.path = cls._get_path(config.name)
179+
config.path = cls._get_path(config.alias)
180180
else:
181181
config.path = Path(path)
182182
with config.path.open(mode="w") as f:
@@ -187,9 +187,9 @@ def dump_yaml(cls, config: Self) -> str:
187187
return yaml.safe_dump(config.model_dump(mode="json"), sort_keys=False)
188188

189189
@classmethod
190-
def exists(cls, name: str) -> bool:
191-
"""Check if a client config exists by name."""
192-
return cls._get_path(name).exists()
190+
def exists(cls, alias: str) -> bool:
191+
"""Check if a client config exists by alias."""
192+
return cls._get_path(alias).exists()
193193

194194
@classmethod
195195
def list(cls) -> list[Self]:
@@ -209,9 +209,9 @@ def make_config(file: str):
209209
return list(map(make_config, files))
210210

211211
@classmethod
212-
def delete(cls, name: str):
213-
"""Delete a client config by name."""
214-
path = cls._get_path(name)
212+
def delete(cls, alias: str):
213+
"""Delete a client config by alias."""
214+
path = cls._get_path(alias)
215215
if path.exists() is False:
216216
raise FileNotFoundError(f"Client config '{path}' does not exist.")
217217
path.unlink()

packages/jumpstarter/jumpstarter/config/client_config_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_client_config_try_from_env(monkeypatch: pytest.MonkeyPatch):
2626
monkeypatch.setenv(JMP_DRIVERS_ALLOW, "jumpstarter.drivers.*,vendorpackage.*")
2727

2828
config = ClientConfigV1Alpha1.try_from_env()
29-
assert config.name == "default"
29+
assert config.alias == "default"
3030
assert config.metadata.namespace == "default"
3131
assert config.metadata.name == "testclient"
3232
assert config.token == "dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz"
@@ -48,7 +48,7 @@ def test_client_config_from_env(monkeypatch: pytest.MonkeyPatch):
4848
monkeypatch.setenv(JMP_DRIVERS_ALLOW, "jumpstarter.drivers.*,vendorpackage.*")
4949

5050
config = ClientConfigV1Alpha1.from_env()
51-
assert config.name == "default"
51+
assert config.alias == "default"
5252
assert config.metadata.namespace == "default"
5353
assert config.metadata.name == "testclient"
5454
assert config.token == "dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz"
@@ -65,7 +65,7 @@ def test_client_config_from_env_allow_unsafe(monkeypatch: pytest.MonkeyPatch):
6565
monkeypatch.setenv(JMP_DRIVERS_ALLOW, "UNSAFE")
6666

6767
config = ClientConfigV1Alpha1.from_env()
68-
assert config.name == "default"
68+
assert config.alias == "default"
6969
assert config.metadata.namespace == "default"
7070
assert config.metadata.name == "testclient"
7171
assert config.token == "dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz"
@@ -105,7 +105,7 @@ def test_client_config_from_file():
105105
f.write(CLIENT_CONFIG)
106106
f.close()
107107
config = ClientConfigV1Alpha1.from_file(f.name)
108-
assert config.name == f.name.split("/")[-1]
108+
assert config.alias == f.name.split("/")[-1]
109109
assert config.metadata.namespace == "default"
110110
assert config.metadata.name == "testclient"
111111
assert config.endpoint == "jumpstarter.my-lab.com:1443"
@@ -175,15 +175,15 @@ def test_client_config_load():
175175
ClientConfigV1Alpha1,
176176
"from_file",
177177
return_value=ClientConfigV1Alpha1(
178-
name="another",
178+
alias="another",
179179
metadata=ObjectMeta(namespace="default", name="another"),
180180
endpoint="abc",
181181
token="123",
182182
drivers=ClientConfigV1Alpha1Drivers(allow=[], unsafe=False),
183183
),
184184
) as from_file_mock:
185185
value = ClientConfigV1Alpha1.load("another")
186-
assert value.name == "another"
186+
assert value.alias == "another"
187187
get_path_mock.assert_called_once_with("another")
188188
from_file_mock.assert_called_once_with(Path(f.name))
189189
os.unlink(f.name)
@@ -212,7 +212,7 @@ def test_client_config_save(monkeypatch: pytest.MonkeyPatch):
212212
unsafe: false
213213
"""
214214
config = ClientConfigV1Alpha1(
215-
name="testclient",
215+
alias="testclient",
216216
metadata=ObjectMeta(namespace="default", name="testclient"),
217217
endpoint="jumpstarter.my-lab.com:1443",
218218
token="dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz",
@@ -247,7 +247,7 @@ def test_client_config_save_explicit_path():
247247
unsafe: false
248248
"""
249249
config = ClientConfigV1Alpha1(
250-
name="testclient",
250+
alias="testclient",
251251
metadata=ObjectMeta(namespace="default", name="testclient"),
252252
endpoint="jumpstarter.my-lab.com:1443",
253253
token="dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz",
@@ -278,7 +278,7 @@ def test_client_config_save_unsafe_drivers():
278278
unsafe: true
279279
"""
280280
config = ClientConfigV1Alpha1(
281-
name="testclient",
281+
alias="testclient",
282282
metadata=ObjectMeta(namespace="default", name="testclient"),
283283
endpoint="jumpstarter.my-lab.com:1443",
284284
token="dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz",
@@ -322,7 +322,7 @@ def test_client_config_list(monkeypatch: pytest.MonkeyPatch):
322322
monkeypatch.setattr(ClientConfigV1Alpha1, "CLIENT_CONFIGS_PATH", Path(d))
323323
configs = ClientConfigV1Alpha1.list()
324324
assert len(configs) == 1
325-
assert configs[0].name == "testclient"
325+
assert configs[0].alias == "testclient"
326326

327327

328328
def test_client_config_list_none(monkeypatch: pytest.MonkeyPatch):

packages/jumpstarter/jumpstarter/config/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def _serialize_current_client(v: ClientConfigV1Alpha1 | None) -> str | None:
1414
if v:
15-
return v.name
15+
return v.alias
1616
else:
1717
return None
1818

packages/jumpstarter/jumpstarter/config/user_config_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_user_config_load(monkeypatch: pytest.MonkeyPatch):
3232
ClientConfigV1Alpha1,
3333
"load",
3434
return_value=ClientConfigV1Alpha1(
35-
name="testclient",
35+
alias="testclient",
3636
metadata=ObjectMeta(namespace="default", name="testclient"),
3737
endpoint="abc",
3838
token="123",
@@ -45,7 +45,7 @@ def test_user_config_load(monkeypatch: pytest.MonkeyPatch):
4545
monkeypatch.setattr(UserConfigV1Alpha1, "USER_CONFIG_PATH", f.name)
4646
config = UserConfigV1Alpha1.load()
4747
mock_load.assert_called_once_with("testclient")
48-
assert config.config.current_client.name == "testclient"
48+
assert config.config.current_client.alias == "testclient"
4949
os.unlink(f.name)
5050

5151

@@ -194,7 +194,7 @@ def test_user_config_save(monkeypatch: pytest.MonkeyPatch):
194194
config = UserConfigV1Alpha1(
195195
config=UserConfigV1Alpha1Config(
196196
current_client=ClientConfigV1Alpha1(
197-
name="testclient",
197+
alias="testclient",
198198
metadata=ObjectMeta(namespace="default", name="testclient"),
199199
endpoint="abc",
200200
token="123",
@@ -235,7 +235,7 @@ def test_user_config_use_client(monkeypatch: pytest.MonkeyPatch):
235235
ClientConfigV1Alpha1,
236236
"load",
237237
return_value=ClientConfigV1Alpha1(
238-
name="testclient",
238+
alias="testclient",
239239
metadata=ObjectMeta(namespace="default", name="testclient"),
240240
endpoint="abc",
241241
token="123",
@@ -247,7 +247,7 @@ def test_user_config_use_client(monkeypatch: pytest.MonkeyPatch):
247247
config = UserConfigV1Alpha1(
248248
config=UserConfigV1Alpha1Config(
249249
current_client=ClientConfigV1Alpha1(
250-
name="another",
250+
alias="another",
251251
metadata=ObjectMeta(namespace="default", name="testclient"),
252252
endpoint="abc",
253253
token="123",
@@ -260,7 +260,7 @@ def test_user_config_use_client(monkeypatch: pytest.MonkeyPatch):
260260
value = loaded.read()
261261
assert value == USER_CONFIG
262262
mock_load.assert_called_once_with("testclient")
263-
assert config.config.current_client.name == "testclient"
263+
assert config.config.current_client.alias == "testclient"
264264
os.unlink(f.name)
265265

266266

@@ -275,7 +275,7 @@ def test_user_config_use_client_none(monkeypatch: pytest.MonkeyPatch):
275275
config = UserConfigV1Alpha1(
276276
config=UserConfigV1Alpha1Config(
277277
current_client=ClientConfigV1Alpha1(
278-
name="another",
278+
alias="another",
279279
metadata=ObjectMeta(namespace="default", name="testclient"),
280280
endpoint="abc",
281281
token="123",

0 commit comments

Comments
 (0)