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
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ console = { version = "0.15.11" }
env_logger = { version = "0.11.5" }
log = { version = "0.4.22" }
openssl = { version = "0.10.75", optional = true }
rand = { version = "0.8" }
reqwest = { version = "0.12.28", default-features = false, features = [
"json",
"multipart",
Expand All @@ -35,6 +36,7 @@ tabled = "0.20.0"
chrono = "0.4.43"
futures = { version = "0.3" }
regex = { version = "1.12.3" }
regex-macro = { version = "0.3.0" }
iso8601-timestamp = { version = "0.2.17" }
toml = { version = "0.8.19" }
git2 = { version = "0.19.0", default-features = false, features = [
Expand Down
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod cmd;
pub mod complete;
pub mod opts;
pub mod sink;

Expand Down Expand Up @@ -60,7 +61,7 @@ impl fmt::Display for BuildInfo {
let cc = &self.git_commit[..8];
write!(
f,
" Built at: {}\n Version: {}\n Sha: {}",
"Renku CLI:\nBuilt at: {}\nVersion: {}\nSha: {}",
self.build_date, self.build_version, cc
)
}
Expand Down
52 changes: 3 additions & 49 deletions src/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ pub mod userdoc;
pub mod version;

use super::sink::{Error as SinkError, Sink};
use crate::cli::opts::{CommonOpts, ProxySetting};
use crate::cli::opts::CommonOpts;
use crate::data::renku_url::RenkuUrl;
use crate::httpclient::{self, Client, proxy};
use crate::httpclient::{self, Client};
use serde::Serialize;
use snafu::{ResultExt, Snafu};

const RENKULAB_IO: &str = "https://renkulab.io";
const ACCESS_TOKEN_ENV: &str = "RENKU_CLI_ACCESS_TOKEN";

pub struct Context {
pub opts: CommonOpts,
pub client: Client,
}

impl Context {
pub fn new(opts: &CommonOpts) -> Result<Context, CmdError> {
let base_url = get_renku_url(opts)?;
let at = std::env::var(ACCESS_TOKEN_ENV).ok();
let client = Client::new(base_url, proxy_settings(opts), None, false, at)
.context(ContextCreateSnafu)?;
let client = opts.create_client(None).context(ContextCreateSnafu)?;
Ok(Context {
opts: opts.clone(),
client,
Expand All @@ -51,46 +45,6 @@ impl Context {
}
}

fn get_renku_url(opts: &CommonOpts) -> Result<RenkuUrl, CmdError> {
match &opts.renku_url {
Some(u) => {
log::debug!("Use renku url from arguments: {}", u);
Ok(u.clone())
}
None => match std::env::var("RENKU_CLI_RENKU_URL").ok() {
Some(u) => {
log::debug!("Use renku url from env RENKU_CLI_RENKU_URL: {}", u);
RenkuUrl::parse(&u).map_err(|e| CmdError::ContextCreate {
source: httpclient::Error::UrlParse { source: e },
})
}
None => {
log::debug!("Use renku url: https://renkulab.io");
RenkuUrl::parse(RENKULAB_IO).map_err(|e| CmdError::ContextCreate {
source: httpclient::Error::UrlParse { source: e },
})
}
},
}
}

fn proxy_settings(opts: &CommonOpts) -> proxy::ProxySetting {
let user = opts.proxy_user.clone();
let password = opts.proxy_password.clone();
let prx = opts.proxy.clone();

log::debug!("Using proxy: {:?} @ {:?}", user, prx);
match prx {
None => proxy::ProxySetting::System,
Some(ProxySetting::None) => proxy::ProxySetting::None,
Some(ProxySetting::Custom { url }) => proxy::ProxySetting::Custom {
url: url.clone(),
user,
password,
},
}
}

#[derive(Debug, Snafu)]
pub enum CmdError {
#[snafu(display("ContextCreate - {}", source))]
Expand Down
41 changes: 39 additions & 2 deletions src/cli/cmd/job/start.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::httpclient::{self, data::SessionStartRequest};
use crate::{
cli::complete::complete_job_launcher_id,
data::submission_id::SubmissionId,
httpclient::{self, data::SessionStartRequest},
};

use super::Context;
use crate::cli::sink::Error as SinkError;

use clap::{Parser, ValueHint};
use clap_complete::ArgValueCompleter;
use ulid::Ulid;

use snafu::{ResultExt, Snafu};
Expand All @@ -14,8 +19,23 @@ use snafu::{ResultExt, Snafu};
#[derive(Parser, Debug)]
pub struct Input {
/// The launcher to use for launching the job.
#[arg(value_hint=ValueHint::Other)]
#[arg(long, value_hint=ValueHint::Other, add = ArgValueCompleter::new(complete_job_launcher_id))]
pub launcher: Ulid,

/// A submission id allows to deduplicate same job submissions. If
/// missing, a random one is generated. It must be at least 4
/// characters, starting with a lowercase letter, followed by
/// alphanumeric characters (including the dash).
#[arg(long)]
pub submission_id: Option<SubmissionId>,

/// Overwrite the command that is set in the launcher.
#[arg(long)]
pub command: Vec<String>,

/// These arguments are passed to the renku job command.
#[arg(trailing_var_arg = true, allow_hyphen_values = true, num_args = 0.., value_name = "ARGS")]
pub passthrough: Vec<String>,
}

#[derive(Debug, Snafu)]
Expand All @@ -29,9 +49,26 @@ pub enum Error {

impl Input {
pub async fn exec(&self, ctx: Context) -> Result<(), Error> {
let submission_id = self
.submission_id
.clone()
.unwrap_or_else(SubmissionId::random);
let cmd = if self.command.is_empty() {
None
} else {
Some(self.command.clone())
};
let args = if self.passthrough.is_empty() {
None
} else {
Some(self.passthrough.clone())
};
let req = SessionStartRequest {
launcher_id: self.launcher.to_string(),
session_type: "non-interactive".into(),
submission_id: Some(submission_id),
job_args_override: args,
job_command_override: cmd,
};
let result = ctx
.client
Expand Down
50 changes: 21 additions & 29 deletions src/cli/cmd/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ use std::fmt;

/// Prints version about server and client.
///
/// Queries the server for its version information and prints more
/// version details about this client.
/// Prints version details about this client and can also query the renku platform for its verion.
#[derive(Parser, Debug, PartialEq)]
pub struct Input {
/// Only show the client version and don't request server side
/// version information.
/// Also request the version on the renku platform.
#[arg(long, default_value_t = false)]
pub client_only: bool,
pub with_server: bool,
}

#[derive(Debug, Snafu)]
Expand All @@ -32,44 +30,38 @@ pub enum Error {

impl Input {
pub async fn exec(&self, ctx: &Context) -> Result<(), Error> {
if self.client_only {
let vinfo = BuildInfo::default();
ctx.write_result(&vinfo).await.context(WriteResultSnafu)?;
} else {
if self.with_server {
let result = ctx.client.version().await.context(HttpClientSnafu)?;
let urlstr = ctx.renku_url().as_str();
let vinfo = Versions::create(result, urlstr);
ctx.write_result(&vinfo).await.context(WriteResultSnafu)?;
let info = Versions::create(result);
ctx.write_result(&info).await.context(WriteResultSnafu)?;
} else {
let build_info = BuildInfo::default();
ctx.write_result(&build_info)
.await
.context(WriteResultSnafu)?;
}
Ok(())
}
}

#[derive(Debug, Serialize)]
pub struct Versions<'a> {
pub client: BuildInfo,
pub server: VersionInfo,
pub renku_url: &'a str,
pub struct Versions {
pub renku_cli: BuildInfo,
pub renku_platform: VersionInfo,
}
impl Versions<'_> {
pub fn create(server: VersionInfo, renku_url: &'_ str) -> Versions<'_> {
impl Versions {
pub fn create(renku_platform: VersionInfo) -> Versions {
Versions {
client: BuildInfo::default(),
server,
renku_url,
renku_cli: BuildInfo::default(),
renku_platform,
}
}
}

impl fmt::Display for Versions<'_> {
impl fmt::Display for Versions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let hc = &self.server.search.head_commit[..8];
write!(
f,
"Client:\n{}\n\nRenku @ {}\n Data Services: {}\n Search Services: {} ({})",
self.client, self.renku_url, self.server.data.version, self.server.search.version, hc
)
write!(f, "{}\n\n{}", self.renku_cli, self.renku_platform)
}
}

impl Sink for Versions<'_> {}
impl Sink for Versions {}
Loading
Loading