@property
def admin_project_name(self):
return self.get_data_from_app("admin_project_name")
+
+
+class MongoClient(BaseRelationClient):
+ """Requires side of a Mongo Endpoint"""
+
+ mandatory_fields_mapping = {
+ "reactive": ["connection_string"],
+ "ops": ["replica_set_uri", "replica_set_name"],
+ }
+
+ def __init__(self, charm: ops.charm.CharmBase, relation_name: str):
+ super().__init__(charm, relation_name, mandatory_fields=[])
+
+ @property
+ def connection_string(self):
+ if self.is_opts():
+ replica_set_uri = self.get_data_from_unit("replica_set_uri")
+ replica_set_name = self.get_data_from_unit("replica_set_name")
+ return f"{replica_set_uri}?replicaSet={replica_set_name}"
+ else:
+ return self.get_data_from_unit("connection_string")
+
+ def is_opts(self):
+ return not self.is_missing_data_in_unit_ops()
+
+ def is_missing_data_in_unit(self):
+ return self.is_missing_data_in_unit_ops() and self.is_missing_data_in_unit_reactive()
+
+ def is_missing_data_in_unit_ops(self):
+ return not all(
+ [self.get_data_from_unit(field) for field in self.mandatory_fields_mapping["ops"]]
+ )
+
+ def is_missing_data_in_unit_reactive(self):
+ return not all(
+ [self.get_data_from_unit(field) for field in self.mandatory_fields_mapping["reactive"]]
+ )
+
+
+class PrometheusClient(BaseRelationClient):
+ """Requires side of a Prometheus Endpoint"""
+
+ mandatory_fields = ["hostname", "port"]
+
+ def __init__(self, charm: ops.charm.CharmBase, relation_name: str):
+ super().__init__(charm, relation_name, self.mandatory_fields)
+
+ @property
+ def hostname(self):
+ return self.get_data_from_app("hostname")
+
+ @property
+ def port(self):
+ return self.get_data_from_app("port")
+
+ @property
+ def user(self):
+ return self.get_data_from_app("user")
+
+ @property
+ def password(self):
+ return self.get_data_from_app("password")