3737from pymongo import MongoClient
3838from pymongo .errors import PyMongoError
3939
40+ from config import TestflingerServerConfig
41+
4042logger = logging .getLogger (__name__ )
4143
4244TESTFLINGER_ADMIN_ID = "testflinger-admin"
@@ -54,6 +56,9 @@ class TestflingerCharm(ops.CharmBase):
5456 def __init__ (self , * args ):
5557 """Initialize the charm."""
5658 super ().__init__ (* args )
59+ self .typed_config = self .load_config (
60+ TestflingerServerConfig , errors = "blocked"
61+ )
5762 self .pebble_service_name = "testflinger"
5863 self .pebble_check_name = "v1_up"
5964 self .container = self .unit .get_container ("testflinger" )
@@ -143,7 +148,7 @@ def _require_nginx_route(self):
143148 # TODO: Remove nginx route when migration to traefik route is completed
144149 require_nginx_route (
145150 charm = self ,
146- service_hostname = self .config [ " external_hostname" ] ,
151+ service_hostname = self .typed_config . external_hostname ,
147152 service_name = self .app .name ,
148153 service_port = DEFAULT_PORT ,
149154 )
@@ -193,7 +198,7 @@ def _configure_traefik_route(self):
193198
194199 testflinger_base_url = (
195200 self .traefik_route .external_host
196- or self .config . get ( " external_hostname" , "" )
201+ or self .typed_config . external_hostname
197202 )
198203 if not testflinger_base_url :
199204 self .unit .status = ops .BlockedStatus (
@@ -345,7 +350,7 @@ def _run_rotation(self, app_env: dict) -> str:
345350
346351 def _on_config_changed (self , _ : ops .framework .EventBase ) -> None :
347352 """Handle config changed event."""
348- new_key = self .config [ " testflinger_secrets_master_key" ]
353+ new_key = self .typed_config . testflinger_secrets_master_key
349354 stored_key = self ._stored .previous_master_key
350355
351356 # Rotate only if master key was previously defined, has changed,
@@ -389,7 +394,7 @@ def _on_retry_key_rotation_action(self, event: ops.ActionEvent) -> None:
389394 unit in BlockedStatus. The old key is read from StoredState and the
390395 new key from the current config.
391396 """
392- current_key = self .config [ " testflinger_secrets_master_key" ]
397+ current_key = self .typed_config . testflinger_secrets_master_key
393398 stored_key = self ._stored .previous_master_key
394399
395400 if not current_key :
@@ -423,7 +428,7 @@ def _on_retry_key_rotation_action(self, event: ops.ActionEvent) -> None:
423428 @property
424429 def _pebble_layer (self ):
425430 """Return a dictionary representing a Pebble layer."""
426- keepalive = str (self .config [ " keepalive" ] )
431+ keepalive = str (self .typed_config . keepalive )
427432 command = " " .join (
428433 [
429434 "gunicorn" ,
@@ -482,15 +487,15 @@ def app_environment(self) -> dict:
482487 "MONGODB_USERNAME" : db_data .get ("db_username" ),
483488 "MONGODB_PASSWORD" : db_data .get ("db_password" ),
484489 "MONGODB_DATABASE" : db_data .get ("db_database" ),
485- "MONGODB_MAX_POOL_SIZE" : str (self .config ["max_pool_size" ]),
486- "JWT_SIGNING_KEY" : self .config ["jwt_signing_key" ],
487- "TESTFLINGER_SECRETS_MASTER_KEY" : self .config [
488- "testflinger_secrets_master_key"
489- ],
490+ "MONGODB_MAX_POOL_SIZE" : str (self .typed_config .max_pool_size ),
491+ "JWT_SIGNING_KEY" : self .typed_config .jwt_signing_key ,
492+ "TESTFLINGER_SECRETS_MASTER_KEY" : self .typed_config .testflinger_secrets_master_key , # noqa: E501
490493 "TESTFLINGER_KEY_VAULT_URI" : self ._fetch_keyvault_uri () or "" ,
491- "HTTP_PROXY" : self .config ["http_proxy" ],
492- "HTTPS_PROXY" : self .config ["https_proxy" ],
493- "NO_PROXY" : self .config ["no_proxy" ],
494+ "HTTP_PROXY" : self .typed_config .http_proxy ,
495+ "HTTPS_PROXY" : self .typed_config .https_proxy ,
496+ "NO_PROXY" : self .typed_config .no_proxy ,
497+ "WEBHOOK_URL" : self .typed_config .webhook_url ,
498+ "WEBHOOK_AUTH" : self .typed_config .webhook_auth ,
494499 }
495500 return env
496501
0 commit comments