From 2dba6242dbc0577b41749a0affeec8e217c1df88 Mon Sep 17 00:00:00 2001 From: Benno van den Berg Date: Mon, 4 Mar 2024 12:38:49 +0100 Subject: [PATCH] Update --- src/integrations/pagerduty_receivers.rs | 36 ++++++++++++++----------- src/utils.rs | 34 ----------------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/integrations/pagerduty_receivers.rs b/src/integrations/pagerduty_receivers.rs index 66c58dcb..d2facf30 100644 --- a/src/integrations/pagerduty_receivers.rs +++ b/src/integrations/pagerduty_receivers.rs @@ -1,7 +1,7 @@ use crate::config::api_client_configuration; use crate::interactive::{name_req, workspace_picker}; use crate::output::{output_details, output_json, output_list, GenericKeyValue}; -use crate::utils::{clear_or_update, override_pagination, override_sorting}; +use crate::utils::clear_or_update; use anyhow::Result; use clap::{Parser, ValueEnum}; use cli_table::Table; @@ -77,7 +77,7 @@ struct CreateArgs { /// An optional name referencing a Template. This template will be expanded /// if a PagerDuty incident is created. #[clap(long, short)] - incident_creation_template: Option, + incident_created_template: Option, /// Output of the webhooks #[clap(long, short, default_value = "table", value_enum)] @@ -105,10 +105,10 @@ async fn handle_create(args: CreateArgs) -> Result<()> { )?; let new_pagerduty_receiver = NewPagerDutyReceiver::builder() - .creation_template(args.incident_creation_template) + .incident_created_template_name(args.incident_created_template) .build(); let pagerduty_receiver = client - .pagerduty_receiver_create(workspace_id, name, new_pagerduty_receiver) + .pagerduty_receiver_create(workspace_id, &name, new_pagerduty_receiver) .await?; match args.output { @@ -149,7 +149,7 @@ async fn handle_get(args: GetArgs) -> Result<()> { let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = name_req("PagerDuty webhook receiver name", args.name, None)?; - let pagerduty_receiver = client.pagerduty_receiver_get(workspace_id, name).await?; + let pagerduty_receiver = client.pagerduty_receiver_get(workspace_id, &name).await?; match args.output { PagerDutyWebhookOutput::Table => { @@ -217,7 +217,7 @@ async fn handle_update(args: UpdateArgs) -> Result<()> { .build(); let pagerduty_receiver = client - .pagerduty_receiver_update(workspace_id, name, update_pagerduty_receiver) + .pagerduty_receiver_update(workspace_id, &name, update_pagerduty_receiver) .await?; match args.output { @@ -254,7 +254,9 @@ async fn handle_delete(args: DeleteArgs) -> Result<()> { let workspace_id = workspace_picker(&client, args.workspace_id).await?; let name = name_req("PagerDuty webhook receiver name", args.name, None)?; - client.pagerduty_receiver_delete(workspace_id, name).await?; + client + .pagerduty_receiver_delete(workspace_id, &name) + .await?; info!("Deleted Pagerduty receiver"); Ok(()) @@ -276,11 +278,11 @@ struct ListArgs { /// Page to display #[clap(long)] - page: Option, + page: Option, /// Amount of integrations to display per page #[clap(long)] - limit: Option, + limit: Option, /// Output of the webhooks #[clap(long, short, default_value = "table", value_enum)] @@ -300,11 +302,15 @@ async fn handle_list(args: ListArgs) -> 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 sorting = override_sorting(args.sort_by, args.sort_direction); - let pagination = override_pagination(args.page, args.limit); let pagerduty_receivers = client - .pagerduty_receiver_list(workspace_id, sorting, pagination) + .pagerduty_receiver_list( + workspace_id, + args.page, + args.limit, + args.sort_by.map(Into::into), + args.sort_direction.map(Into::into), + ) .await?; if pagerduty_receivers.has_more_results { @@ -326,8 +332,8 @@ pub struct PagerDutyReceiverRow { #[table(title = "Name")] pub name: String, - #[table(title = "Incident Creation Template")] - pub incident_creation_template: String, + #[table(title = "Incident Created Template")] + pub incident_created_template: String, #[table(title = "Updated at")] pub updated_at: String, @@ -340,7 +346,7 @@ impl From for PagerDutyReceiverRow { fn from(pagerduty_receiver: PagerDutyReceiver) -> Self { Self { name: pagerduty_receiver.name.to_string(), - incident_creation_template: pagerduty_receiver + incident_created_template: pagerduty_receiver .incident_created_template_name .map(|name| name.to_string()) .unwrap_or_else(|| String::from("")), diff --git a/src/utils.rs b/src/utils.rs index 76bbcfec..3fe300d9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,3 @@ -use fiberplane::models::paging::Pagination; -use fiberplane::models::sorting::{SortDirection, SortField, Sorting}; - pub fn clear_or_update(clear: bool, update: Option) -> Option> { if clear { Some(None) @@ -8,34 +5,3 @@ pub fn clear_or_update(clear: bool, update: Option) -> Option> { update.map(Some) } } - -pub fn override_sorting( - sort_field: Option, - sort_direction: Option, -) -> Sorting { - let mut sorting: Sorting = Default::default(); - - if let Some(sort_field) = sort_field { - sorting.sort_by = sort_field; - } - - if let Some(sort_direction) = sort_direction { - sorting.sort_direction = sort_direction; - } - - sorting -} - -pub fn override_pagination(page: Option, limit: Option) -> Pagination { - let mut pagination: Pagination = Default::default(); - - if let Some(page) = page { - pagination.page = page; - } - - if let Some(limit) = limit { - pagination.limit = limit; - } - - pagination -}