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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::output::OutputProcessor;

use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::identity::v4::federation::identity_provider::list;
use openstack_sdk::api::{Pagination, paged};
use openstack_types::identity::v4::federation::identity_provider::response::list::IdentityProviderResponse;

/// List identity providers. Without any filters only global identity providers
Expand All @@ -48,6 +49,10 @@ pub struct IdentityProvidersCommand {
/// Path parameters
#[command(flatten)]
path: PathParameters,

/// Total limit of entities count to return. Use this when there are too many entries.
#[arg(long, default_value_t = 10000)]
max_items: usize,
}

/// Query parameters
Expand All @@ -57,6 +62,18 @@ struct QueryParameters {
#[arg(help_heading = "Query parameters", long)]
domain_id: Option<String>,

/// Limit number of entries on the single response page.
#[arg(
help_heading = "Query parameters",
long("page-size"),
visible_alias("limit")
)]
limit: Option<u32>,

/// Page marker (id of the last entry on the previous page.
#[arg(help_heading = "Query parameters", long)]
marker: Option<String>,

/// Filters the response by IDP name.
#[arg(help_heading = "Query parameters", long)]
name: Option<String>,
Expand Down Expand Up @@ -91,12 +108,20 @@ impl IdentityProvidersCommand {
if let Some(val) = &self.query.domain_id {
ep_builder.domain_id(val);
}
if let Some(val) = &self.query.limit {
ep_builder.limit(*val);
}
if let Some(val) = &self.query.marker {
ep_builder.marker(val);
}

let ep = ep_builder
.build()
.map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;

let data: Vec<serde_json::Value> = ep.query_async(client).await?;
let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
.query_async(client)
.await?;
op.output_list::<IdentityProviderResponse>(data)?;
// Show command specific hints
op.show_command_hint()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ use crate::api::rest_endpoint_prelude::*;

use std::borrow::Cow;

use crate::api::Pageable;
#[derive(Builder, Debug, Clone)]
#[builder(setter(strip_option))]
pub struct Request<'a> {
/// Filters the response by a domain ID.
#[builder(default, setter(into))]
domain_id: Option<Cow<'a, str>>,

/// Limit number of entries on the single response page.
#[builder(default)]
limit: Option<u32>,

/// Page marker (id of the last entry on the previous page.
#[builder(default, setter(into))]
marker: Option<Cow<'a, str>>,

/// Filters the response by IDP name.
#[builder(default, setter(into))]
name: Option<Cow<'a, str>>,
Expand Down Expand Up @@ -91,6 +100,8 @@ impl RestEndpoint for Request<'_> {
let mut params = QueryParams::default();
params.push_opt("name", self.name.as_ref());
params.push_opt("domain_id", self.domain_id.as_ref());
params.push_opt("limit", self.limit);
params.push_opt("marker", self.marker.as_ref());

params
}
Expand All @@ -113,6 +124,7 @@ impl RestEndpoint for Request<'_> {
Some(ApiVersion::new(4, 0))
}
}
impl Pageable for Request<'_> {}

#[cfg(test)]
mod tests {
Expand Down