Skip to content

Commit

Permalink
Make sure updated external url propagates to catalogue (#107)
Browse files Browse the repository at this point in the history
* Make sure updated url propogates to catalogue
* no_implicit_optional
* fetch-lib
* Fix port being None
  • Loading branch information
sed-i authored Nov 22, 2022
1 parent e2ef70b commit 7d52879
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 64 deletions.
12 changes: 7 additions & 5 deletions lib/charms/alertmanager_k8s/v0/alertmanager_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, *args):
"""
import logging
import socket
from typing import Callable, List
from typing import Callable, List, Optional
from urllib.parse import urlparse

import ops
Expand All @@ -42,7 +42,7 @@ def __init__(self, *args):

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

# Set to match metadata.yaml
INTERFACE_NAME = "alertmanager_dispatch"
Expand Down Expand Up @@ -240,7 +240,7 @@ def __init__(
relation_name: str = "alerting",
api_port: int = 9093,
*,
external_url: Callable = None,
external_url: Optional[Callable] = None,
):
# TODO: breaking change: force keyword-only args from relation_name onwards
super().__init__(charm, relation_name, RelationRole.provides)
Expand Down Expand Up @@ -270,9 +270,11 @@ def _generate_relation_data(self, relation: Relation):
"""
# Drop the scheme
parsed = urlparse(self._external_url())
return {"public_address": "{}:{}{}".format(parsed.hostname, parsed.port, parsed.path)}
return {
"public_address": "{}:{}{}".format(parsed.hostname, parsed.port or 80, parsed.path)
}

def update_relation_data(self, event: RelationEvent = None):
def update_relation_data(self, event: Optional[RelationEvent] = None):
"""Helper function for updating relation data bags.
This function can be used in two different ways:
Expand Down
Loading

0 comments on commit 7d52879

Please sign in to comment.