-
Notifications
You must be signed in to change notification settings - Fork 0
allow storing client_id and client_secret in coman config for envs without keyring #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,10 @@ pub enum ComputePlatform { | |
|
|
||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct CscsConfig { | ||
| #[serde(default)] | ||
| pub client_id: Option<String>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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()?; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
#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) | ||||||
|
|
||||||
There was a problem hiding this comment.
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