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

chore: keep public-url config option for compatibility #213

Merged
merged 1 commit into from
Jul 24, 2024
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
7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ options:
type: string
default: ''
description: Static password for logging in without an external auth service
public-url:
type: string
default: ''
description: |
DEPRECATED - Please leave empty or use issuer-url instead. This configuration option will be removed soon.
It has been preserved to avoid breaking compatibility with existing deployments.
Publicly-accessible endpoint for cluster
13 changes: 13 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def _issuer_url(self) -> str:
"""Return issuer-url value if config option exists; otherwise default Dex's endpoint."""
if issuer_url := self.model.config["issuer-url"]:
return issuer_url
# TODO: remove this after the release of dex-auth 2.39
# This should not be supported anymore, but has been kept for compatibility
if public_url := self.model.config["public-url"]:
self.logger.warning(
"DEPRECATED: The public-url config option is deprecated"
"Please leave empty or use issuer-url;"
"otherwise this may cause unexpected behaviour."
)
# This will just cover cases like when the URL is my-dex.io:5557,
# not when it starts with a different protocol
if not public_url.startswith(("http://", "https://")):
public_url = f"http://{public_url}"
return f"{public_url}/dex"
return (
f"http://{self.model.app.name}.{self._namespace}.svc:{self.model.config['port']}/dex"
)
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def test_config_changed(update, harness):
"connectors": "connector01",
"static-username": "new-user",
"static-password": "new-pass",
"public-url": "",
}

harness.update_config(config_updates)
Expand Down Expand Up @@ -261,3 +262,46 @@ def test_grpc_relation_with_data_when_data_changes(

# Change the port of the service and check the value changes
assert provider_rel_data["issuer-url"] == harness.model.config["issuer-url"]


@patch("charm.KubernetesServicePatch", lambda *_, **__: None)
@pytest.mark.parametrize(
"issuer_url_config, default_value, expected_result",
(
(None, True, None),
("http://my-dex.io:5557/dex", False, "http://my-dex.io:5557/dex"),
),
)
def test_issuer_url_property_with_issuer_url_config(
issuer_url_config, default_value, expected_result, harness
):
"""Test the property returns as expected.


The first case assumes the issuer-url config option is not set, thus the default-value
of "http://dex-auth.<namespace>.svc:5556/dex" should be returned; the second case should return
the value set in the config option.
"""
harness.set_leader(True)
harness.update_config({"issuer-url": issuer_url_config})
harness.begin()

if default_value:
expected_result = f"http://{harness.model.app.name}.{harness.model.name}.svc:5556/dex"
assert harness.charm._issuer_url == expected_result


@patch("charm.KubernetesServicePatch", lambda *_, **__: None)
@pytest.mark.parametrize(
"public_url_config, expected_result",
(
("http://my-dex.io:5557", "http://my-dex.io:5557/dex"),
("my-dex.io:5557", "http://my-dex.io:5557/dex"),
),
)
def test_issuer_url_property_with_public_url_config(public_url_config, expected_result, harness):
"""Test the property returns as expected."""
harness.set_leader(True)
harness.update_config({"public-url": public_url_config})
harness.begin()
assert harness.charm._issuer_url == expected_result
Loading