Skip to content

Commit

Permalink
Merge pull request #28 from canonical/ldap-validator-update
Browse files Browse the repository at this point in the history
Allow ldaps for ldap url
  • Loading branch information
AmberCharitos authored May 30, 2024
2 parents 6a938dd + df29069 commit 4ee5a4f
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 123 deletions.
303 changes: 199 additions & 104 deletions lib/charms/data_platform_libs/v0/data_interfaces.py

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions lib/charms/nginx_ingress_integrator/v0/nginx_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

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

__all__ = ["require_nginx_route", "provide_nginx_route"]

Expand Down Expand Up @@ -119,7 +119,7 @@ class _NginxRouteCharmEvents(ops.charm.CharmEvents):
nginx_route_broken = ops.framework.EventSource(_NginxRouteBrokenEvent)


class _NginxRouteRequirer(ops.framework.Object):
class NginxRouteRequirer(ops.framework.Object):
"""This class defines the functionality for the 'requires' side of the 'nginx-route' relation.
Hook events observed:
Expand Down Expand Up @@ -148,7 +148,7 @@ def __init__(
self._config_reconciliation,
)
# Set default values.
self._config: typing.Dict[str, typing.Union[str, int, bool]] = {
self.config: typing.Dict[str, typing.Union[str, int, bool]] = {
"service-namespace": self._charm.model.name,
**config,
}
Expand All @@ -163,11 +163,11 @@ def _config_reconciliation(self, _event: typing.Any = None) -> None:
delete_keys = {
relation_field
for relation_field in relation_app_data
if relation_field not in self._config
if relation_field not in self.config
}
for delete_key in delete_keys:
del relation_app_data[delete_key]
relation_app_data.update({k: str(v) for k, v in self._config.items()})
relation_app_data.update({k: str(v) for k, v in self.config.items()})


# C901 is ignored since the method has too many ifs but wouldn't be
Expand Down Expand Up @@ -195,7 +195,7 @@ def require_nginx_route( # pylint: disable=too-many-locals,too-many-branches,to
session_cookie_max_age: typing.Optional[int] = None,
tls_secret_name: typing.Optional[str] = None,
nginx_route_relation_name: str = "nginx-route",
) -> None:
) -> NginxRouteRequirer:
"""Set up nginx-route relation handlers on the requirer side.
This function must be invoked in the charm class constructor.
Expand Down Expand Up @@ -242,6 +242,9 @@ def require_nginx_route( # pylint: disable=too-many-locals,too-many-branches,to
nginx_route_relation_name: Specifies the relation name of
the relation handled by this requirer class. The relation
must have the nginx-route interface.
Returns:
the NginxRouteRequirer.
"""
config: typing.Dict[str, typing.Union[str, int, bool]] = {}
if service_hostname is not None:
Expand Down Expand Up @@ -281,7 +284,7 @@ def require_nginx_route( # pylint: disable=too-many-locals,too-many-branches,to
if tls_secret_name is not None:
config["tls-secret-name"] = tls_secret_name

_NginxRouteRequirer(
return NginxRouteRequirer(
charm=charm, config=config, nginx_route_relation_name=nginx_route_relation_name
)

Expand Down
10 changes: 5 additions & 5 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(self, *args):
- `scrape_timeout`
- `proxy_url`
- `relabel_configs`
- `metrics_relabel_configs`
- `metric_relabel_configs`
- `sample_limit`
- `label_limit`
- `label_name_length_limit`
Expand Down Expand Up @@ -362,7 +362,7 @@ def _on_scrape_targets_changed(self, event):

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

PYDEPS = ["cosl"]

Expand All @@ -377,7 +377,7 @@ def _on_scrape_targets_changed(self, event):
"scrape_timeout",
"proxy_url",
"relabel_configs",
"metrics_relabel_configs",
"metric_relabel_configs",
"sample_limit",
"label_limit",
"label_name_length_limit",
Expand Down Expand Up @@ -521,8 +521,8 @@ def expand_wildcard_targets_into_individual_jobs(
# for such a target. Therefore labeling with Juju topology, excluding the
# unit name.
non_wildcard_static_config["labels"] = {
**non_wildcard_static_config.get("labels", {}),
**topology.label_matcher_dict,
**non_wildcard_static_config.get("labels", {}),
}

non_wildcard_static_configs.append(non_wildcard_static_config)
Expand All @@ -547,9 +547,9 @@ def expand_wildcard_targets_into_individual_jobs(
if topology:
# Add topology labels
modified_static_config["labels"] = {
**modified_static_config.get("labels", {}),
**topology.label_matcher_dict,
**{"juju_unit": unit_name},
**modified_static_config.get("labels", {}),
}

# Instance relabeling for topology should be last in order.
Expand Down
10 changes: 7 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,16 @@ def update(self, event):
charm_function = self.config["charm-function"].value
logger.info("configuring ranger %s", charm_function)

if charm_function == "admin":
self.model.unit.open_port(port=APPLICATION_PORT, protocol="tcp")
command, context = self._configure_ranger_admin(container)
self.model.unit.close_port(port=APPLICATION_PORT, protocol="tcp")

if charm_function == "usersync":
command, context = self._configure_ranger_usersync(container)
elif charm_function == "admin":
self.model.unit.open_port(port=APPLICATION_PORT, protocol="tcp")
command, context = self._configure_ranger_admin(container)
else:
self.unit.status = BlockedStatus("Missing charm-function.")
return

logger.info("planning ranger %s execution", charm_function)
pebble_layer = {
Expand Down
2 changes: 1 addition & 1 deletion src/structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def sync_ldap_url_validator(cls, value: str) -> Optional[str]:
Raises:
ValueError: in the case when the value incorrectly formatted.
"""
ldap_url_pattern = r"^ldap://.*:\d+$"
ldap_url_pattern = r"^ldaps?://.*:\d+$"
if re.match(ldap_url_pattern, value) is not None:
return value
raise ValueError("Value incorrectly formatted.")
3 changes: 1 addition & 2 deletions tests/integration/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ async def test_create_service(self, ops_test: OpsTest):
new_service = ranger.get_service(TRINO_SERVICE)
logger.info(f"service: {new_service}")
name = new_service.get("name")
service_id = new_service.get("id")
assert name == TRINO_SERVICE and service_id == 1
assert TRINO_SERVICE in name
2 changes: 1 addition & 1 deletion tests/unit/test_structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_string_values(_harness) -> None:

# sync-ldap-url
check_invalid_values(_harness, "sync-ldap-url", erroneus_values)
accepted_values = ["ldap://ldap-k8s:3893", "ldap://example-host:636"]
accepted_values = ["ldap://ldap-k8s:3893", "ldaps://example-host:636"]
check_valid_values(_harness, "sync-ldap-url", accepted_values)


Expand Down

0 comments on commit 4ee5a4f

Please sign in to comment.