You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking into MongoDBProvider class, I can see it registers the same information for each user twice, where username, database, hosts, password and replset are registered as variables and as part of the URI in the databag.
That means any change in the charm code must take into consideration that both the configuration itself and the URI must be updated as either maybe used.
That is passed in the mongodb provider:
class MongoDBProvider(Object):
...
def _set_relation(self, config: MongoDBConfiguration):
"""Save all output fields into application relation."""
relation = self._get_relation_from_username(config.username)
if relation is None:
return None
data = relation.data[self.charm.app]
data["username"] = config.username
data["password"] = config.password
data["database"] = config.database
data["endpoints"] = ",".join(config.hosts)
data["replset"] = config.replset
data["uris"] = config.uri
relation.data[self.charm.app].update(data)
And the MongoDBConfiguration code:
class MongoDBConfiguration:
...
replset: str
database: Optional[str]
username: str
password: str
hosts: Set[str]
roles: Set[str]
tls_external: bool
tls_internal: bool
@property
def uri(self):
"""Return URI concatenated from fields."""
hosts = ",".join(self.hosts)
# Auth DB should be specified while user connects to application DB.
auth_source = ""
if self.database != "admin":
auth_source = "&authSource=admin"
return (
f"mongodb://{quote_plus(self.username)}:"
f"{quote_plus(self.password)}@"
f"{hosts}/{quote_plus(self.database)}?"
f"replicaSet={quote_plus(self.replset)}"
f"{auth_source}"
)
The text was updated successfully, but these errors were encountered:
phvalguima
changed the title
MongoDBProvider duplicates information in databag and is error-prone
[VM & K8S] MongoDBProvider duplicates information in databag and is error-prone
Jul 20, 2023
Looking into MongoDBProvider class, I can see it registers the same information for each user twice, where username, database, hosts, password and replset are registered as variables and as part of the URI in the databag.
That means any change in the charm code must take into consideration that both the configuration itself and the URI must be updated as either maybe used.
That is passed in the mongodb provider:
And the MongoDBConfiguration code:
The text was updated successfully, but these errors were encountered: