diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7cae4d..e1cb28cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format of this file is based on [Keep a Changelog](https://keepachangelog.co ## [Unreleased] - Update all dependencies, except `hyper` (#260) +- Allow overriding the token through an argument or envvar (#261) ## [2.11.0] diff --git a/src/auth.rs b/src/auth.rs index bd022e97..9b9f88ac 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -103,22 +103,35 @@ pub async fn handle_login_command(args: Arguments) -> Result<(), Error> { Ok(()) } -/// Logout from Fiberplane and delete the API Token from the config file +/// Invalidate the API token. +/// +/// If a token is set using the `--token` flag, then that will be used, +/// otherwise it will use the token from the config file. The token will also be +/// removed from the config file if that was used. pub async fn handle_logout_command(args: Arguments) -> Result<(), Error> { - let mut config = Config::load(args.config).await?; + if let Some(token) = args.token { + let api_config = api_client_configuration_from_token(&token, args.base_url)?; - match config.api_token { - Some(token) => { - let api_config = api_client_configuration_from_token(&token, args.base_url)?; - logout(&api_config).await?; + logout(&api_config).await?; - config.api_token = None; - config.save().await?; + info!("You are logged out"); + } else { + let mut config = Config::load(args.config).await?; - info!("You are logged out"); - } - None => { - warn!("You are already logged out"); + match config.api_token { + Some(token) => { + let api_config = api_client_configuration_from_token(&token, args.base_url)?; + + logout(&api_config).await?; + + config.api_token = None; + config.save().await?; + + info!("You are logged out"); + } + None => { + warn!("You are already logged out"); + } } } diff --git a/src/config.rs b/src/config.rs index e6925ca7..3f1ccf07 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,18 +78,34 @@ fn default_config_file_path() -> PathBuf { .join("config.toml") } +/// Returns a ApiClient with the token set. If `token` is `Some` then that will +/// be used, otherwise the config will be used for the token. pub(crate) async fn api_client_configuration( + token: Option, config_path: Option, base_url: Url, ) -> Result { - let token = Config::load(config_path).await?.api_token.ok_or_else(|| { - anyhow!("Must be logged in to run this command. Please run `fp login` first.") - })?; + let token = { + if let Some(token) = token { + // an override has been specified, use that + token + } else { + // no override, so try loading the config + let config = Config::load(config_path).await?; + if let Some(token) = config.api_token { + token + } else { + return Err(anyhow!( + "Must be logged in to run this command. Please run `fp login` first." + )); + } + } + }; api_client_configuration_from_token(&token, base_url) } -pub(crate) fn api_client_configuration_from_token(token: &str, base_url: Url) -> Result { +pub fn api_client_configuration_from_token(token: &str, base_url: Url) -> Result { let mut headers = HeaderMap::new(); headers.insert( "Authorization", diff --git a/src/daemons.rs b/src/daemons.rs index 48945110..71108f96 100644 --- a/src/daemons.rs +++ b/src/daemons.rs @@ -62,6 +62,9 @@ pub struct CreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -79,6 +82,9 @@ pub struct ListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -96,6 +102,9 @@ pub struct DataSourcesArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -116,6 +125,9 @@ pub struct GetArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -132,6 +144,9 @@ pub struct DeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } /// A generic output for daemon related commands. @@ -158,7 +173,7 @@ pub async fn handle_command(args: Arguments) -> Result<()> { async fn handle_create_command(args: CreateArgs) -> Result<()> { let default_name = Name::new(petname(2, "-")).expect("petname should be valid name"); let name = name_req("Daemon name", args.name, Some(default_name))?; - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let mut new_proxy = NewProxy::builder().name(name).build(); @@ -189,7 +204,7 @@ struct ProxySummaryWithConnectedDataSources { } async fn handle_list_command(args: ListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let proxies = proxy_list(&client, workspace_id).await?; let data_sources = data_source_list(&client, workspace_id).await?; @@ -249,7 +264,7 @@ async fn handle_list_command(args: ListArgs) -> Result<()> { } async fn handle_get_command(args: GetArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let proxy_name = interactive::proxy_picker( &client, @@ -270,7 +285,7 @@ async fn handle_get_command(args: GetArgs) -> Result<()> { } async fn handle_data_sources_command(args: DataSourcesArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_sources = data_source_list(&client, workspace_id).await?; @@ -286,7 +301,7 @@ async fn handle_data_sources_command(args: DataSourcesArgs) -> Result<()> { } async fn handle_delete_command(args: DeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let proxy_name = interactive::proxy_picker( &client, diff --git a/src/data_sources.rs b/src/data_sources.rs index a2d6f8b5..3312ad4c 100644 --- a/src/data_sources.rs +++ b/src/data_sources.rs @@ -96,6 +96,9 @@ struct CreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -117,6 +120,9 @@ struct GetArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -134,6 +140,9 @@ struct DeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -163,6 +172,9 @@ struct UpdateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -180,6 +192,9 @@ struct ListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } pub async fn handle_command(args: Arguments) -> Result<()> { @@ -196,7 +211,7 @@ pub async fn handle_command(args: Arguments) -> Result<()> { } async fn handle_create(args: CreateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = name_req("Data source name", args.name, None)?; @@ -240,7 +255,7 @@ async fn handle_create(args: CreateArgs) -> Result<()> { } async fn handle_delete(args: DeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_source = data_source_picker(&client, Some(workspace_id), args.name).await?; @@ -251,7 +266,7 @@ async fn handle_delete(args: DeleteArgs) -> Result<()> { } async fn handle_get(args: GetArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_source = data_source_picker(&client, Some(workspace_id), args.name).await?; @@ -266,7 +281,7 @@ async fn handle_get(args: GetArgs) -> Result<()> { } async fn handle_update(args: UpdateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_source = data_source_picker(&client, Some(workspace_id), args.name).await?; @@ -287,7 +302,7 @@ async fn handle_update(args: UpdateArgs) -> Result<()> { } async fn handle_list(args: ListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_sources = data_source_list(&client, workspace_id).await?; diff --git a/src/events.rs b/src/events.rs index 779896cd..7f83a969 100644 --- a/src/events.rs +++ b/src/events.rs @@ -79,6 +79,9 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -124,10 +127,13 @@ pub struct SearchArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_event_create_command(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let key_values: HashMap<_, _> = args .labels @@ -159,7 +165,7 @@ async fn handle_event_create_command(args: CreateArguments) -> Result<()> { } async fn handle_event_search_command(args: SearchArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; @@ -196,10 +202,13 @@ pub struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_event_delete_command(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; event_delete(&client, args.id).await?; diff --git a/src/experiments.rs b/src/experiments.rs index 89b5cc54..e53e9bbc 100644 --- a/src/experiments.rs +++ b/src/experiments.rs @@ -68,12 +68,15 @@ struct MessageArgs { #[clap(from_global)] base_url: Url, - #[clap(from_global)] - config: Option, - /// Output type to display #[clap(long, short, default_value = "table", value_enum)] output: MessageOutput, + + #[clap(from_global)] + config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -92,6 +95,9 @@ struct CrawlArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -115,6 +121,9 @@ struct PrometheusGraphToNotebookArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(ValueEnum, Clone)] @@ -138,7 +147,7 @@ pub async fn handle_command(args: Arguments) -> Result<()> { } async fn handle_message_command(args: MessageArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let notebook_id = interactive::notebook_picker(&client, args.notebook_id, None).await?; let mut cache = Cache::load().await?; @@ -214,7 +223,7 @@ async fn handle_crawl_command(args: CrawlArgs) -> Result<()> { let mut notebook_titles: HashMap = HashMap::new(); let mut notebooks_to_crawl = VecDeque::new(); - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let starting_notebook_id = interactive::notebook_picker(&client, args.notebook_id, None).await?; @@ -384,7 +393,7 @@ fn cache_file_path() -> PathBuf { } async fn handle_prometheus_redirect_command(args: PrometheusGraphToNotebookArgs) -> Result<()> { - let client = Arc::new(api_client_configuration(args.config, args.base_url).await?); + let client = Arc::new(api_client_configuration(args.token, args.config, args.base_url).await?); let workspace_id = interactive::workspace_picker(&client, args.workspace_id).await?; let notebook_id = interactive::notebook_picker(&client, args.notebook_id, Some(workspace_id)).await?; diff --git a/src/labels.rs b/src/labels.rs index 4e826e3b..2b3d148d 100644 --- a/src/labels.rs +++ b/src/labels.rs @@ -50,6 +50,9 @@ pub struct ListKeysArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(ValueEnum, Clone)] @@ -62,7 +65,7 @@ enum ListKeysOutput { } async fn handle_list_keys_command(args: ListKeysArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let prefix = interactive::text_opt("Prefix", args.prefix, None); @@ -95,6 +98,9 @@ pub struct ListValuesArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(ValueEnum, Clone)] @@ -107,7 +113,7 @@ enum ListValuesOutput { } async fn handle_list_values_command(args: ListValuesArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let label_key = interactive::text_req("Label key", args.label_key, None)?; diff --git a/src/main.rs b/src/main.rs index 82f87241..9afb5dc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,12 @@ pub struct Arguments { #[clap(long, global = true, env, help_heading = "Global options")] config: Option, + /// Override the API token used + /// + /// If nothing is specified then it will use the token from the config file. + #[clap(long, global = true, env = "FP_TOKEN", help_heading = "Global options")] + token: Option, + /// Disables the version check #[clap(long, global = true, env, help_heading = "Global options")] disable_version_check: bool, @@ -540,10 +546,13 @@ struct NewArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_new_command(args: NewArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let title = if args.title.is_empty() { diff --git a/src/notebooks.rs b/src/notebooks.rs index fb95cb50..5416b580 100644 --- a/src/notebooks.rs +++ b/src/notebooks.rs @@ -166,10 +166,13 @@ pub struct CreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_create_command(args: CreateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let labels = args.labels.into_iter().map(Into::into).collect(); @@ -248,10 +251,13 @@ pub struct DuplicateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_duplicate_command(args: DuplicateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let notebook_id = interactive::notebook_picker_with_prompt( "Source Notebook", @@ -320,10 +326,13 @@ pub struct GetArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_get_command(args: GetArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let notebook_id = notebook_picker(&client, args.notebook_id, args.workspace_id).await?; let notebook = notebook_get(&client, notebook_id).await?; @@ -356,10 +365,13 @@ pub struct ListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_list_command(args: ListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebooks = notebook_list(&client, workspace_id).await?; @@ -408,10 +420,13 @@ pub struct SearchArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_search_command(args: SearchArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let mut search_params = NotebookSearch::default(); @@ -465,10 +480,13 @@ pub struct OpenArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_open_command(args: OpenArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebook_id = notebook_picker(&client, args.notebook_id, None).await?; @@ -497,10 +515,13 @@ pub struct DeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_delete_command(args: DeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let notebook_id = notebook_picker(&client, args.notebook_id, args.workspace_id).await?; notebook_delete(&client, notebook_id) @@ -528,16 +549,19 @@ pub struct AppendCellArgs { #[clap(from_global)] base_url: Url, - #[clap(from_global)] - config: Option, - /// Output type to display #[clap(long, short, default_value = "table", value_enum)] output: CellOutput, + + #[clap(from_global)] + config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_append_cell_command(args: AppendCellArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let notebook_id = notebook_picker(&client, args.notebook_id, None).await?; let cell = if let Some(content) = args.text { @@ -603,10 +627,13 @@ pub struct InsertSnippetArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } pub(crate) async fn handle_insert_snippet_command(args: InsertSnippetArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let workspace_id = workspace_picker_with_prompt( "Workspace of the snippet and notebook", @@ -675,10 +702,13 @@ struct FrontMatterUpdateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_front_matter_update_command(args: FrontMatterUpdateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebook_id = notebook_picker(&client, args.notebook_id, Some(workspace_id)).await?; @@ -704,10 +734,13 @@ struct FrontMatterClearArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_front_matter_clear_command(args: FrontMatterClearArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebook_id = notebook_picker(&client, args.notebook_id, Some(workspace_id)).await?; diff --git a/src/run/mod.rs b/src/run/mod.rs index b82dfa75..d90dfc9c 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -35,12 +35,15 @@ pub struct Arguments { #[clap(from_global)] base_url: Url, - #[clap(from_global)] - config: Option, - /// Output type to display #[clap(long, short, default_value = "command", value_enum)] output: ExecOutput, + + #[clap(from_global)] + config: Option, + + #[clap(from_global)] + token: Option, } #[derive(ValueEnum, Clone, PartialEq)] @@ -56,7 +59,12 @@ enum ExecOutput { } pub async fn handle_command(args: Arguments) -> Result<()> { - let client = api_client_configuration(args.config.clone(), args.base_url.clone()).await?; + let client = api_client_configuration( + args.token.clone(), + args.config.clone(), + args.base_url.clone(), + ) + .await?; let command = args.command.join(" "); let workspace_id = interactive::workspace_picker(&client, args.workspace_id).await?; diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 37f608ba..0a14a7ca 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -32,6 +32,9 @@ pub struct Arguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } const TEXT_BUF_SIZE: usize = 256; @@ -44,7 +47,7 @@ pub(crate) async fn handle_command(args: Arguments) -> Result<()> { )); } - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let notebook_id = interactive::notebook_picker(&client, args.notebook_id, None).await?; let launcher = ShellLauncher::new(notebook_id.into()); diff --git a/src/snippets.rs b/src/snippets.rs index e5db93a0..41cc141a 100644 --- a/src/snippets.rs +++ b/src/snippets.rs @@ -105,6 +105,9 @@ struct ConvertArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -141,6 +144,9 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -168,6 +174,9 @@ struct GetArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -184,6 +193,9 @@ struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser, Debug)] @@ -209,6 +221,9 @@ struct ListArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -241,6 +256,9 @@ struct UpdateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -285,7 +303,7 @@ pub async fn handle_command(args: Arguments) -> Result<()> { } async fn handle_convert(args: ConvertArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebook_id = notebook_picker(&client, args.notebook_id, Some(workspace_id)).await?; let notebook = notebook_get(&client, notebook_id).await?; @@ -370,7 +388,7 @@ async fn handle_convert(args: ConvertArguments) -> Result<()> { } async fn handle_create(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = name_opt( @@ -402,7 +420,7 @@ async fn handle_create(args: CreateArguments) -> Result<()> { } async fn handle_delete(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, snippet_name) = snippet_picker(&client, args.snippet_name, None).await?; @@ -415,7 +433,7 @@ async fn handle_delete(args: DeleteArguments) -> Result<()> { } async fn handle_list(args: ListArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; @@ -437,7 +455,7 @@ async fn handle_list(args: ListArguments) -> Result<()> { } async fn handle_get(args: GetArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, snippet_name) = snippet_picker(&client, args.snippet_name, None).await?; let snippet = snippet_get(&client, workspace_id, &snippet_name).await?; @@ -453,7 +471,7 @@ async fn handle_get(args: GetArguments) -> Result<()> { } async fn handle_update(args: UpdateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, snippet_name) = snippet_picker(&client, args.snippet_name, args.workspace_id).await?; diff --git a/src/templates.rs b/src/templates.rs index b60ed447..69b928c2 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -144,6 +144,9 @@ struct ExpandArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -190,6 +193,9 @@ struct ConvertArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -233,6 +239,9 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -260,6 +269,9 @@ struct GetArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -276,6 +288,9 @@ struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser, Debug)] @@ -301,6 +316,9 @@ struct ListArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -333,6 +351,9 @@ struct UpdateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -437,21 +458,39 @@ async fn load_template(template_path: &str) -> Result { async fn handle_expand_command(args: ExpandArguments) -> Result<()> { let base_url = args.base_url.clone(); - let client = api_client_configuration(args.config.clone(), base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, base_url.clone()).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let template_url_base = base_url.join(&format!("workspaces/{workspace_id}/templates/"))?; // First, check if the template is the ID of an uploaded template let notebook = if let Ok(template_name) = Name::from_str(&args.template) { - expand_template_api(args, workspace_id, template_name).await + expand_template_api( + &client, + workspace_id, + template_name, + args.template_arguments, + ) + .await } else if let Some(template_name) = args.template.strip_prefix(template_url_base.as_str()) { // Next, check if it is a URL of an uploaded template let template_name = Name::from_str(template_name) .with_context(|| "Error parsing template name from URL")?; - expand_template_api(args, workspace_id, template_name).await + expand_template_api( + &client, + workspace_id, + template_name, + args.template_arguments, + ) + .await } else { // Otherwise, treat the template as a local path or URL of a template file - expand_template_file(args, workspace_id).await + expand_template_file( + &client, + workspace_id, + args.template, + args.template_arguments, + ) + .await }?; let notebook_id = Base64Uuid::parse_str(¬ebook.id)?; @@ -464,20 +503,18 @@ async fn handle_expand_command(args: ExpandArguments) -> Result<()> { /// Expand a template that has already been uploaded to Fiberplane async fn expand_template_api( - args: ExpandArguments, + client: &ApiClient, workspace_id: Base64Uuid, template_name: Name, + template_arguments: Option, ) -> Result { - let client = api_client_configuration(args.config, args.base_url).await?; - let notebook = template_expand( - &client, + client, workspace_id, &template_name, - args.template_arguments - .map_or_else(TemplateExpandPayload::new, |args| { - Map::from_iter(args.0.into_iter()) - }), + template_arguments.map_or_else(TemplateExpandPayload::new, |args| { + Map::from_iter(args.0.into_iter()) + }), ) .await .with_context(|| format!("Error expanding template: {template_name}"))?; @@ -486,12 +523,16 @@ async fn expand_template_api( } /// Expand a template that is either a local file or one hosted remotely -async fn expand_template_file(args: ExpandArguments, workspace_id: Base64Uuid) -> Result { - let template = load_template(&args.template).await?; - let client = api_client_configuration(args.config, args.base_url.clone()).await?; +async fn expand_template_file( + client: &ApiClient, + workspace_id: Base64Uuid, + template: String, + template_arguments: Option, +) -> Result { + let template = load_template(&template).await?; - let template_args = if let Some(args) = args.template_arguments { + let template_args = if let Some(args) = template_arguments { args.0 } else { HashMap::new() @@ -508,7 +549,8 @@ async fn expand_template_file(args: ExpandArguments, workspace_id: Base64Uuid) - async fn handle_convert_command(args: ConvertArguments) -> Result<()> { // Load the notebook - let client = api_client_configuration(args.config.clone(), args.base_url.clone()).await?; + let client = + api_client_configuration(args.token, args.config.clone(), args.base_url.clone()).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let notebook_id = interactive::notebook_picker(&client, args.notebook_id, Some(workspace_id)).await?; @@ -605,7 +647,7 @@ async fn handle_convert_command(args: ConvertArguments) -> Result<()> { } async fn handle_create_command(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = interactive::name_opt( @@ -641,7 +683,7 @@ async fn handle_create_command(args: CreateArguments) -> Result<()> { } async fn handle_get_command(args: GetArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, template_name) = interactive::template_picker(&client, args.template_name, None).await?; @@ -658,7 +700,7 @@ async fn handle_get_command(args: GetArguments) -> Result<()> { } async fn handle_delete_command(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, template_name) = interactive::template_picker(&client, args.template_name, None).await?; @@ -673,7 +715,7 @@ async fn handle_delete_command(args: DeleteArguments) -> Result<()> { async fn handle_list_command(args: ListArguments) -> Result<()> { debug!("handle list command"); - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let templates = template_list( @@ -694,7 +736,7 @@ async fn handle_list_command(args: ListArguments) -> Result<()> { } async fn handle_update_command(args: UpdateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let (workspace_id, template_name) = interactive::template_picker(&client, args.template_name, args.workspace_id).await?; diff --git a/src/tokens.rs b/src/tokens.rs index b7911a80..4c80bfa4 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -77,6 +77,9 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -106,6 +109,9 @@ pub struct ListArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -118,10 +124,13 @@ pub struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_token_create_command(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let token = token_create(&client, NewToken::new(args.name)).await?; @@ -140,7 +149,7 @@ async fn handle_token_create_command(args: CreateArguments) -> Result<()> { } async fn handle_token_list_command(args: ListArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let tokens = token_list( &client, @@ -161,7 +170,7 @@ async fn handle_token_list_command(args: ListArguments) -> Result<()> { } async fn handle_token_delete_command(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; token_delete(&client, args.id).await?; diff --git a/src/triggers.rs b/src/triggers.rs index 3f6d2b5a..1b4d0d03 100644 --- a/src/triggers.rs +++ b/src/triggers.rs @@ -85,6 +85,9 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -101,6 +104,9 @@ struct GetArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -113,6 +119,9 @@ struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -130,6 +139,9 @@ struct ListArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -156,6 +168,9 @@ struct InvokeArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } /// A generic output for trigger related commands. @@ -169,7 +184,7 @@ enum TriggerOutput { } async fn handle_trigger_create_command(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let workspace_id = interactive::workspace_picker(&client, args.workspace_id).await?; let (_, template_name) = @@ -199,7 +214,7 @@ async fn handle_trigger_create_command(args: CreateArguments) -> Result<()> { } async fn handle_trigger_get_command(args: GetArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let trigger_id = interactive::trigger_picker(&client, args.trigger_id, None).await?; let trigger = trigger_get(&client, trigger_id) @@ -215,7 +230,7 @@ async fn handle_trigger_get_command(args: GetArguments) -> Result<()> { } async fn handle_trigger_delete_command(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let trigger_id = interactive::trigger_picker(&client, args.trigger_id, None).await?; trigger_delete(&client, trigger_id) @@ -228,7 +243,7 @@ async fn handle_trigger_delete_command(args: DeleteArguments) -> Result<()> { } async fn handle_trigger_list_command(args: ListArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = interactive::workspace_picker(&client, args.workspace_id).await?; let mut triggers = trigger_list(&client, workspace_id) .await @@ -247,7 +262,7 @@ async fn handle_trigger_list_command(args: ListArguments) -> Result<()> { } async fn handle_trigger_invoke_command(args: InvokeArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url.clone()).await?; + let client = api_client_configuration(args.token, args.config, args.base_url.clone()).await?; let trigger_id = interactive::trigger_picker(&client, args.trigger_id, None).await?; let secret_key = interactive::text_req("Secret Key", args.secret_key, None)?; diff --git a/src/users.rs b/src/users.rs index 5e921e0f..79b526ae 100644 --- a/src/users.rs +++ b/src/users.rs @@ -39,6 +39,9 @@ struct GetArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } pub async fn handle_command(args: Arguments) -> Result<()> { @@ -48,7 +51,7 @@ pub async fn handle_command(args: Arguments) -> Result<()> { } async fn handle_get_profile_command(args: GetArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let profile = profile_get(&client).await?; match args.output { diff --git a/src/views.rs b/src/views.rs index ae9ce737..35a26c79 100644 --- a/src/views.rs +++ b/src/views.rs @@ -98,10 +98,13 @@ struct CreateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_create(args: CreateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = name_opt("Name", args.name, None).unwrap(); @@ -168,10 +171,13 @@ struct ListArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_list(args: ListArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; @@ -209,10 +215,13 @@ struct DeleteArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_delete(args: DeleteArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let view_name = view_picker(&client, args.workspace_id, args.view_name).await?; @@ -296,10 +305,13 @@ struct UpdateArguments { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_update(args: UpdateArguments) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let view_name = view_picker(&client, args.workspace_id, args.view_name).await?; diff --git a/src/webhooks.rs b/src/webhooks.rs index 8bf98f6f..3acc5e1f 100644 --- a/src/webhooks.rs +++ b/src/webhooks.rs @@ -100,10 +100,13 @@ struct CreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_create(args: CreateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let categories = webhook_category_picker(args.categories)?; @@ -158,10 +161,13 @@ struct ListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_list(args: ListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhooks = webhooks_list(&client, workspace_id, args.page, args.limit).await?; @@ -190,10 +196,13 @@ struct DeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_delete(args: DeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhook_id = webhook_picker(&client, workspace_id, args.webhook_id).await?; @@ -247,10 +256,13 @@ struct UpdateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_update(args: UpdateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhook_id = webhook_picker(&client, workspace_id, args.webhook_id).await?; @@ -313,10 +325,13 @@ struct WebhookDeliveryListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_delivery_list(args: WebhookDeliveryListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhook_id = webhook_picker(&client, workspace_id, args.webhook_id).await?; @@ -357,10 +372,13 @@ struct WebhookDeliveryInfoArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_webhook_delivery_info(args: WebhookDeliveryInfoArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhook_id = webhook_picker(&client, workspace_id, args.webhook_id).await?; @@ -412,10 +430,12 @@ struct WebhookDeliveryResendArgs { #[clap(from_global)] config: Option, -} + #[clap(from_global)] + token: Option, +} async fn handle_webhook_delivery_resend(args: WebhookDeliveryResendArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let webhook_id = webhook_picker(&client, workspace_id, args.webhook_id).await?; diff --git a/src/workspaces.rs b/src/workspaces.rs index c941ad0a..9f1331a3 100644 --- a/src/workspaces.rs +++ b/src/workspaces.rs @@ -146,10 +146,13 @@ struct CreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_workspace_create(args: CreateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let name = name_opt("Unique workspace name", args.name, None) .ok_or_else(|| anyhow!("Name is required"))?; @@ -183,10 +186,13 @@ struct DeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_workspace_delete(args: DeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; workspace_delete(&client, workspace_id).await?; @@ -222,10 +228,13 @@ struct ListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_workspace_list(args: ListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let list = workspace_list( &client, @@ -254,10 +263,13 @@ struct LeaveArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_workspace_leave(args: LeaveArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; workspace_leave(&client, workspace_id).await?; @@ -289,10 +301,13 @@ struct InviteCreateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_invite_create(args: InviteCreateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let email = text_req("Email", args.email, None)?; @@ -348,10 +363,13 @@ struct InviteListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_invite_list(args: InviteListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let invites = workspace_invite_get( @@ -384,10 +402,13 @@ struct InviteDeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_invite_delete(args: InviteDeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; workspace_invite_delete(&client, args.invite_id).await?; @@ -426,10 +447,13 @@ struct UserListArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_user_list(args: UserListArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let users = workspace_users_list( @@ -468,10 +492,13 @@ struct UserUpdateArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_user_update(args: UserUpdateArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let user = workspace_user_picker(&client, &workspace_id, args.user_id).await?; @@ -501,10 +528,13 @@ struct UserDeleteArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_user_delete(args: UserDeleteArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let user = workspace_user_picker(&client, &workspace_id, args.user_id).await?; @@ -542,6 +572,9 @@ struct MoveOwnerArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -558,6 +591,9 @@ struct ChangeNameArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -586,6 +622,9 @@ pub(crate) struct GetDefaultDataSourcesArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -606,6 +645,9 @@ pub(crate) struct SetDefaultDataSourcesArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } #[derive(Parser)] @@ -622,10 +664,13 @@ pub(crate) struct UnsetDefaultDataSourcesArgs { #[clap(from_global)] config: Option, + + #[clap(from_global)] + token: Option, } async fn handle_move_owner(args: MoveOwnerArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let new_owner = workspace_user_picker(&client, &workspace_id, args.new_owner_id).await?; @@ -642,7 +687,7 @@ async fn handle_move_owner(args: MoveOwnerArgs) -> Result<()> { } async fn handle_change_name(args: ChangeNameArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; workspace_update( @@ -659,7 +704,7 @@ async fn handle_change_name(args: ChangeNameArgs) -> Result<()> { } async fn handle_get_default_data_sources(args: GetDefaultDataSourcesArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let default_data_sources = workspace_get(&client, workspace_id) @@ -677,7 +722,7 @@ async fn handle_get_default_data_sources(args: GetDefaultDataSourcesArgs) -> Res } async fn handle_set_default_data_source(args: SetDefaultDataSourcesArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let data_source = @@ -721,7 +766,7 @@ async fn handle_set_default_data_source(args: SetDefaultDataSourcesArgs) -> Resu } async fn handle_unset_default_data_source(args: UnsetDefaultDataSourcesArgs) -> Result<()> { - let client = api_client_configuration(args.config, args.base_url).await?; + let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; let mut default_data_sources = workspace_get(&client, workspace_id)