@@ -13,15 +13,17 @@ use axum::{
1313 routing:: { delete, get, post, put} ,
1414 serve,
1515} ;
16+ use defguard_certs:: CertificateAuthority ;
1617use defguard_common:: {
1718 VERSION ,
1819 auth:: claims:: { Claims , ClaimsType } ,
1920 config:: { DefGuardConfig , InitVpnLocationArgs , server_config} ,
2021 db:: {
2122 init_db,
2223 models:: {
23- Device , DeviceType , User , WireguardNetwork ,
24+ Device , DeviceType , Settings , User , WireguardNetwork ,
2425 oauth2client:: OAuth2Client ,
26+ settings:: { initialize_current_settings, update_current_settings} ,
2527 wireguard:: {
2628 DEFAULT_DISCONNECT_THRESHOLD , DEFAULT_KEEPALIVE_INTERVAL , DEFAULT_WIREGUARD_MTU ,
2729 LocationMfaMode , ServiceLocationMode ,
@@ -632,6 +634,7 @@ pub async fn run_web_server(
632634/// Test device keys:
633635/// Public: gQYL5eMeFDj0R+lpC7oZyIl0/sNVmQDC6ckP7husZjc=
634636/// Private: wGS1qdJfYbWJsOUuP1IDgaJYpR+VaKZPVZvdmLjsH2Y=
637+ #[ allow( deprecated) ]
635638pub async fn init_dev_env ( config : & DefGuardConfig ) {
636639 info ! ( "Initializing dev environment" ) ;
637640 let pool = init_db (
@@ -648,6 +651,24 @@ pub async fn init_dev_env(config: &DefGuardConfig) {
648651 . await
649652 . expect ( "Failed to create admin user" ) ;
650653
654+ let ca = CertificateAuthority :: new ( "Defguard Dev" , "defguard-dev@defguard.net" , 5000 )
655+ . expect ( "Failed to create CA" ) ;
656+
657+ initialize_current_settings ( & pool)
658+ . await
659+ . expect ( "Could not initialize current settings in the database" ) ;
660+ let mut settings = Settings :: get_current_settings ( ) ;
661+ settings. ca_cert_der = Some ( ca. cert_der ( ) . to_vec ( ) ) ;
662+ settings. ca_key_der = Some ( ca. key_pair_der ( ) . to_vec ( ) ) ;
663+ settings. ca_expiry = Some ( ca. expiry ( ) . expect ( "Failed to get CA expiry" ) ) ;
664+ settings. initial_setup_completed = true ;
665+ // This should possibly be initialized somehow differently in the future since we are deprecating the enrollment URL env var.
666+ settings. public_proxy_url = config. enrollment_url . to_string ( ) ;
667+ settings. defguard_url = config. url . to_string ( ) ;
668+ update_current_settings ( & pool, settings)
669+ . await
670+ . expect ( "Failed to update settings" ) ;
671+
651672 let mut transaction = pool
652673 . begin ( )
653674 . await
0 commit comments