Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
439 changes: 300 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ license = "MIT OR Apache-2.0"
name = "omnect-ui"
readme = "README.md"
repository = "git@github.com:omnect/omnect-ui.git"
version = "1.0.6"
version = "1.1.0"
build = "src/build.rs"

[dependencies]
actix-cors = { version = "0.7", default-features = false }
actix-files = { version = "0.6", default-features = false }
actix-multipart = { version = "0.7", default-features = false, features = [
"tempfile",
"derive"
]}
actix-session = { version = "0.10", features = ["cookie-session"] }
] }
actix-server = { version = "2.6", default-features = false }
actix-session = { version = "0.11", features = ["cookie-session"] }
actix-web = { version = "4.11", default-features = false, features = [
"macros",
"rustls-0_23",
Expand All @@ -37,6 +38,7 @@ log-panics = { version = "2.1", default-features = false, features = [
mockall = { version = "0.13", optional = true, default-features = false }
rand_core = { version = "0.9", default-features = false, features = ["std"] }
reqwest = { version = "0.12.23", default-features = false, features = ["json", "rustls-tls"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't it be just 0.12 to match the other entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we need exactly that version

rust-ini = { version = "0.21", default-features = false }
rustls = { version = "0.23", default-features = false, features = [
"aws_lc_rs",
"std",
Expand All @@ -51,11 +53,13 @@ serde_json = { version = "1.0", default-features = false, features = [
"raw_value",
] }
serde_repr = { version = "0.1", default-features = false }
serde_valid = { version = "2.0", default-features = false }
tokio = { version = "1.45", default-features = false, features = [
"macros",
"net",
"process",
] }
trait-variant = { version = "0.1" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default-features = false is missing

uuid = { version = "1.17", default-features = false, features = [
"v4",
] }
Expand All @@ -66,5 +70,5 @@ mock = ["dep:mockall"]
[dev-dependencies]
actix-http = "3.11"
actix-service = "2.0"
tempfile = "3.20"
mockall_double = "0.3"
tempfile = "3.20"
19 changes: 14 additions & 5 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"linter": {
"enabled": true,
"rules": {
Expand All @@ -10,23 +10,32 @@
},
"style": {
"noParameterAssign": "off",
"useImportType": "off"
"useImportType": "off",
"useAsConstAssertion": "error",
"useDefaultParameterLast": "error",
"useEnumInitializers": "error",
"useSelfClosingElements": "error",
"useSingleVarDeclarator": "error",
"noUnusedTemplateLiteral": "error",
"useNumberNamespace": "error",
"noInferrableTypes": "error",
"noUselessElse": "error"
},
"complexity": {
"noStaticOnlyClass": "off",
"useLiteralKeys": "off",
"noForEach": "off"
}
},
"ignore": []
"includes": ["**"]
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 150,
"ignore": []
"includes": ["**"]
},
"javascript": {
"formatter": {
Expand All @@ -39,7 +48,7 @@
}
},
"files": {
"ignore": ["./.vscode*"],
"includes": ["**", "!.vscode*"],
"maxSize": 31457280
}
}
1 change: 1 addition & 0 deletions build-and-run-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ docker run --rm \
-v $(pwd)/temp:/cert \
-v /tmp:/socket \
-v $(pwd)/temp/data:/data \
-v $(pwd)/temp/network:/network \
-u $(id -u):$(id -g) \
-e RUST_LOG=debug \
-e UI_PORT=1977 \
Expand Down
14 changes: 14 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
auth::TokenManager,
common::{config_path, data_path, host_data_path, tmp_path, validate_password},
keycloak_client::SingleSignOnProvider,
network::{NetworkConfig, NetworkConfigService},
omnect_device_service_client::{DeviceServiceClient, FactoryReset, LoadUpdate, RunUpdate},
};
use actix_files::NamedFile;
Expand Down Expand Up @@ -146,6 +147,7 @@ where
pub async fn token(session: Session, token_manager: web::Data<TokenManager>) -> impl Responder {
debug!("token() called");

NetworkConfigService::cancel_rollback();
Self::session_token(session, token_manager)
}

Expand Down Expand Up @@ -275,6 +277,18 @@ where
HttpResponse::Ok().finish()
}

pub async fn set_network_config(
network_config: web::Json<NetworkConfig>,
api: web::Data<Self>,
) -> impl Responder {
debug!("set_network_config() called");

Self::handle_service_result(
NetworkConfigService::set_network_config(&api.service_client, &network_config).await,
"set_network_config",
)
}

async fn validate_token_and_claims(&self, token: &str) -> Result<()> {
let claims = self.single_sign_on.verify_token(token).await?;
let Some(tenant_list) = &claims.tenant_list else {
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn create_frontend_config_file() -> Result<()> {
.context("failed to create frontend config file")?;

config_file
.write_all(keycloak_client::config().as_bytes())
.write_all(keycloak_client::KeycloakProvider::config().as_bytes())
.context("failed to write frontend config file")
}

Expand Down
18 changes: 10 additions & 8 deletions src/keycloak_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use base64::{Engine, prelude::BASE64_STANDARD};
use jwt_simple::prelude::{RS256PublicKey, RSAPublicKeyLike};
#[cfg(feature = "mock")]
use mockall::automock;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use trait_variant::make;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TokenClaims {
Expand All @@ -25,9 +27,9 @@ macro_rules! keycloak_url {
}};
}

#[make(Send + Sync)]
#[cfg_attr(feature = "mock", automock)]
#[allow(async_fn_in_trait)]
pub trait SingleSignOnProvider: Send + Sync {
pub trait SingleSignOnProvider {
async fn verify_token(&self, token: &str) -> anyhow::Result<TokenClaims>;
}

Expand All @@ -39,12 +41,17 @@ pub struct KeycloakProvider {
impl Default for KeycloakProvider {
fn default() -> Self {
Self {
client: reqwest::Client::new(),
client: Client::new(),
}
}
}

impl KeycloakProvider {
pub fn config() -> String {
let keycloak_url = &keycloak_url!();
format!("window.__APP_CONFIG__ = {{KEYCLOAK_URL:\"{keycloak_url}\"}};")
}

async fn realm_public_key(&self) -> Result<RS256PublicKey> {
let resp = self
.client
Expand All @@ -71,8 +78,3 @@ impl SingleSignOnProvider for KeycloakProvider {
Ok(claims.custom)
}
}

pub fn config() -> String {
let keycloak_url = &keycloak_url!();
format!("window.__APP_CONFIG__ = {{KEYCLOAK_URL:\"{keycloak_url}\"}};")
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pub mod common;
pub mod http_client;
pub mod keycloak_client;
pub mod middleware;
pub mod network;
pub mod omnect_device_service_client;
Loading
Loading