Skip to content

Commit

Permalink
chore: update charm libraries (#161)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <github-actions@github.com>
  • Loading branch information
observability-noctua-bot and Github Actions authored Jun 5, 2023
1 parent 61251e9 commit af190b4
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/charms/traefik_k8s/v1/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):

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

DEFAULT_RELATION_NAME = "ingress"
RELATION_INTERFACE = "ingress"
Expand Down Expand Up @@ -98,6 +98,7 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):
"host": {"type": "string"},
"port": {"type": "string"},
"strip-prefix": {"type": "string"},
"redirect-https": {"type": "string"},
},
"required": ["model", "name", "host", "port"],
}
Expand All @@ -118,7 +119,14 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):
# Model of the data a unit implementing the requirer will need to provide.
RequirerData = TypedDict(
"RequirerData",
{"model": str, "name": str, "host": str, "port": int, "strip-prefix": bool},
{
"model": str,
"name": str,
"host": str,
"port": int,
"strip-prefix": bool,
"redirect-https": bool,
},
total=False,
)
# Provider ingress data model.
Expand Down Expand Up @@ -226,14 +234,15 @@ def restore(self, snapshot) -> None:
class IngressPerAppDataProvidedEvent(_IPAEvent):
"""Event representing that ingress data has been provided for an app."""

__args__ = ("name", "model", "port", "host", "strip_prefix")
__args__ = ("name", "model", "port", "host", "strip_prefix", "redirect_https")

if typing.TYPE_CHECKING:
name: Optional[str] = None
model: Optional[str] = None
port: Optional[str] = None
host: Optional[str] = None
strip_prefix: bool = False
redirect_https: bool = False


class IngressPerAppDataRemovedEvent(RelationEvent):
Expand Down Expand Up @@ -274,6 +283,7 @@ def _handle_relation(self, event):
data["port"],
data["host"],
data.get("strip-prefix", False),
data.get("redirect-https", False),
)

def _handle_relation_broken(self, event):
Expand Down Expand Up @@ -306,13 +316,14 @@ def _get_requirer_data(self, relation: Relation) -> RequirerData: # type: ignor

databag = relation.data[relation.app]
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_APP_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 get_data(self, relation: Relation) -> RequirerData: # type: ignore
Expand Down Expand Up @@ -418,6 +429,7 @@ def __init__(
host: Optional[str] = None,
port: Optional[int] = None,
strip_prefix: bool = False,
redirect_https: bool = False,
):
"""Constructor for IngressRequirer.
Expand All @@ -433,6 +445,7 @@ def __init__(
host: Hostname to be used by the ingress provider to address the requiring
application; if unspecified, the default Kubernetes service name will be used.
strip_prefix: configure Traefik to strip the path prefix.
redirect_https: redirect incoming requests to the HTTPS.
Request Args:
port: the port of the service
Expand All @@ -441,6 +454,7 @@ def __init__(
self.charm: CharmBase = charm
self.relation_name = relation_name
self._strip_prefix = strip_prefix
self._redirect_https = redirect_https

self._stored.set_default(current_url=None) # type: ignore

Expand Down Expand Up @@ -517,6 +531,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_APP_SCHEMA)
self.relation.data[self.app].update(data)

Expand Down

0 comments on commit af190b4

Please sign in to comment.