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/.config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sbatch_script_template = """
#!/bin/bash
#SBATCH --job-name={{name}}
#SBATCH --ntasks=1
#SBATCH --time=24:00:00
#SBATCH --time=10:00:00
srun {% if environment_file %}--environment={{environment_file}}{% endif %} {% if coman_squash %}/coman/coman exec {% endif %}{{command}}
"""

Expand Down
2 changes: 1 addition & 1 deletion coman/src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ pub async fn check_update() -> Result<()> {
> TimeDelta::hours(config.values.update_check_interval_hours as i64)
{
println!("checking for updates");
update()?;
tokio::task::spawn_blocking(update).await??;
std::fs::write(&stamp_path, Local::now().to_rfc3339())?;
}
Ok(())
Expand Down
6 changes: 2 additions & 4 deletions coman/src/components/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ impl MockComponent for StatusBar {
impl Component<Msg, UserEvent> for StatusBar {
fn on(&mut self, ev: Event<UserEvent>) -> Option<Msg> {
match ev {
Event::Tick => {
if self.last_updated.elapsed() > self.status_clear_time {
self.current_status = None;
}
Event::Tick if self.last_updated.elapsed() > self.status_clear_time => {
self.current_status = None;
}
Event::User(UserEvent::Status(status)) => {
self.current_status = Some(status);
Expand Down
16 changes: 14 additions & 2 deletions coman/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use color_eyre::{
use directories::ProjectDirs;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use strum_macros::{EnumString, VariantNames};
use strum_macros::{EnumIter, EnumString, VariantNames};
use toml_edit::DocumentMut;

const DEFAULT_CONFIG_TOML: &str = include_str!("../.config/config.toml");
Expand All @@ -33,7 +33,7 @@ pub struct SystemDescription {
pub architecture: Vec<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize, Default, strum::Display, EnumString, VariantNames)]
#[derive(Clone, Debug, Serialize, Deserialize, Default, strum::Display, EnumString, VariantNames, EnumIter)]
#[strum(serialize_all = "lowercase")]
#[allow(clippy::upper_case_acronyms)]
pub enum ComputePlatform {
Expand Down Expand Up @@ -331,6 +331,18 @@ impl Config {
let _cfg: ComanConfig = builder.build()?.try_deserialize().wrap_err("invalid config")?;
Ok(())
}

// Returns tuple of bool saying whether a values is set in (default, global, project local) config
pub fn value_source(&self, key_path: &str) -> Result<(bool, bool, bool)> {
Ok((
self.default_layer.get(key_path).is_some(),
self.global_layer.get(key_path).unwrap_or_default().is_some(),
self.project_layer
.as_ref()
.map(|l| l.get(key_path).unwrap_or_default().is_some())
.unwrap_or(false),
))
}
}

pub fn global_config_layer() -> Result<Layer> {
Expand Down
21 changes: 18 additions & 3 deletions coman/src/cscs/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use itertools::Itertools;
use regex::Regex;
use reqwest::Url;
use sha2::{Digest, Sha256};
use strum::IntoEnumIterator;
use tarpc::{client, context, serde_transport, tokio_serde::formats::Bincode};
use tokio::{
fs::File,
Expand Down Expand Up @@ -84,9 +85,23 @@ pub(crate) async fn cscs_login(client_id: String, client_secret: String) -> Resu
store_secret(CLIENT_ID_SECRET_NAME, client_id_secret.clone()).await?;
let client_secret_secret = Secret::new(client_secret);
store_secret(CLIENT_SECRET_SECRET_NAME, client_secret_secret.clone()).await?;
client_credentials_login(client_id_secret, client_secret_secret)
.await
.map(|_| ())
let token = client_credentials_login(client_id_secret, client_secret_secret).await?;

// figure out what platform the user has access to and set it in config
let mut config = Config::new()?;
let source = config.value_source("cscs.current_platform")?;
if source.1 || source.2 {
// don't override setting if it's already provided
return Ok(());
}
for platform in ComputePlatform::iter() {
let api_client = CscsApi::new(token.0.0.clone(), Some(platform.clone())).unwrap();
if (api_client.list_systems().await).is_ok() {
config.set("cscs.current_platform", platform.to_string(), true)?;
break;
}
}
Ok(())
}

#[allow(dead_code)]
Expand Down