Skip to content

Commit f301190

Browse files
authored
allow storing client_id and client_secret in coman config for envs without keyring) (#61)
1 parent 34c3280 commit f301190

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

coman/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coman"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
edition = "2024"
55
description = "Compute Manager for managing HPC compute"
66
authors = ["Ralf Grubenmann <ralf.grubenmann@sdsc.ethz.ch>"]

coman/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub enum ComputePlatform {
4545

4646
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
4747
pub struct CscsConfig {
48+
#[serde(default)]
49+
pub client_id: Option<String>,
50+
#[serde(default)]
51+
pub client_secret: Option<String>,
4852
#[serde(default)]
4953
pub current_system: String,
5054
#[serde(default)]

coman/src/cscs/handlers.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,24 @@ use crate::{
5757
const CSCS_MAX_DIRECT_SIZE: usize = 5242880;
5858

5959
async fn get_access_token() -> Result<Secret> {
60-
let client_id = match get_secret(CLIENT_ID_SECRET_NAME).await {
61-
Ok(Some(client_id)) => client_id,
62-
Ok(None) => Err(eyre!("not logged in"))?,
63-
Err(e) => Err(e)?,
60+
let config = Config::new()?;
61+
let client_id = if let Some(client_id) = config.values.cscs.client_id {
62+
Secret(client_id)
63+
} else {
64+
match get_secret(CLIENT_ID_SECRET_NAME).await {
65+
Ok(Some(client_id)) => client_id,
66+
Ok(None) => Err(eyre!("not logged in"))?,
67+
Err(e) => Err(e)?,
68+
}
6469
};
65-
let client_secret = match get_secret(CLIENT_SECRET_SECRET_NAME).await {
66-
Ok(Some(client_secret)) => client_secret,
67-
Ok(None) => Err(eyre!("not logged in"))?,
68-
Err(e) => Err(e)?,
70+
let client_secret = if let Some(client_secret) = config.values.cscs.client_secret {
71+
Secret(client_secret)
72+
} else {
73+
match get_secret(CLIENT_SECRET_SECRET_NAME).await {
74+
Ok(Some(client_secret)) => client_secret,
75+
Ok(None) => Err(eyre!("not logged in"))?,
76+
Err(e) => Err(e)?,
77+
}
6978
};
7079
let token = client_credentials_login(client_id, client_secret).await?;
7180
Ok(token.0)

0 commit comments

Comments
 (0)