mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 11:49:39 -05:00
add update_available query parameter to filter for only stacks /deployments with available update
This commit is contained in:
@@ -51,12 +51,25 @@ impl Resolve<ReadArgs> for ListDeployments {
|
||||
} else {
|
||||
get_all_tags(None).await?
|
||||
};
|
||||
Ok(
|
||||
resource::list_for_user::<Deployment>(
|
||||
self.query, user, &all_tags,
|
||||
)
|
||||
.await?,
|
||||
let update_available_filter =
|
||||
self.query.specific.update_available;
|
||||
let deployments = resource::list_for_user::<Deployment>(
|
||||
self.query, user, &all_tags,
|
||||
)
|
||||
.await?;
|
||||
let deployments = if let Some(update_available_filter) =
|
||||
update_available_filter
|
||||
{
|
||||
deployments
|
||||
.into_iter()
|
||||
.filter(|deployment| {
|
||||
deployment.info.update_available == update_available_filter
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
deployments
|
||||
};
|
||||
Ok(deployments)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,10 +194,29 @@ impl Resolve<ReadArgs> for ListStacks {
|
||||
} else {
|
||||
get_all_tags(None).await?
|
||||
};
|
||||
Ok(
|
||||
let update_available_filter =
|
||||
self.query.specific.update_available;
|
||||
let stacks =
|
||||
resource::list_for_user::<Stack>(self.query, user, &all_tags)
|
||||
.await?,
|
||||
)
|
||||
.await?;
|
||||
let stacks = if let Some(update_available_filter) =
|
||||
update_available_filter
|
||||
{
|
||||
stacks
|
||||
.into_iter()
|
||||
.filter(|stack| {
|
||||
stack
|
||||
.info
|
||||
.services
|
||||
.iter()
|
||||
.any(|service| service.update_available)
|
||||
== update_available_filter
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
stacks
|
||||
};
|
||||
Ok(stacks)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -453,11 +453,20 @@ pub type DeploymentQuery = ResourceQuery<DeploymentQuerySpecifics>;
|
||||
Debug, Clone, Default, Serialize, Deserialize, DefaultBuilder,
|
||||
)]
|
||||
pub struct DeploymentQuerySpecifics {
|
||||
/// Query only for Deployments on these Servers.
|
||||
/// If empty, does not filter by Server.
|
||||
/// Only accepts Server id (not name).
|
||||
#[serde(default)]
|
||||
pub server_ids: Vec<String>,
|
||||
|
||||
/// Query only for Deployments with these Builds attached.
|
||||
/// If empty, does not filter by Build.
|
||||
/// Only accepts Build id (not name).
|
||||
#[serde(default)]
|
||||
pub build_ids: Vec<String>,
|
||||
|
||||
/// Query only for Deployments with available image updates.
|
||||
pub update_available: Option<bool>,
|
||||
}
|
||||
|
||||
impl super::resource::AddFilters for DeploymentQuerySpecifics {
|
||||
|
||||
@@ -603,12 +603,24 @@ pub type StackQuery = ResourceQuery<StackQuerySpecifics>;
|
||||
Serialize, Deserialize, Debug, Clone, Default, DefaultBuilder,
|
||||
)]
|
||||
pub struct StackQuerySpecifics {
|
||||
/// Query only for Stacks on these Servers.
|
||||
/// If empty, does not filter by Server.
|
||||
/// Only accepts Server id (not name).
|
||||
#[serde(default)]
|
||||
pub server_ids: Vec<String>,
|
||||
/// Filter syncs by their repo.
|
||||
#[serde(default)]
|
||||
pub repos: Vec<String>,
|
||||
/// Query only for Stack with available image updates.
|
||||
pub update_available: Option<bool>,
|
||||
}
|
||||
|
||||
impl super::resource::AddFilters for StackQuerySpecifics {
|
||||
fn add_filters(&self, filters: &mut Document) {
|
||||
if !self.server_ids.is_empty() {
|
||||
filters
|
||||
.insert("config.server_id", doc! { "$in": &self.server_ids });
|
||||
}
|
||||
if !self.repos.is_empty() {
|
||||
filters.insert("config.repo", doc! { "$in": &self.repos });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user