Skip to content

Commit 5be1652

Browse files
authored
Gateway wizard (#1919)
* issue certificates for gateway * remove gw tokens, cleanup * cleanup * clippy * sqlx prepare * consts * update protobufs * proxy wizard backend * proxy wizard frontend * remove eprintln * fix lint * fix * fix 2 * gateway wizard 1 * fix domain validator * fixes, gateway names, navigation * routetree * fix frontend * after merge fix * proto update * fix linters * fix sqlx fixtures
1 parent d5d856d commit 5be1652

55 files changed

Lines changed: 1979 additions & 467 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.sqlx/query-cd6c70e9b46c5cdce053d6f0772612388c1e322dbc7ce93d92251b3a82caabef.json renamed to .sqlx/query-5af0fbf61295a5a23149c6248ea0b4a7afcbee1b63e34932c143f4697a0bc2cc.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-9655c2e6a8f749fe1ea966dcdc0ea2080a4c27137278b2fb761d3b279b69f9db.json renamed to .sqlx/query-ae3e3cef524f2a911808bf72e7c57b7f32e22adefc9b9185a9b3cd80c169a6e2.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-671c3ef062fa5c901d26adb86c75b7ccad57d9cc9caa41502cbe85c6eafb087e.json renamed to .sqlx/query-b43694450d7abe3b93ea88fa7c95c38d3e2deb43d5ca3458724deb3ead69389a.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-d10c9a7b0b391aeb8b4869f6bddf997807b66e0b532da747b146513c34e15c5c.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-e9ca71b61f7a3736ca335d90aca36ab5a93dc8a00ad622267f13b3cd4cdb4a5a.json

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-16802280f46083a640c0f084479e4aee1d1b2098133ff953c1188346c7cb252e.json renamed to .sqlx/query-ed3266f5f0d7b1613ad8745c9be953a7d9ef0becedf668c1d2225a1673003c77.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/defguard/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ dotenvy = "0.15"
2626
secrecy = { workspace = true }
2727
tokio = { workspace = true }
2828
tracing = { workspace = true }
29+
tracing-subscriber = { workspace = true }

crates/defguard/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use tokio::sync::{
4747
broadcast,
4848
mpsc::{channel, unbounded_channel},
4949
};
50+
use tracing_subscriber::util::SubscriberInitExt;
5051

5152
#[macro_use]
5253
extern crate tracing;
@@ -61,11 +62,13 @@ async fn main() -> Result<(), anyhow::Error> {
6162
.set(config.clone())
6263
.expect("Failed to initialize server config.");
6364

64-
// initialize tracing with version formatter
65-
defguard_version::tracing::init(
66-
defguard_version::Version::parse(VERSION)?,
65+
let subscriber = tracing_subscriber::registry();
66+
defguard_version::tracing::with_version_formatters(
67+
&defguard_version::Version::parse(VERSION)?,
6768
&config.log_level,
68-
)?;
69+
subscriber,
70+
)
71+
.init();
6972

7073
info!("Starting ... version v{VERSION}");
7174
debug!("Using config: {config:?}");

crates/defguard_common/src/db/models/gateway.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct Gateway<I = NoId> {
1818
pub has_certificate: bool,
1919
pub certificate_expiry: Option<NaiveDateTime>,
2020
pub version: Option<String>,
21+
pub name: String,
2122
}
2223

2324
impl<I> Gateway<I> {
@@ -34,7 +35,7 @@ impl<I> Gateway<I> {
3435

3536
impl Gateway {
3637
#[must_use]
37-
pub fn new<S: Into<String>>(network_id: Id, url: S) -> Self {
38+
pub fn new<S: Into<String>>(network_id: Id, url: S, name: S) -> Self {
3839
Self {
3940
id: NoId,
4041
network_id,
@@ -45,6 +46,7 @@ impl Gateway {
4546
has_certificate: false,
4647
certificate_expiry: None,
4748
version: None,
49+
name: name.into(),
4850
}
4951
}
5052
}
@@ -120,6 +122,18 @@ impl Gateway<Id> {
120122

121123
Ok(())
122124
}
125+
126+
// TODO: Split the URL into address and port fields just like in proxy
127+
pub async fn find_by_url<'e, E>(executor: E, url: &str) -> Result<Option<Self>, sqlx::Error>
128+
where
129+
E: PgExecutor<'e>,
130+
{
131+
let record = query_as!(Self, "SELECT * FROM gateway WHERE url = $1", url)
132+
.fetch_optional(executor)
133+
.await?;
134+
135+
Ok(record)
136+
}
123137
}
124138

125139
impl fmt::Display for Gateway<Id> {

0 commit comments

Comments
 (0)