From 5125d251cb2b396b6b198d4b43a4548d2cb63435 Mon Sep 17 00:00:00 2001 From: Mari Date: Mon, 11 Mar 2024 16:25:22 +0100 Subject: [PATCH 1/3] add workspace integrations command --- src/integrations.rs | 22 +++++++------- src/main.rs | 8 +++-- src/workspaces.rs | 74 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/integrations.rs b/src/integrations.rs index 589e014..c04886f 100644 --- a/src/integrations.rs +++ b/src/integrations.rs @@ -3,8 +3,8 @@ use crate::output::{output_json, output_list}; use anyhow::Result; use clap::{Parser, ValueEnum}; use cli_table::Table; -use fiberplane::api_client::integrations_get; -use fiberplane::models::integrations::IntegrationSummary; +use fiberplane::api_client::integrations_get_by_user; +use fiberplane::models::integrations::PersonalIntegrationSummary; use std::path::PathBuf; use time::format_description::well_known::Rfc3339; use url::Url; @@ -44,7 +44,7 @@ struct ListArgs { } #[derive(ValueEnum, Clone)] -enum IntegrationOutput { +pub(crate) enum IntegrationOutput { /// Output the details of the integrations as a table Table, @@ -54,7 +54,7 @@ enum IntegrationOutput { async fn handle_integrations_list(args: ListArgs) -> Result<()> { let client = api_client_configuration(args.token, args.config, args.base_url).await?; - let integrations = integrations_get(&client).await?; + let integrations = integrations_get_by_user(&client).await?; match args.output { IntegrationOutput::Table => { @@ -66,22 +66,22 @@ async fn handle_integrations_list(args: ListArgs) -> Result<()> { } #[derive(Table)] -struct IntegrationRow { +pub(crate) struct IntegrationRow { #[table(title = "ID")] - id: String, + pub(crate) id: String, #[table(title = "Status")] - status: String, + pub(crate) status: String, #[table(title = "Created at")] - created_at: String, + pub(crate) created_at: String, #[table(title = "Updated at")] - updated_at: String, + pub(crate) updated_at: String, } -impl From for IntegrationRow { - fn from(integration: IntegrationSummary) -> Self { +impl From for IntegrationRow { + fn from(integration: PersonalIntegrationSummary) -> Self { Self { id: integration.id.to_string(), status: integration.status.to_string(), diff --git a/src/main.rs b/src/main.rs index ca4a7d3..f01d895 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ mod events; mod experiments; mod fp_urls; mod front_matter; -mod integrations; +pub(crate) mod integrations; mod interactive; mod labels; mod manifest; @@ -226,9 +226,11 @@ enum SubCommand { #[clap(aliases = &["webhook", "wh"])] Webhooks(webhooks::Arguments), - /// Interact with integrations + /// Interact with personal integrations. /// - /// Integrations allow you to integrate various third-party tools into Fiberplane + /// Integrations allow you to integrate various third-party tools into Fiberplane. + /// + /// If you wish to configure workspace level integrations, please use `fp workspaces integrations` #[clap(alias = "integration")] Integrations(integrations::Arguments), diff --git a/src/workspaces.rs b/src/workspaces.rs index 3a390ac..1fccf68 100644 --- a/src/workspaces.rs +++ b/src/workspaces.rs @@ -1,4 +1,5 @@ use crate::config::api_client_configuration; +use crate::integrations::{IntegrationOutput, IntegrationRow}; use crate::interactive::{ data_source_picker, default_theme, name_opt, text_opt, text_req, workspace_picker, workspace_user_picker, @@ -9,12 +10,14 @@ use clap::{Parser, ValueEnum}; use cli_table::Table; use dialoguer::FuzzySelect; use fiberplane::api_client::{ - workspace_create, workspace_delete, workspace_get, workspace_invite_create, - workspace_invite_delete, workspace_invite_get, workspace_leave, workspace_list, - workspace_update, workspace_user_list, workspace_user_remove, workspace_user_update, + integrations_get_by_workspace, workspace_create, workspace_delete, workspace_get, + workspace_invite_create, workspace_invite_delete, workspace_invite_get, workspace_leave, + workspace_list, workspace_update, workspace_user_list, workspace_user_remove, + workspace_user_update, }; use fiberplane::base64uuid::Base64Uuid; use fiberplane::models::data_sources::{ProviderType, SelectedDataSource}; +use fiberplane::models::integrations::WorkspaceIntegrationSummary; use fiberplane::models::names::Name; use fiberplane::models::sorting::{ SortDirection, WorkspaceInviteListingSortFields, WorkspaceListingSortFields, @@ -26,6 +29,7 @@ use fiberplane::models::workspaces::{ }; use std::collections::BTreeMap; use std::{fmt::Display, path::PathBuf}; +use time::format_description::well_known::Rfc3339; use tracing::info; use url::Url; @@ -60,6 +64,10 @@ enum SubCommand { /// List, update and remove users from a workspace #[clap(subcommand)] Users(UsersSubCommand), + + /// List, update and remove integrations from a workspace + #[clap(subcommand)] + Integrations(IntegrationsSubCommand), } #[derive(Parser)] @@ -89,6 +97,12 @@ enum UsersSubCommand { Delete(UserDeleteArgs), } +#[derive(Parser)] +enum IntegrationsSubCommand { + /// List the integrations that are connected to this workspace + List(ListIntegrationsArgs), +} + pub async fn handle_command(args: Arguments) -> Result<()> { match args.sub_command { SubCommand::Create(args) => handle_workspace_create(args).await, @@ -112,6 +126,9 @@ pub async fn handle_command(args: Arguments) -> Result<()> { handle_default_data_sources_command(sub_command).await } }, + SubCommand::Integrations(sub_command) => match sub_command { + IntegrationsSubCommand::List(args) => handle_integrations_list(args).await, + }, } } @@ -669,6 +686,25 @@ pub(crate) struct UnsetDefaultDataSourcesArgs { token: Option, } +#[derive(Parser)] +pub(crate) struct ListIntegrationsArgs { + /// Output of the webhooks + #[clap(long, short, default_value = "table", value_enum)] + output: IntegrationOutput, + + #[clap(from_global)] + workspace_id: Option, + + #[clap(from_global)] + base_url: Url, + + #[clap(from_global)] + config: Option, + + #[clap(from_global)] + token: Option, +} + async fn handle_move_owner(args: MoveOwnerArgs) -> Result<()> { let client = api_client_configuration(args.token, args.config, args.base_url).await?; let workspace_id = workspace_picker(&client, args.workspace_id).await?; @@ -801,6 +837,21 @@ async fn handle_unset_default_data_source(args: UnsetDefaultDataSourcesArgs) -> Ok(()) } +async fn handle_integrations_list(args: ListIntegrationsArgs) -> Result<()> { + let client = api_client_configuration(args.token, args.config, args.base_url).await?; + let workspace_id = workspace_picker(&client, args.workspace_id).await?; + + let integrations = integrations_get_by_workspace(&client, workspace_id).await?; + + match args.output { + IntegrationOutput::Table => { + let rows: Vec = integrations.into_iter().map(Into::into).collect(); + output_list(rows) + } + IntegrationOutput::Json => output_json(&integrations), + } +} + #[derive(ValueEnum, Clone)] enum WorkspaceOutput { /// Output the details as a table @@ -998,6 +1049,23 @@ impl From for MembershipRow { } } +impl From for IntegrationRow { + fn from(integration: WorkspaceIntegrationSummary) -> Self { + Self { + id: integration.id.to_string(), + status: integration.status.to_string(), + created_at: integration.created_at.map_or_else( + || "n/a".to_string(), + |time| time.format(&Rfc3339).unwrap_or_default(), + ), + updated_at: integration.updated_at.map_or_else( + || "n/a".to_string(), + |time| time.format(&Rfc3339).unwrap_or_default(), + ), + } + } +} + fn print_data_sources(input: &BTreeMap) -> impl Display { let mut output = String::new(); let mut iterator = input.iter().peekable(); From 4a36850b2140ad64cdf7f1941a2a9d063b780127 Mon Sep 17 00:00:00 2001 From: Mari Date: Mon, 11 Mar 2024 16:37:22 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 206f043..b394e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format of this file is based on [Keep a Changelog](https://keepachangelog.co ## unreleased +### Added + +- Added `workspaces integrations list` command (#284) + ## [2.23.0] - 2024-03-01 ### Changed From 9223ac206126e7f6533c43e7bb03081316bdbc44 Mon Sep 17 00:00:00 2001 From: Mari Date: Tue, 12 Mar 2024 12:06:12 +0100 Subject: [PATCH 3/3] update fiberplane --- Cargo.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af681cc..73c90b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,7 +195,7 @@ checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "base64uuid" version = "1.1.0" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "base64 0.13.1", "serde", @@ -935,8 +935,8 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fiberplane" -version = "1.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "1.0.0-beta.14" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "base64uuid", "fiberplane-api-client", @@ -948,8 +948,8 @@ dependencies = [ [[package]] name = "fiberplane-api-client" -version = "1.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "1.0.0-beta.13" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "anyhow", "base64uuid", @@ -963,8 +963,8 @@ dependencies = [ [[package]] name = "fiberplane-markdown" -version = "1.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "1.0.0-beta.13" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "fiberplane-models", "pulldown-cmark", @@ -975,8 +975,8 @@ dependencies = [ [[package]] name = "fiberplane-models" -version = "1.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "1.0.0-beta.13" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "base64 0.13.1", "base64uuid", @@ -999,8 +999,8 @@ dependencies = [ [[package]] name = "fiberplane-provider-runtime" -version = "2.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "2.0.0-beta.13" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "bytes", "fiberplane-models", @@ -1019,8 +1019,8 @@ dependencies = [ [[package]] name = "fiberplane-templates" -version = "1.0.0-beta.12" -source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#1158fc6051aa55b091c1fe0c77ae0d0e559fa276" +version = "1.0.0-beta.14" +source = "git+ssh://git@github.com/fiberplane/fiberplane.git?branch=main#5ed58db5911538a905574807ac7909a067abe713" dependencies = [ "base64uuid", "fiberplane-models",