Skip to content

Commit

Permalink
fix bug in role retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Sep 26, 2023
1 parent 059356f commit bed71ce
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ def db_initialised(self) -> bool:
@property
def role(self) -> str:
"""Returns role of MongoDB deployment."""
if "role" not in self.app_peer_data and self.unit.is_leader():
if (
"role" not in self.app_peer_data
and self.unit.is_leader()
and self.model.config["role"]
):
self.app_peer_data["role"] = self.model.config["role"]
# app data bag isn't set until function completes
return self.model.config["role"]
else:
# if leader hasn't set the role yet, use the one set by model
self.model.config["role"]
return self.model.config["role"]

return self.app_peer_data.get("role")

Expand Down Expand Up @@ -762,7 +768,7 @@ def _get_mongodb_config_for_user(
return MongoDBConfiguration(
replset=self.app.name,
database=user.get_database_name(),
username=user.get_username(),
username=f"{user.get_username()}-{self.role}",
password=self.get_secret(APP_SCOPE, user.get_password_key_name()),
hosts=hosts,
roles=user.get_roles(),
Expand Down

0 comments on commit bed71ce

Please sign in to comment.