Skip to content

Commit

Permalink
fix: post review
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness committed Oct 15, 2024
1 parent 0b6038b commit d21702d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/charms/mongodb/v1/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
from charms.data_platform_libs.v0.data_interfaces import DatabaseProvides
from charms.mongodb.v0.mongo import MongoConfiguration, MongoConnection
from charms.mongodb.v1.helpers import generate_password
from ops.charm import CharmBase, EventBase, RelationBrokenEvent, RelationChangedEvent
from ops.charm import (
CharmBase,
EventBase,
RelationBrokenEvent,
RelationChangedEvent,
RelationEvent,
)
from ops.framework import Object
from ops.model import Relation
from pymongo.errors import PyMongoError
Expand Down Expand Up @@ -88,10 +94,10 @@ def pass_sanity_hook_checks(self) -> bool:
if not self.charm.db_initialised:
return False

# This is tricky: the sanity hook checks can pass when the call is
# Warning: the sanity_hook_checks can pass when the call is
# issued by a config-sever because the config-server is allowed to manage the users
# in MongoDB. This is not well named and does not protect integration of a config-server
# to a client application
# to a client application.
if not self.charm.is_role(Config.Role.MONGOS) and not self.charm.is_relation_feasible(
self.get_relation_name()
):
Expand All @@ -103,10 +109,12 @@ def pass_sanity_hook_checks(self) -> bool:

return True

def pass_hook_checks(self, event: RelationChangedEvent) -> bool:
def pass_hook_checks(self, event: RelationEvent) -> bool:
"""Runs the pre-hooks checks for MongoDBProvider, returns True if all pass."""
# First, ensure that the relation is valid, useless to do anything else otherwise
if not self.charm.is_relation_feasible(event.relation.name):
if not self.charm.is_role(Config.Role.MONGOS) and not self.charm.is_relation_feasible(
event.relation.name
):
return False

if not self.pass_sanity_hook_checks():
Expand Down

0 comments on commit d21702d

Please sign in to comment.