Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion crates/defguard_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ use axum::{
routing::{delete, get, post, put},
serve,
};
use defguard_certs::CertificateAuthority;
use defguard_common::{
VERSION,
auth::claims::{Claims, ClaimsType},
config::{DefGuardConfig, InitVpnLocationArgs, server_config},
db::{
init_db,
models::{
Device, DeviceType, User, WireguardNetwork,
Device, DeviceType, Settings, User, WireguardNetwork,
oauth2client::OAuth2Client,
settings::{initialize_current_settings, update_current_settings},
wireguard::{
DEFAULT_DISCONNECT_THRESHOLD, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_WIREGUARD_MTU,
LocationMfaMode, ServiceLocationMode,
Expand Down Expand Up @@ -632,6 +634,7 @@ pub async fn run_web_server(
/// Test device keys:
/// Public: gQYL5eMeFDj0R+lpC7oZyIl0/sNVmQDC6ckP7husZjc=
/// Private: wGS1qdJfYbWJsOUuP1IDgaJYpR+VaKZPVZvdmLjsH2Y=
#[allow(deprecated)]
pub async fn init_dev_env(config: &DefGuardConfig) {
info!("Initializing dev environment");
let pool = init_db(
Expand All @@ -648,6 +651,24 @@ pub async fn init_dev_env(config: &DefGuardConfig) {
.await
.expect("Failed to create admin user");

let ca = CertificateAuthority::new("Defguard Dev", "defguard-dev@defguard.net", 5000)
.expect("Failed to create CA");

initialize_current_settings(&pool)
.await
.expect("Could not initialize current settings in the database");
let mut settings = Settings::get_current_settings();
settings.ca_cert_der = Some(ca.cert_der().to_vec());
settings.ca_key_der = Some(ca.key_pair_der().to_vec());
settings.ca_expiry = Some(ca.expiry().expect("Failed to get CA expiry"));
settings.initial_setup_completed = true;
// This should possibly be initialized somehow differently in the future since we are deprecating the enrollment URL env var.
settings.public_proxy_url = config.enrollment_url.to_string();
settings.defguard_url = config.url.to_string();
update_current_settings(&pool, settings)
.await
.expect("Failed to update settings");

let mut transaction = pool
.begin()
.await
Expand Down
Loading