Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion coman/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coman"
version = "0.8.0"
version = "0.8.1"
edition = "2024"
description = "Compute Manager for managing HPC compute"
authors = ["Ralf Grubenmann <ralf.grubenmann@sdsc.ethz.ch>"]
Expand Down
4 changes: 4 additions & 0 deletions coman/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub enum ComputePlatform {

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct CscsConfig {
#[serde(default)]

Choose a reason for hiding this comment

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

The serde(default) attribute should be applied to all fields that can be missing from the config file.

#ai-review-inline

pub client_id: Option<String>,

Choose a reason for hiding this comment

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

Consider adding documentation to explain the purpose of client_id.

#ai-review-inline

#[serde(default)]

Choose a reason for hiding this comment

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

The serde(default) attribute should be applied to all fields that can be missing from the config file.

#ai-review-inline

pub client_secret: Option<String>,

Choose a reason for hiding this comment

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

Consider adding documentation to explain the purpose of client_secret.

#ai-review-inline

#[serde(default)]
pub current_system: String,
#[serde(default)]
Expand Down
25 changes: 17 additions & 8 deletions coman/src/cscs/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ use crate::{
const CSCS_MAX_DIRECT_SIZE: usize = 5242880;

async fn get_access_token() -> Result<Secret> {
let client_id = match get_secret(CLIENT_ID_SECRET_NAME).await {
Ok(Some(client_id)) => client_id,
Ok(None) => Err(eyre!("not logged in"))?,
Err(e) => Err(e)?,
let config = Config::new()?;

Choose a reason for hiding this comment

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

Consider extracting config loading into a separate function for better readability and testability.

Suggested change
let config = Config::new()?;
let config = Config::new()?;

#ai-review-inline

let client_id = if let Some(client_id) = config.values.cscs.client_id {
Secret(client_id)
} else {
match get_secret(CLIENT_ID_SECRET_NAME).await {
Ok(Some(client_id)) => client_id,
Ok(None) => Err(eyre!("not logged in"))?,
Err(e) => Err(e)?,
}
};
let client_secret = match get_secret(CLIENT_SECRET_SECRET_NAME).await {
Ok(Some(client_secret)) => client_secret,
Ok(None) => Err(eyre!("not logged in"))?,
Err(e) => Err(e)?,
let client_secret = if let Some(client_secret) = config.values.cscs.client_secret {
Secret(client_secret)
} else {
match get_secret(CLIENT_SECRET_SECRET_NAME).await {
Ok(Some(client_secret)) => client_secret,
Ok(None) => Err(eyre!("not logged in"))?,
Err(e) => Err(e)?,
}
};
let token = client_credentials_login(client_id, client_secret).await?;
Ok(token.0)
Expand Down