Skip to content

Commit c9086e0

Browse files
committed
make 'account' a global option, add it for job start and make it optional
1 parent fcbcda0 commit c9086e0

9 files changed

Lines changed: 42 additions & 36 deletions

File tree

coman/src/cli.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
};
1010

1111
#[derive(Subcommand, Debug)]
12+
#[allow(clippy::large_enum_variant)]
1213
pub enum CliCommands {
1314
#[clap(about = "Show version and config file locations")]
1415
Version,
@@ -20,6 +21,8 @@ pub enum CliCommands {
2021
system: Option<String>,
2122
#[clap(short, long, ignore_case=true, value_parser=clap::builder::PossibleValuesParser::new(ComputePlatform::VARIANTS).map(|s|s.parse::<ComputePlatform>().unwrap()),help = "override compute platform (one of 'hpc', 'ml' or 'cw')")]
2223
platform: Option<ComputePlatform>,
24+
#[clap(short, long, help = "override compute account to use (project or user)")]
25+
account: Option<String>,
2326
},
2427
#[clap(about = "Create a new project configuration file")]
2528
Init {
@@ -90,16 +93,17 @@ pub enum CscsFileCommands {
9093
List { path: PathBuf },
9194
#[clap(alias("dl"), about = "Download a remote file [aliases: dl]")]
9295
Download {
93-
#[clap(short, long, help = "account/project to use")]
94-
account: Option<String>,
96+
#[clap(help = "The path in the cluster to download")]
9597
remote: PathBuf,
98+
#[clap(help = "The local path to download the file to")]
9699
local: PathBuf,
97100
},
98101
#[clap(alias("ul"), about = "Upload a file to remote storage [aliases: ul]")]
99102
Upload {
100-
#[clap(short, long, help = "account/project to use")]
101-
account: Option<String>,
103+
#[clap(help = "The local path to upload to the cluster")]
102104
local: PathBuf,
105+
106+
#[clap(help = "the path in the cluster to upload to")]
103107
remote: PathBuf,
104108
},
105109
}

coman/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct CscsConfig {
4141
#[serde(default)]
4242
pub current_platform: ComputePlatform,
4343
#[serde(default)]
44-
pub account: String,
44+
pub account: Option<String>,
4545
#[serde(default)]
4646
pub sbatch_script_template: String,
4747
#[serde(default)]

coman/src/cscs/api_client.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl CscsApi {
381381
pub async fn start_job(
382382
&self,
383383
system_name: &str,
384+
account: Option<String>,
384385
name: &str,
385386
script_path: PathBuf,
386387
envvars: HashMap<String, String>,
@@ -390,6 +391,7 @@ impl CscsApi {
390391
let result = post_compute_system_job(
391392
&self.client,
392393
system_name,
394+
account,
393395
name,
394396
None,
395397
Some(script_path),
@@ -472,15 +474,10 @@ impl CscsApi {
472474
pub async fn transfer_upload(
473475
&self,
474476
system_name: &str,
475-
account: &str,
477+
account: Option<String>,
476478
path: PathBuf,
477479
size: i64,
478480
) -> Result<(i64, S3Upload)> {
479-
if account.is_empty() {
480-
return Err(eyre!(
481-
"An account is required, set it in the config file or with the --account flag"
482-
));
483-
}
484481
let job = post_filesystem_transfer_upload(&self.client, system_name, account, path, size)
485482
.await
486483
.wrap_err("couldn't upload file")?;
@@ -497,12 +494,12 @@ impl CscsApi {
497494
.wrap_err("couldn't download file")?;
498495
Ok(content)
499496
}
500-
pub async fn transfer_download(&self, system_name: &str, account: &str, path: PathBuf) -> Result<(i64, Url)> {
501-
if account.is_empty() {
502-
return Err(eyre!(
503-
"An account is required, set it in the config file or with the --account flag"
504-
));
505-
}
497+
pub async fn transfer_download(
498+
&self,
499+
system_name: &str,
500+
account: Option<String>,
501+
path: PathBuf,
502+
) -> Result<(i64, Url)> {
506503
let job = post_filesystem_transfer_download(&self.client, system_name, account, path)
507504
.await
508505
.wrap_err("couldn't transfer file")?;

coman/src/cscs/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub(crate) async fn cli_cscs_job_log(
9999
}
100100
}
101101

102+
#[allow(clippy::too_many_arguments)]
102103
pub(crate) async fn cli_cscs_job_start(
103104
script_file: Option<PathBuf>,
104105
image: Option<DockerImageUrl>,
@@ -107,8 +108,9 @@ pub(crate) async fn cli_cscs_job_start(
107108
env: Vec<(String, String)>,
108109
system: Option<String>,
109110
platform: Option<ComputePlatform>,
111+
account: Option<String>,
110112
) -> Result<()> {
111-
cscs_start_job(script_file, image, command, workdir, env, system, platform).await
113+
cscs_start_job(script_file, image, command, workdir, env, system, platform, account).await
112114
}
113115

114116
pub(crate) async fn cli_cscs_job_cancel(

coman/src/cscs/handlers.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub async fn cscs_job_cancel(job_id: i64, system: Option<String>, platform: Opti
146146
}
147147
}
148148

149+
#[allow(clippy::too_many_arguments)]
149150
pub async fn cscs_start_job(
150151
script_file: Option<PathBuf>,
151152
image: Option<DockerImageUrl>,
@@ -154,12 +155,14 @@ pub async fn cscs_start_job(
154155
env: Vec<(String, String)>,
155156
system: Option<String>,
156157
platform: Option<ComputePlatform>,
158+
account: Option<String>,
157159
) -> Result<()> {
158160
match get_access_token().await {
159161
Ok(access_token) => {
160162
let api_client = CscsApi::new(access_token.0, platform).unwrap();
161163
let config = Config::new().unwrap();
162164
let current_system = &system.unwrap_or(config.cscs.current_system);
165+
let account = account.or(config.cscs.account);
163166
let user_info = api_client.get_userinfo(current_system).await?;
164167
let current_system_info = api_client.get_system(current_system).await?;
165168
let scratch = match current_system_info {
@@ -245,7 +248,7 @@ pub async fn cscs_start_job(
245248

246249
// start job
247250
api_client
248-
.start_job(current_system, &name, script_path, envvars)
251+
.start_job(current_system, account, &name, script_path, envvars)
249252
.await?;
250253
Ok(())
251254
}
@@ -295,9 +298,8 @@ pub async fn cscs_file_download(
295298
Ok(None)
296299
} else {
297300
// download via s3
298-
let job_data = api_client
299-
.transfer_download(current_system, &account.unwrap_or(config.cscs.account), remote)
300-
.await?;
301+
let account = account.or(config.cscs.account);
302+
let job_data = api_client.transfer_download(current_system, account, remote).await?;
301303
Ok(Some((job_data.0, job_data.1, size)))
302304
}
303305
}
@@ -333,13 +335,9 @@ pub async fn cscs_file_upload(
333335
Ok(None)
334336
} else {
335337
// upload via s3
338+
let account = account.or(config.cscs.account);
336339
let transfer_data = api_client
337-
.transfer_upload(
338-
&config.cscs.current_system,
339-
&account.unwrap_or(config.cscs.account),
340-
remote,
341-
size as i64,
342-
)
340+
.transfer_upload(&config.cscs.current_system, account, remote, size as i64)
343341
.await?;
344342

345343
Ok(Some(transfer_data))

coman/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async fn main() -> Result<()> {
5757
command: cscs_command,
5858
system,
5959
platform,
60+
account,
6061
} => match cscs_command {
6162
cli::CscsCommands::Login => cli_cscs_login().await?,
6263
cli::CscsCommands::Job { command } => match command {
@@ -69,15 +70,17 @@ async fn main() -> Result<()> {
6970
command,
7071
workdir,
7172
env,
72-
} => cli_cscs_job_start(script_file, image, command, workdir, env, system, platform).await?,
73+
} => {
74+
cli_cscs_job_start(script_file, image, command, workdir, env, system, platform, account).await?
75+
}
7376
cli::CscsJobCommands::Cancel { job_id } => cli_cscs_job_cancel(job_id, system, platform).await?,
7477
},
7578
cli::CscsCommands::File { command } => match command {
7679
cli::CscsFileCommands::List { path } => cli_cscs_file_list(path, system, platform).await?,
77-
cli::CscsFileCommands::Download { remote, local, account } => {
80+
cli::CscsFileCommands::Download { remote, local } => {
7881
cli_cscs_file_download(remote, local, account, system, platform).await?
7982
}
80-
cli::CscsFileCommands::Upload { local, remote, account } => {
83+
cli::CscsFileCommands::Upload { local, remote } => {
8184
cli_cscs_file_upload(local, remote, account, system, platform).await?
8285
}
8386
},

firecrest_client/src/compute_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
pub async fn post_compute_system_job(
1515
client: &FirecrestClient,
1616
system_name: &str,
17+
account: Option<String>,
1718
name: &str,
1819
script: Option<&str>,
1920
script_path: Option<PathBuf>,
@@ -37,6 +38,7 @@ pub async fn post_compute_system_job(
3738
.map_err(|_| eyre!("couldn't convert working dir path"))?
3839
.unwrap_or("/".to_owned()),
3940
env: Some(JobDescriptionModelEnv::Object(json!(envvars))),
41+
account,
4042
..Default::default()
4143
},
4244
};

firecrest_client/src/filesystem_api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub async fn post_filesystem_ops_upload(
139139
pub async fn post_filesystem_transfer_upload(
140140
client: &FirecrestClient,
141141
system_name: &str,
142-
account: &str,
142+
account: Option<String>,
143143
path: PathBuf,
144144
size: i64,
145145
) -> Result<UploadFileResponse> {
@@ -150,7 +150,7 @@ pub async fn post_filesystem_transfer_upload(
150150
file_size: Some(size),
151151
..Default::default()
152152
}),
153-
account: Some(account.to_owned()),
153+
account,
154154
};
155155
let body_json = serde_json::to_string(&body)?;
156156
let response = client
@@ -194,14 +194,14 @@ pub async fn get_filesystem_ops_download(client: &FirecrestClient, system_name:
194194
pub async fn post_filesystem_transfer_download(
195195
client: &FirecrestClient,
196196
system_name: &str,
197-
account: &str,
197+
account: Option<String>,
198198
path: PathBuf,
199199
) -> Result<DownloadFileResponse> {
200200
let file_path = path.as_os_str().to_str().ok_or(eyre!("couldn't cast path to string"))?;
201201
let body = PostFileDownloadRequest {
202202
source_path: Some(file_path.to_owned()),
203203
transfer_directives: PostFileDownloadRequestTransferDirectives::S3(S3TransferRequest::default()),
204-
account: Some(account.to_owned()),
204+
account,
205205
};
206206
let body_json = serde_json::to_string(&body)?;
207207
let response = client

firecrest_client/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! AUTO-GENERATED CODE - DO NOT EDIT!
1010
//!
1111
//! FirecREST
12-
//! Source: /tmp/.tmpJ9quLA.json
12+
//! Source: /tmp/.tmp2nZAlD.json
1313
//! Version: 2.4.1
1414
//! Generated by `oas3-gen v0.21.1`
1515
//!

0 commit comments

Comments
 (0)