+from ops.main import main
+from opslib.osm.charm import CharmedOsmBase, RelationsMissing
+from opslib.osm.interfaces.kafka import KafkaClient
+from opslib.osm.interfaces.keystone import KeystoneClient
+from opslib.osm.interfaces.mongo import MongoClient
+from opslib.osm.interfaces.prometheus import PrometheusClient
+from opslib.osm.pod import (
+ ContainerV3Builder,
+ FilesV3Builder,
+ PodRestartPolicy,
+ PodSpecV3Builder,
+)
+from opslib.osm.validator import ModelValidator, validator
+
+
+logger = logging.getLogger(__name__)
+
+PORT = 8000
+
+
+def _check_certificate_data(name: str, content: str):
+ if not name or not content:
+ raise ValueError("certificate name and content must be a non-empty string")
+
+
+def _extract_certificates(certs_config: str):
+ certificates = {}
+ if certs_config:
+ cert_list = certs_config.split(",")
+ for cert in cert_list:
+ name, content = cert.split(":")
+ _check_certificate_data(name, content)
+ certificates[name] = content
+ return certificates
+
+
+def decode(content: str):
+ return base64.b64decode(content.encode("utf-8")).decode("utf-8")
+
+
+class ConfigModel(ModelValidator):
+ keystone_enabled: bool
+ vca_host: str
+ vca_user: str
+ vca_secret: str
+ vca_cacert: str
+ database_commonkey: str
+ mongodb_uri: Optional[str]
+ log_level: str
+ openstack_default_granularity: int
+ global_request_timeout: int
+ collector_interval: int
+ evaluator_interval: int
+ grafana_url: str
+ grafana_user: str
+ grafana_password: str
+ certificates: Optional[str]
+ image_pull_policy: str
+ debug_mode: bool
+ security_context: bool
+
+ @validator("log_level")
+ def validate_log_level(cls, v):
+ if v not in {"INFO", "DEBUG"}:
+ raise ValueError("value must be INFO or DEBUG")
+ return v
+
+ @validator("certificates")
+ def validate_certificates(cls, v):
+ # Raises an exception if it cannot extract the certificates
+ _extract_certificates(v)
+ return v
+
+ @validator("mongodb_uri")
+ def validate_mongodb_uri(cls, v):
+ if v and not v.startswith("mongodb://"):
+ raise ValueError("mongodb_uri is not properly formed")
+ return v
+
+ @validator("image_pull_policy")
+ def validate_image_pull_policy(cls, v):
+ values = {
+ "always": "Always",
+ "ifnotpresent": "IfNotPresent",
+ "never": "Never",
+ }
+ v = v.lower()
+ if v not in values.keys():
+ raise ValueError("value must be always, ifnotpresent or never")
+ return values[v]