mirror of
https://github.com/moghtech/komodo.git
synced 2026-09-06 00:00:44 +00:00
implement ResourceQuery
This commit is contained in:
Generated
+4
-4
@@ -1998,9 +1998,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mongo_indexed"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d973a56f5991c904e1e212816717c978e43049319b084678ee8ab0ef7992e078"
|
||||
checksum = "f0cd571ac04a8ac4751e6899f404e5d1370ec79f17609ea5a3caa823619b7513"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -2011,9 +2011,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mongo_indexed_derive"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "737ea2a86127af23a996114a29457517ac5e457e384629192bb7f5802ba9a848"
|
||||
checksum = "da28743409e01e8a63877563786b227285423a0f36c3c16e83f6b8226de9990e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ derive_variants = "0.1.1"
|
||||
resolver_api = "0.1.6"
|
||||
parse_csl = "0.1.0"
|
||||
mungos = "0.5.4"
|
||||
mongo_indexed = "0.2.1"
|
||||
mongo_indexed = "0.2.2"
|
||||
serror = "0.1.4"
|
||||
serror_axum = "0.1.2"
|
||||
svi = "0.1.4"
|
||||
|
||||
@@ -8,8 +8,6 @@ license.workspace = true
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# local
|
||||
# monitor_types.workspace = true
|
||||
# mogh
|
||||
serror.workspace = true
|
||||
resolver_api.workspace = true
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
use derive_variants::EnumVariants;
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::{
|
||||
doc, serde_helpers::hex_string_as_object_id,
|
||||
doc, Document, serde_helpers::hex_string_as_object_id,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::Document;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use derive_builder::Builder;
|
||||
use mungos::mongodb::bson::doc;
|
||||
use mungos::mongodb::bson::{doc, Document};
|
||||
use partial_derive2::Partial;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
@@ -7,7 +7,7 @@ use typeshare::typeshare;
|
||||
use crate::entities::I64;
|
||||
|
||||
use super::{
|
||||
resource::{Resource, ResourceListItem},
|
||||
resource::{AddFilters, Resource, ResourceListItem, ResourceQuery},
|
||||
EnvironmentVar, SystemCommand, Version,
|
||||
};
|
||||
|
||||
@@ -114,3 +114,41 @@ pub struct BuildActionState {
|
||||
pub building: bool,
|
||||
pub updating: bool,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
pub type BuildQuery = ResourceQuery<BuildQuerySpecifics>;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct BuildQuerySpecifics {
|
||||
#[serde(default)]
|
||||
pub builder_ids: Vec<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub repos: Vec<String>,
|
||||
|
||||
/// query for builds last built more recently than this timestamp
|
||||
/// defaults to 0 which is a no op
|
||||
#[serde(default)]
|
||||
pub built_since: I64,
|
||||
}
|
||||
|
||||
impl AddFilters for BuildQuerySpecifics {
|
||||
fn add_filters(&self, filters: &mut Document) {
|
||||
if !self.builder_ids.is_empty() {
|
||||
filters.insert(
|
||||
"config.builder_id",
|
||||
doc! { "$in": &self.builder_ids },
|
||||
);
|
||||
}
|
||||
if !self.repos.is_empty() {
|
||||
filters.insert("config.repo", doc! { "$in": &self.repos });
|
||||
}
|
||||
if self.built_since > 0 {
|
||||
filters.insert(
|
||||
"info.last_built_at",
|
||||
doc! { "$gte": self.built_since },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use derive_builder::Builder;
|
||||
use derive_variants::EnumVariants;
|
||||
use mungos::mongodb::bson::{doc, Document};
|
||||
use partial_derive2::Partial;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use super::{
|
||||
resource::{Resource, ResourceListItem},
|
||||
resource::{AddFilters, Resource, ResourceListItem, ResourceQuery},
|
||||
EnvironmentVar, Version,
|
||||
};
|
||||
|
||||
@@ -301,3 +302,22 @@ pub struct DeploymentActionState {
|
||||
pub renaming: bool,
|
||||
pub deleting: bool,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
pub type DeploymentQuery = ResourceQuery<DeploymentQuerySpecifics>;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct DeploymentQuerySpecifics {
|
||||
#[serde(default)]
|
||||
pub server_ids: Vec<String>,
|
||||
}
|
||||
|
||||
impl AddFilters for DeploymentQuerySpecifics {
|
||||
fn add_filters(&self, filters: &mut Document) {
|
||||
if !self.server_ids.is_empty() {
|
||||
filters
|
||||
.insert("config.server_id", doc! { "$in": &self.server_ids });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use derive_builder::Builder;
|
||||
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
|
||||
use mungos::mongodb::bson::{
|
||||
doc, serde_helpers::hex_string_as_object_id, Document,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
@@ -54,3 +56,33 @@ pub struct ResourceListItem<Info> {
|
||||
pub tags: Vec<String>,
|
||||
pub info: Info,
|
||||
}
|
||||
|
||||
/// Passing empty Vec is the same as not filtering by that field
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct ResourceQuery<T> {
|
||||
#[serde(default)]
|
||||
pub names: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub tags: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub specific: T,
|
||||
}
|
||||
|
||||
pub trait AddFilters {
|
||||
fn add_filters(&self, _filters: &mut Document) {}
|
||||
}
|
||||
|
||||
impl AddFilters for () {}
|
||||
|
||||
impl<T: AddFilters> AddFilters for ResourceQuery<T> {
|
||||
fn add_filters(&self, filters: &mut Document) {
|
||||
if !self.names.is_empty() {
|
||||
filters.insert("name", doc! { "$in": &self.names });
|
||||
}
|
||||
if !self.tags.is_empty() {
|
||||
filters.insert("tags", doc! { "$all": &self.tags });
|
||||
}
|
||||
self.specific.add_filters(filters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use partial_derive2::Partial;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use super::resource::{Resource, ResourceListItem};
|
||||
use super::resource::{Resource, ResourceListItem, ResourceQuery};
|
||||
|
||||
pub mod docker_image;
|
||||
pub mod docker_network;
|
||||
@@ -168,3 +168,12 @@ pub enum ServerStatus {
|
||||
Ok,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
pub type ServerQuery = ResourceQuery<ServerQuerySpecifics>;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct ServerQuerySpecifics {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::Document;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
use typeshare::typeshare;
|
||||
|
||||
@@ -2,7 +2,7 @@ use derive_builder::Builder;
|
||||
use derive_variants::EnumVariants;
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::{
|
||||
doc, serde_helpers::hex_string_as_object_id,
|
||||
doc, serde_helpers::hex_string_as_object_id, Document,
|
||||
};
|
||||
use partial_derive2::Partial;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -2,7 +2,7 @@ use async_timing_util::unix_timestamp_ms;
|
||||
use derive_variants::EnumVariants;
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::{
|
||||
doc, serde_helpers::hex_string_as_object_id,
|
||||
doc, serde_helpers::hex_string_as_object_id, Document,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use mongo_indexed::derive::MongoIndexed;
|
||||
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
|
||||
use mungos::mongodb::bson::{
|
||||
serde_helpers::hex_string_as_object_id, Document,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user