Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Update charm libraries (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <[email protected]>
  • Loading branch information
observability-noctua-bot and Github Actions authored Jun 5, 2023
1 parent 9fd64cc commit 966d7bf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/charms/traefik_k8s/v1/ingress_per_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _on_ingress_revoked(self, event: IngressPerUnitRevokedForUnitEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 11
LIBPATCH = 12

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -113,6 +113,7 @@ def _on_ingress_revoked(self, event: IngressPerUnitRevokedForUnitEvent):
"port": {"type": "string"},
"mode": {"type": "string"},
"strip-prefix": {"type": "string"},
"redirect-https": {"type": "string"},
},
"required": ["model", "name", "host", "port"],
}
Expand Down Expand Up @@ -152,6 +153,7 @@ def _on_ingress_revoked(self, event: IngressPerUnitRevokedForUnitEvent):
"port": int,
"mode": Optional[Literal["tcp", "http"]],
"strip-prefix": Optional[bool],
"redirect-https": Optional[bool],
},
total=False,
)
Expand Down Expand Up @@ -483,13 +485,14 @@ def _get_requirer_unit_data(self, relation: Relation, remote_unit: Unit) -> Requ

databag = relation.data[remote_unit]
remote_data: Dict[str, Union[int, str]] = {}
for k in ("port", "host", "model", "name", "mode", "strip-prefix"):
for k in ("port", "host", "model", "name", "mode", "strip-prefix", "redirect-https"):
v = databag.get(k)
if v is not None:
remote_data[k] = v
_validate_data(remote_data, INGRESS_REQUIRES_UNIT_SCHEMA)
remote_data["port"] = int(remote_data["port"])
remote_data["strip-prefix"] = bool(remote_data.get("strip-prefix", False))
remote_data["strip-prefix"] = bool(remote_data.get("strip-prefix", "false") == "true")
remote_data["redirect-https"] = bool(remote_data.get("redirect-https", "false") == "true")
return typing.cast(RequirerData, remote_data)

def _provider_app_data(self, relation: Relation) -> ProviderApplicationData:
Expand Down Expand Up @@ -659,6 +662,7 @@ def __init__(
mode: Literal["tcp", "http"] = "http",
listen_to: Literal["only-this-unit", "all-units", "both"] = "only-this-unit",
strip_prefix: bool = False,
redirect_https: bool = False,
):
"""Constructor for IngressPerUnitRequirer.
Expand Down Expand Up @@ -687,6 +691,7 @@ def __init__(
"all": this unit will receive both event types (which means it
will be notified *twice* of changes to this unit's ingress!).
strip_prefix: remove prefixes from the URL path.
redirect_https: redirect incoming requests to HTTPS
"""
super().__init__(charm, relation_name)
self._stored.set_default(current_urls=None) # type: ignore
Expand All @@ -697,6 +702,7 @@ def __init__(
self._port = port
self._mode = mode
self._strip_prefix = strip_prefix
self._redirect_https = redirect_https

self.listen_to = listen_to

Expand Down Expand Up @@ -789,6 +795,9 @@ def provide_ingress_requirements(self, *, host: Optional[str] = None, port: int)
if self._strip_prefix:
data["strip-prefix"] = "true"

if self._redirect_https:
data["redirect-https"] = "true"

_validate_data(data, INGRESS_REQUIRES_UNIT_SCHEMA)
self.relation.data[self.unit].update(data)

Expand Down

0 comments on commit 966d7bf

Please sign in to comment.