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
33 changes: 29 additions & 4 deletions openstack_cli/src/identity/v4/federation/mapping/list.rs
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::mapping::list;
use openstack_sdk::api::{Pagination, paged};
use openstack_types::identity::v4::federation::mapping::response::list::MappingResponse;

/// List available federation mappings.
Expand All @@ -48,6 +49,10 @@ pub struct MappingsCommand {
/// 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 @@ -65,6 +70,18 @@ struct QueryParameters {
#[arg(help_heading = "Query parameters", long)]
idp_id: Option<String>,

/// Limit number of entries on the single response page (Maximal 100)
#[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 @@ -93,15 +110,21 @@ impl MappingsCommand {
let mut ep_builder = list::Request::builder();

// Set query parameters
if let Some(val) = &self.query.name {
ep_builder.name(val);
}
if let Some(val) = &self.query.domain_id {
ep_builder.domain_id(val);
}
if let Some(val) = &self.query.idp_id {
ep_builder.idp_id(val);
}
if let Some(val) = &self.query.name {
ep_builder.name(val);
}
if let Some(val) = &self.query.limit {
ep_builder.limit(*val);
}
if let Some(val) = &self.query.marker {
ep_builder.marker(val);
}
if let Some(val) = &self.query._type {
ep_builder._type(val);
}
Expand All @@ -110,7 +133,9 @@ impl MappingsCommand {
.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::<MappingResponse>(data)?;
// Show command specific hints
op.show_command_hint()?;
Expand Down
14 changes: 13 additions & 1 deletion openstack_sdk/src/api/identity/v4/federation/mapping/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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> {
Expand All @@ -44,6 +45,14 @@ pub struct Request<'a> {
#[builder(default, setter(into))]
idp_id: Option<Cow<'a, str>>,

/// Limit number of entries on the single response page (Maximal 100)
#[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 @@ -97,9 +106,11 @@ impl RestEndpoint for Request<'_> {

fn parameters(&self) -> QueryParams<'_> {
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("idp_id", self.idp_id.as_ref());
params.push_opt("name", self.name.as_ref());
params.push_opt("limit", self.limit);
params.push_opt("marker", self.marker.as_ref());
params.push_opt("type", self._type.as_ref());

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

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