generated from canonical/platform-engineering-charm-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Allow enabling http for haproxy route backend #230
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
Merged
Thanhphan1147
merged 20 commits into
main
from
allow_enabling_http_for_haproxy_route_backend
Nov 24, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cda4288
Migrate to UV+Ruff
weiiwang01 8a4aebf
Fix linting issues found by ruff
weiiwang01 c05298a
Update .licenserc.yaml
weiiwang01 5b6c9ff
Add git as build package
weiiwang01 6284bad
Apply suggestions from review comments
weiiwang01 05cbf4a
Apply suggestions from review comments
weiiwang01 ac072db
add `allow_http` attribute, update test, improve rendering logic
Thanhphan1147 33cfcf6
update spelling
Thanhphan1147 fb2ee66
add haproxy-spoe-auth snap (#224)
Thanhphan1147 5de433f
specify snap folder for build step (#226)
Thanhphan1147 aeebb35
Get network information from relation endpoint binding (#223)
Thanhphan1147 920e8d3
chore: update charm libraries (#206)
github-actions[bot] 08fc285
update integration test to test for allow HTTP
Thanhphan1147 968697b
Merge branch 'main' into allow_enabling_http_for_haproxy_route_backend
Thanhphan1147 d454a40
update test to reduce depth
Thanhphan1147 08d03e6
add change artifact file
Thanhphan1147 43814ba
Merge branch 'main' into allow_enabling_http_for_haproxy_route_backend
Thanhphan1147 de9890c
Merge branch 'main' into allow_enabling_http_for_haproxy_route_backend
Thanhphan1147 1273b10
Merge branch 'main' into allow_enabling_http_for_haproxy_route_backend
Thanhphan1147 3ed6c62
update name for acl attribute
Thanhphan1147 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 @@ | ||
| schema_version: 1 | ||
| changes: | ||
| - title: Allow enabling http for haproxy route backend. | ||
| author: tphan025 | ||
| type: minor | ||
| description: | | ||
| Add a new allow_http attribute to allow disabling mandatory HTTPS redirection for backends. | ||
| Add logic to build the required ACL and rendering logic in the j2 template. | ||
| urls: | ||
| pr: https://github.com/canonical/haproxy-operator/pull/230 | ||
| related_doc: | ||
| related_issue: | ||
| visibility: public | ||
| highlight: false |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| """Unit tests for haproxy-route interface library HaproxyRouteRequirerData.""" | ||
|
|
||
| import ipaddress | ||
| import typing | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from charms.haproxy.v0.haproxy_route_tcp import HaproxyRouteTcpRequirersData | ||
| from charms.haproxy.v1.haproxy_route import ( | ||
| HaproxyRouteRequirerData, | ||
| HaproxyRouteRequirersData, | ||
| RequirerApplicationData, | ||
| RequirerUnitData, | ||
| ) | ||
|
|
||
| from state.haproxy_route import HaproxyRouteRequirersInformation | ||
|
|
||
|
|
||
| @pytest.fixture(name="mock_requirer_app_data_with_allow_http") | ||
| def mock_requirer_app_data_with_allow_http_fixture(): | ||
| """Create mock requirer application data with allow_http enabled.""" | ||
| return RequirerApplicationData( | ||
| service="test-service", | ||
| ports=[8080], | ||
| hosts=[ipaddress.ip_address("10.0.0.1")], | ||
| allow_http=True, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(name="mock_haproxy_route_requirer_data") | ||
| def mock_haproxy_route_requirer_data_fixture(): | ||
| """Create mock requirer application data with allow_http enabled.""" | ||
| return HaproxyRouteRequirerData( | ||
| relation_id=1, | ||
| application_data=typing.cast( | ||
| RequirerApplicationData, | ||
| RequirerApplicationData.from_dict( | ||
| { | ||
| "service": "service", | ||
| "ports": [80], | ||
| "allow_http": True, | ||
| "hostname": "example.com", | ||
| "paths": ["/path"], | ||
| "deny_paths": ["/private"], | ||
| } | ||
| ), | ||
| ), | ||
| units_data=[ | ||
| typing.cast(RequirerUnitData, RequirerUnitData.from_dict({"address": "10.0.0.1"})) | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(name="mock_haproxy_route_relation_data") | ||
| def mock_haproxy_route_relation_data_fixture( | ||
| mock_haproxy_route_requirer_data: HaproxyRouteRequirerData, | ||
| ) -> HaproxyRouteRequirersData: | ||
| """Create mock requirer application data with allow_http enabled.""" | ||
| return HaproxyRouteRequirersData( | ||
| requirers_data=[mock_haproxy_route_requirer_data], | ||
| relation_ids_with_invalid_data=[], | ||
| ) | ||
|
|
||
|
|
||
| def test_requirer_application_data_allow_http_default_is_false(): | ||
| """ | ||
| arrange: Create a RequirerApplicationData model without specifying allow_http. | ||
| act: Check the allow_http value. | ||
| assert: allow_http defaults to False. | ||
| """ | ||
| data = RequirerApplicationData( | ||
| service="test-service", | ||
| ports=[8080], | ||
| ) | ||
|
|
||
| assert data.allow_http is False | ||
|
|
||
|
|
||
| def test_haproxy_route_requirer_data_with_allow_http_true(mock_requirer_app_data_with_allow_http): | ||
| """ | ||
| arrange: Create a HaproxyRouteRequirerData with RequirerApplicationData having allow_http=True. | ||
| act: Instantiate HaproxyRouteRequirerData. | ||
| assert: Object is created successfully and allow_http is True. | ||
| """ | ||
| requirer_data = HaproxyRouteRequirerData( | ||
| relation_id=2, | ||
| application_data=mock_requirer_app_data_with_allow_http, | ||
| units_data=[RequirerUnitData(address=ipaddress.ip_address("10.0.0.1"))], | ||
| ) | ||
|
|
||
| assert requirer_data.application_data.allow_http is True | ||
|
|
||
|
|
||
| def test_haproxy_route_requirer_information( | ||
| mock_haproxy_route_relation_data: HaproxyRouteRequirersData, | ||
| ): | ||
| """ | ||
| arrange: Setup all relation providers mock. | ||
| act: Initialize the charm state. | ||
| assert: The proxy mode is correctly set to HAPROXY_ROUTE. | ||
| """ | ||
| haproxy_route_tcp_provider_mock = MagicMock() | ||
| haproxy_route_tcp_provider_mock.get_data = MagicMock( | ||
| return_value=HaproxyRouteTcpRequirersData( | ||
| requirers_data=[], relation_ids_with_invalid_data=[] | ||
| ) | ||
| ) | ||
| haproxy_route_provider_mock = MagicMock() | ||
| haproxy_route_provider_mock.get_data = MagicMock(return_value=mock_haproxy_route_relation_data) | ||
| haproxy_route_information = HaproxyRouteRequirersInformation.from_provider( | ||
| haproxy_route=haproxy_route_provider_mock, | ||
| haproxy_route_tcp=haproxy_route_tcp_provider_mock, | ||
| external_hostname=None, | ||
| peers=[], | ||
| ca_certs_configured=False, | ||
| ) | ||
| assert haproxy_route_information.acls_for_allow_http == [ | ||
| "{ req.hdr(Host) -m str example.com } { path_beg -i /path } !{ path_beg -i /private }" | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.