-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose additional ports for sessions internally
Expose additional configurable ports for tools in the user-internal network. Example use-case would be to expose an additional REST API, which can be used by a another session to automate tasks.
- Loading branch information
1 parent
d666f64
commit a9c0e03
Showing
10 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import typing as t | ||
|
||
if t.TYPE_CHECKING: | ||
from . import models | ||
|
||
|
||
def resolve_tool_ports(ports: "models.SessionPorts") -> dict[str, int]: | ||
model = ports.model_dump() | ||
additional = model["additional"] | ||
del model["additional"] | ||
|
||
return model | additional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
from capellacollab.tools import models as tools_models | ||
from capellacollab.tools import util as tools_util | ||
|
||
|
||
def test_additional_ports_are_unique(): | ||
with pytest.raises(ValueError): | ||
tools_models.HTTPPorts( | ||
metrics=9118, | ||
http=8080, | ||
additional={"restapi": 5007, "restapi2": 5007}, | ||
) | ||
|
||
|
||
def test_additional_ports_not_reserved_keys(): | ||
with pytest.raises(ValueError): | ||
tools_models.HTTPPorts( | ||
metrics=9118, | ||
http=8080, | ||
additional={"http": 5007}, | ||
) | ||
|
||
|
||
def test_additional_port_already_in_use(): | ||
with pytest.raises(ValueError): | ||
tools_models.HTTPPorts( | ||
metrics=9118, | ||
http=8080, | ||
additional={"restapi": 8080}, | ||
) | ||
|
||
|
||
def test_additional_ports_reserved_port(): | ||
with pytest.raises(ValueError): | ||
tools_models.HTTPPorts( | ||
metrics=9118, | ||
http=8080, | ||
additional={"test": 80}, | ||
) | ||
|
||
|
||
def test_environment_resolution(): | ||
ports = tools_models.HTTPPorts( | ||
metrics=9118, | ||
http=8080, | ||
additional={"restapi": 5007}, | ||
) | ||
assert tools_util.resolve_tool_ports(ports) == { | ||
"metrics": 9118, | ||
"http": 8080, | ||
"restapi": 5007, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters