Skip to content

Commit 56d8997

Browse files
authored
Fixed proxy overwriting manager config (#11)
* Fixed proxy overwriting manager config * Update PR template with new issue repo
1 parent ff0cf0c commit 56d8997

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Include a summary of this pull request
44

55
New dependencies: (Added to requirements_*.txt)
66

7-
Fixes # (potential issues that are fixed by this PR)
7+
Fixes vikinganalytics/daeploy-issues# (potential issues that are fixed by this PR)
88

99
## Type of Change
1010

manager/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
DAEPLOY_PICKLE_FILE_NAME = "model.pkl"
3131

3232
DAEPLOY_PROXY_DASHBOARD_IDENTIFIER = "proxy_dashboard_configuration"
33-
DAEPLOY_MANAGER_IDENTIFIER = "manager_configuration"
33+
DAEPLOY_MANAGER_PROXY_CONFIG_FILE = "manager_configuration"
3434
DAEPLOY_AUTH_MIDDLEWARE = "proxy_auth_middleware"
3535
DAEPLOY_AUTH_MIDDLEWARE_IDENTIFIER = f"{DAEPLOY_AUTH_MIDDLEWARE}_configuration"
3636

manager/data_models/request_models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ class BaseService(BaseModel):
1616
@validator("name")
1717
def must_adhere_to_docker_requirements(cls, name):
1818
# Only allow a name to contain lower case letters, numbers and underscore
19-
regex_pattern = re.compile("[a-z0-9_]+$")
19+
# anywhere but in the beginning and end
20+
regex_pattern = re.compile("^(?!_)[a-z0-9_]+(?<!_)$")
2021
if not regex_pattern.match(name):
2122
raise ValueError(
22-
"can only contain lower case letters, numbers and underscores"
23+
"Name can only contain lower case letters, numbers and underscores,"
24+
" but should not start or end with an underscore."
2325
)
2426
return name
2527

2628
# pylint: disable=no-self-use
2729
@validator("version")
2830
def must_be_semver_string(cls, version):
2931
if not semver.VersionInfo.isvalid(version):
30-
raise ValueError("must be a semantic version string")
32+
raise ValueError("Version must be a semantic version string.")
3133
return version
3234

3335

manager/proxy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from manager.notification_api import _manager_notification, register_notification
1111
from manager.constants import (
1212
DAEPLOY_PROXY_DASHBOARD_IDENTIFIER,
13-
DAEPLOY_MANAGER_IDENTIFIER,
13+
DAEPLOY_MANAGER_PROXY_CONFIG_FILE,
1414
DAEPLOY_AUTH_MIDDLEWARE,
1515
DAEPLOY_AUTH_MIDDLEWARE_IDENTIFIER,
1616
DAEPLOY_DATA_DIR,
@@ -343,7 +343,9 @@ def initial_setup():
343343
)
344344

345345
# Add manager to root
346-
add_dynamic_configuration(DAEPLOY_MANAGER_IDENTIFIER, get_manager_configuration())
346+
add_dynamic_configuration(
347+
DAEPLOY_MANAGER_PROXY_CONFIG_FILE, get_manager_configuration()
348+
)
347349

348350
# Add auth middleware
349351
add_dynamic_configuration(
@@ -405,7 +407,7 @@ def create_new_service_configuration(name: str, version: str, address: str):
405407
"""
406408
LOGGER.info(f"Creating configuration for service: {name}")
407409
service_name = f"{name}_{version}"
408-
file_name = f"{service_name}_configuration.toml"
410+
file_name = f"service_{service_name}_configuration.toml"
409411
config = get_base_service_config(service_name)
410412

411413
# Create service configurations
@@ -437,7 +439,7 @@ def create_mirror_configuration(
437439
shadow_versions (List[str], optional): List of versions of the shadow
438440
services. Defaults to None.
439441
"""
440-
file_name = f"{name}_configuration.toml"
442+
file_name = f"service_{name}_configuration.toml"
441443
config = get_base_service_config(name)
442444

443445
shadow_versions = shadow_versions or []
@@ -465,7 +467,7 @@ def remove_service_configuration(name: str, version: str):
465467
version (str): Service version
466468
"""
467469
service_name = f"{name}_{version}"
468-
file_name = f"{service_name}_configuration.toml"
469-
mirror_file_name = f"{name}_configuration.toml"
470+
file_name = f"service_{service_name}_configuration.toml"
471+
mirror_file_name = f"service_{name}_configuration.toml"
470472
remove_dynamic_configuration(file_name)
471473
remove_dynamic_configuration(mirror_file_name)

tests/manager_test/model_test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ def test_ServiceRequest_name_validator_invalid_names():
2525
with pytest.raises(ValueError):
2626
BaseNewServiceRequest(name="//////", version="0.0.1", port=80)
2727

28+
with pytest.raises(ValueError):
29+
BaseNewServiceRequest(name="service_", version="0.0.1", port=80)
30+
31+
with pytest.raises(ValueError):
32+
BaseNewServiceRequest(name="_service", version="0.0.1", port=80)
33+
34+
with pytest.raises(ValueError):
35+
BaseNewServiceRequest(name="_service_", version="0.0.1", port=80)
36+
2837

2938
def test_ServiceRequest_name_validator_valid_names():
3039
BaseNewServiceRequest(name="model", version="0.0.1", port=80)
3140
BaseNewServiceRequest(name="my_model", version="0.0.1", port=80)
32-
BaseNewServiceRequest(name="my_model123_", version="0.0.1", port=80)
33-
BaseNewServiceRequest(name="_model_", version="0.0.1", port=80)
41+
BaseNewServiceRequest(name="my_model_123", version="0.0.1", port=80)

tests/manager_test/proxy_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ def test_initial_setup_creates_existing_service_configs(tmp_path):
174174
time.sleep(1) # Grace period
175175
try:
176176
proxy_files = os.listdir(tmp_path / "dynamic")
177-
assert "1_configuration.toml" in proxy_files
178-
assert "1_1.0.0_configuration.toml" in proxy_files
179-
assert "1_1.1.0_configuration.toml" in proxy_files
180-
assert "2_configuration.toml" in proxy_files
181-
assert "2_1.0.1_configuration.toml" in proxy_files
177+
assert "service_1_configuration.toml" in proxy_files
178+
assert "service_1_1.0.0_configuration.toml" in proxy_files
179+
assert "service_1_1.1.0_configuration.toml" in proxy_files
180+
assert "service_2_configuration.toml" in proxy_files
181+
assert "service_2_1.0.1_configuration.toml" in proxy_files
182182
finally:
183183
killer()
184184

@@ -198,7 +198,7 @@ def test_https_dynamic_config_services(tmp_path, pinned):
198198
root.recreate_proxy_configurations()
199199
time.sleep(1) # Grace period
200200
try:
201-
with open(tmp_path / "dynamic" / "1_configuration.toml", "r") as f:
201+
with open(tmp_path / "dynamic" / "service_1_configuration.toml", "r") as f:
202202
service_config = toml.load(f)
203203
assert service_config == pinned
204204
finally:

0 commit comments

Comments
 (0)