change to tags. begin test monrun

This commit is contained in:
mbecker20
2024-03-26 02:42:45 -07:00
parent 7c5acb8c21
commit 73217c9178
13 changed files with 434 additions and 396 deletions

View File

@@ -2,7 +2,7 @@ use anyhow::Context;
use async_trait::async_trait;
use monitor_client::{
api::read::{GetTag, ListTags},
entities::{tag::CustomTag, user::User},
entities::{tag::Tag, user::User},
};
use mungos::find::find_collect;
use resolver_api::Resolve;
@@ -15,7 +15,7 @@ impl Resolve<GetTag, User> for State {
&self,
GetTag { id }: GetTag,
_: User,
) -> anyhow::Result<CustomTag> {
) -> anyhow::Result<Tag> {
get_tag(&id).await
}
}
@@ -26,7 +26,7 @@ impl Resolve<ListTags, User> for State {
&self,
ListTags { query }: ListTags,
_: User,
) -> anyhow::Result<Vec<CustomTag>> {
) -> anyhow::Result<Vec<Tag>> {
find_collect(&db_client().await.tags, query, None)
.await
.context("failed to get tags from db")

View File

@@ -99,7 +99,7 @@ enum WriteRequest {
// ==== TAG ====
CreateTag(CreateTag),
DeleteTag(DeleteTag),
UpdateTag(UpdateTag),
RenameTag(RenameTag),
UpdateTagsOnResource(UpdateTagsOnResource),
}

View File

@@ -2,19 +2,19 @@ use anyhow::{anyhow, Context};
use async_trait::async_trait;
use monitor_client::{
api::write::{
CreateTag, DeleteTag, UpdateTag, UpdateTagsOnResource,
CreateTag, DeleteTag, RenameTag, UpdateTagsOnResource,
UpdateTagsOnResourceResponse,
},
entities::{
alerter::Alerter, build::Build, builder::Builder,
deployment::Deployment, permission::PermissionLevel,
procedure::Procedure, repo::Repo, server::Server, tag::CustomTag,
procedure::Procedure, repo::Repo, server::Server, tag::Tag,
update::ResourceTarget, user::User,
},
};
use mungos::{
by_id::{delete_one_by_id, update_one_by_id},
mongodb::bson::{doc, to_bson},
mongodb::bson::doc,
};
use resolver_api::Resolve;
@@ -28,18 +28,12 @@ use crate::{
impl Resolve<CreateTag, User> for State {
async fn resolve(
&self,
CreateTag {
name,
category,
color,
}: CreateTag,
CreateTag { name }: CreateTag,
user: User,
) -> anyhow::Result<CustomTag> {
let mut tag = CustomTag {
) -> anyhow::Result<Tag> {
let mut tag = Tag {
id: Default::default(),
name,
category,
color,
owner: user.id.clone(),
};
tag.id = db_client()
@@ -57,22 +51,23 @@ impl Resolve<CreateTag, User> for State {
}
#[async_trait]
impl Resolve<UpdateTag, User> for State {
impl Resolve<RenameTag, User> for State {
async fn resolve(
&self,
UpdateTag { id, config }: UpdateTag,
RenameTag { id, name }: RenameTag,
user: User,
) -> anyhow::Result<CustomTag> {
) -> anyhow::Result<Tag> {
get_tag_check_owner(&id, &user).await?;
update_one_by_id(
&db_client().await.tags,
&id,
doc! { "$set": to_bson(&config)? },
doc! { "$set": { "name": name } },
None,
)
.await
.context("context")?;
.context("failed to rename tag on db")?;
get_tag(&id).await
}
}
@@ -83,7 +78,7 @@ impl Resolve<DeleteTag, User> for State {
&self,
DeleteTag { id }: DeleteTag,
user: User,
) -> anyhow::Result<CustomTag> {
) -> anyhow::Result<Tag> {
let tag = get_tag_check_owner(&id, &user).await?;
tokio::try_join!(

View File

@@ -10,7 +10,7 @@ use monitor_client::entities::{
procedure::Procedure,
repo::Repo,
server::{stats::SystemStatsRecord, Server},
tag::CustomTag,
tag::Tag,
update::Update,
user::User,
};
@@ -37,7 +37,7 @@ pub struct DbClient {
pub users: Collection<User>,
pub permissions: Collection<Permission>,
pub api_keys: Collection<ApiKey>,
pub tags: Collection<CustomTag>,
pub tags: Collection<Tag>,
pub updates: Collection<Update>,
pub alerts: Collection<Alert>,
pub stats: Collection<SystemStatsRecord>,
@@ -92,7 +92,7 @@ impl DbClient {
users: User::collection(&db, true).await?,
permissions: Permission::collection(&db, true).await?,
api_keys: ApiKey::collection(&db, true).await?,
tags: CustomTag::collection(&db, true).await?,
tags: Tag::collection(&db, true).await?,
updates: Update::collection(&db, true).await?,
alerts: Alert::collection(&db, true).await?,
stats: SystemStatsRecord::collection(&db, true).await?,

View File

@@ -6,7 +6,7 @@ use monitor_client::entities::{
monitor_timestamp,
permission::{Permission, PermissionLevel},
server::{Server, ServerStatus},
tag::CustomTag,
tag::Tag,
update::{ResourceTarget, Update, UpdateListItem},
user::User,
Operation,
@@ -109,7 +109,7 @@ pub async fn get_deployment_state(
// TAG
pub async fn get_tag(tag_id: &str) -> anyhow::Result<CustomTag> {
pub async fn get_tag(tag_id: &str) -> anyhow::Result<Tag> {
find_one_by_id(&db_client().await.tags, tag_id)
.await
.context("failed to query mongo for tag")?
@@ -119,7 +119,7 @@ pub async fn get_tag(tag_id: &str) -> anyhow::Result<CustomTag> {
pub async fn get_tag_check_owner(
tag_id: &str,
user: &User,
) -> anyhow::Result<CustomTag> {
) -> anyhow::Result<Tag> {
let tag = get_tag(tag_id).await?;
if !user.admin && tag.owner != user.id {
return Err(anyhow!("user must be tag owner or admin"));

View File

@@ -7,7 +7,6 @@ config.server_id = "mogh-server"
[[deployment.config.environment]]
variable = "TEST_1"
value = "VALUE"
[[deployment.config.environment]]
variable = "TEST_2"
value = "VALUE"

View File

@@ -2,7 +2,12 @@ use std::collections::HashMap;
use async_trait::async_trait;
use monitor_client::{
api::write,
api::{
read::ListTags,
write::{
self, CreateTag, UpdateDescription, UpdateTagsOnResource,
},
},
entities::{
alerter::{Alerter, AlerterListItemInfo, PartialAlerterConfig},
build::{Build, BuildListItemInfo, PartialBuildConfig},
@@ -13,6 +18,7 @@ use monitor_client::{
repo::{PartialRepoConfig, Repo, RepoInfo},
resource::{Resource, ResourceListItem},
server::{PartialServerConfig, Server, ServerListItemInfo},
update::ResourceTarget,
},
};
@@ -24,269 +30,26 @@ use crate::{
monitor_client,
};
#[async_trait]
impl Sync for Server {
type ListItemInfo = ServerListItemInfo;
type PartialConfig = PartialServerConfig;
fn display() -> &'static str {
"server"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_server()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateServer {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateServer {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Deployment {
type PartialConfig = PartialDeploymentConfig;
type ListItemInfo = DeploymentListItemInfo;
fn display() -> &'static str {
"deployment"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_deployment()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateDeployment {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateDeployment {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Build {
type PartialConfig = PartialBuildConfig;
type ListItemInfo = BuildListItemInfo;
fn display() -> &'static str {
"build"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_build()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateBuild {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateBuild {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Builder {
type PartialConfig = PartialBuilderConfig;
type ListItemInfo = BuilderListItemInfo;
fn display() -> &'static str {
"builder"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_builder()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateBuilder {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateBuilder {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Alerter {
type PartialConfig = PartialAlerterConfig;
type ListItemInfo = AlerterListItemInfo;
fn display() -> &'static str {
"alerter"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_alerter()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateAlerter {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateAlerter {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Repo {
type PartialConfig = PartialRepoConfig;
type ListItemInfo = RepoInfo;
fn display() -> &'static str {
"repo"
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_repo()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::CreateRepo {
name: resource.name,
config: resource.config,
})
.await?;
Ok(())
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateRepo {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
type ToUpdate<T> = Vec<(String, Resource<T>)>;
type ToCreate<T> = Vec<Resource<T>>;
type UpdatesResult<T> = (ToUpdate<T>, ToCreate<T>);
#[async_trait]
pub trait Sync {
type PartialConfig: Send + 'static;
type PartialConfig: Clone + Send + 'static;
type ListItemInfo: 'static;
fn display() -> &'static str;
fn resource_target(id: String) -> ResourceTarget;
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>;
/// Returns created id
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()>;
) -> anyhow::Result<String>;
async fn update(
id: String,
@@ -343,18 +106,382 @@ pub trait Sync {
to_update: ToUpdate<Self::PartialConfig>,
to_create: ToCreate<Self::PartialConfig>,
) {
let mut tag_name_to_id = monitor_client()
.read(ListTags::default())
.await
.expect("failed to ListTags mid run")
.into_iter()
.map(|tag| (tag.name, tag.id))
.collect::<HashMap<_, _>>();
for (id, resource) in to_update {
// Update resource
let name = resource.name.clone();
if let Err(e) = Self::update(id, resource).await {
warn!("failed to update {} {name} | {e:#}", Self::display(),)
let tags = resource.tags.clone();
let description = resource.description.clone();
if let Err(e) = Self::update(id.clone(), resource).await {
warn!("failed to update {} {name} | {e:#}", Self::display());
}
Self::update_tags(
id.clone(),
&name,
&tags,
&mut tag_name_to_id,
)
.await;
Self::update_description(id, description).await;
}
for resource in to_create {
let name = resource.name.clone();
if let Err(e) = Self::create(resource).await {
warn!("failed to create {} {name} | {e:#}", Self::display(),)
let tags = resource.tags.clone();
let description = resource.description.clone();
let id = match Self::create(resource).await {
Ok(id) => id,
Err(e) => {
warn!(
"failed to create {} {name} | {e:#}",
Self::display(),
);
continue;
}
};
Self::update_tags(
id.clone(),
&name,
&tags,
&mut tag_name_to_id,
)
.await;
Self::update_description(id, description).await;
}
}
async fn update_tags(
resource_id: String,
resource_name: &str,
tags: &[String],
tag_name_to_id: &mut HashMap<String, String>,
) {
// make sure all tags are created
for tag_name in tags {
if !tag_name_to_id.contains_key(tag_name) {
let tag_id = monitor_client()
.write(CreateTag {
name: tag_name.to_string(),
})
.await
.expect("failed to CreateTag mid run")
.id;
tag_name_to_id.insert(tag_name.to_string(), tag_id);
}
}
// get Vec<tag_id>
let tags = tags
.iter()
.map(|tag_name| {
tag_name_to_id
.get(tag_name)
.expect("somehow didn't find tag at this point")
.to_string()
})
.collect();
// Update tags
if let Err(e) = monitor_client()
.write(UpdateTagsOnResource {
target: Self::resource_target(resource_id),
tags,
})
.await
{
warn!(
"failed to update tags on {} {resource_name} | {e:#}",
Self::display(),
);
}
}
async fn update_description(id: String, description: String) {
if let Err(e) = monitor_client()
.write(UpdateDescription {
target: Self::resource_target(id.clone()),
description,
})
.await
{
warn!("failed to update resource {id} description | {e:#}");
}
}
}
#[async_trait]
impl Sync for Server {
type ListItemInfo = ServerListItemInfo;
type PartialConfig = PartialServerConfig;
fn display() -> &'static str {
"server"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Server(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_server()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateServer {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateServer {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Deployment {
type PartialConfig = PartialDeploymentConfig;
type ListItemInfo = DeploymentListItemInfo;
fn display() -> &'static str {
"deployment"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Deployment(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_deployment()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateDeployment {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateDeployment {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Build {
type PartialConfig = PartialBuildConfig;
type ListItemInfo = BuildListItemInfo;
fn display() -> &'static str {
"build"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Build(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_build()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateBuild {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateBuild {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Builder {
type PartialConfig = PartialBuilderConfig;
type ListItemInfo = BuilderListItemInfo;
fn display() -> &'static str {
"builder"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Builder(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_builder()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateBuilder {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateBuilder {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Alerter {
type PartialConfig = PartialAlerterConfig;
type ListItemInfo = AlerterListItemInfo;
fn display() -> &'static str {
"alerter"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Alerter(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_alerter()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateAlerter {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateAlerter {
id,
config: resource.config,
})
.await?;
Ok(())
}
}
#[async_trait]
impl Sync for Repo {
type PartialConfig = PartialRepoConfig;
type ListItemInfo = RepoInfo;
fn display() -> &'static str {
"repo"
}
fn resource_target(id: String) -> ResourceTarget {
ResourceTarget::Repo(id)
}
fn name_to_resource(
) -> &'static HashMap<String, ResourceListItem<Self::ListItemInfo>>
{
name_to_repo()
}
async fn create(
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<String> {
monitor_client()
.write(write::CreateRepo {
name: resource.name,
config: resource.config,
})
.await
.map(|res| res.id)
}
async fn update(
id: String,
resource: Resource<Self::PartialConfig>,
) -> anyhow::Result<()> {
monitor_client()
.write(write::UpdateRepo {
id,
config: resource.config,
})
.await?;
Ok(())
}
}

View File

@@ -3,7 +3,7 @@ use resolver_api::derive::Request;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{tag::CustomTag, MongoDocument};
use crate::entities::{tag::Tag, MongoDocument};
use super::MonitorReadRequest;
@@ -20,13 +20,13 @@ pub struct GetTag {
}
#[typeshare]
pub type GetTagResponse = CustomTag;
pub type GetTagResponse = Tag;
//
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits,
)]
#[empty_traits(MonitorReadRequest)]
#[response(ListTagsResponse)]
@@ -35,4 +35,4 @@ pub struct ListTags {
}
#[typeshare]
pub type ListTagsResponse = Vec<CustomTag>;
pub type ListTagsResponse = Vec<Tag>;

View File

@@ -3,10 +3,7 @@ use resolver_api::derive::Request;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{
tag::{CustomTag, TagColor, _PartialCustomTag},
update::ResourceTarget,
};
use crate::entities::{tag::Tag, update::ResourceTarget};
use super::MonitorWriteRequest;
@@ -17,15 +14,9 @@ use super::MonitorWriteRequest;
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorWriteRequest)]
#[response(CustomTag)]
#[response(Tag)]
pub struct CreateTag {
pub name: String,
#[serde(default)]
pub category: String,
#[serde(default)]
pub color: TagColor,
}
//
@@ -35,7 +26,7 @@ pub struct CreateTag {
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorWriteRequest)]
#[response(CustomTag)]
#[response(Tag)]
pub struct DeleteTag {
pub id: String,
}
@@ -47,10 +38,10 @@ pub struct DeleteTag {
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorWriteRequest)]
#[response(CustomTag)]
pub struct UpdateTag {
#[response(Tag)]
pub struct RenameTag {
pub id: String,
pub config: _PartialCustomTag,
pub name: String,
}
//
@@ -63,7 +54,8 @@ pub struct UpdateTag {
#[response(UpdateTagsOnResourceResponse)]
pub struct UpdateTagsOnResource {
pub target: ResourceTarget,
pub tags: Vec<String>, // custom tag ids
/// Tag Ids
pub tags: Vec<String>,
}
#[typeshare]

View File

@@ -32,6 +32,7 @@ pub struct Resource<Config, Info: Default = ()> {
#[builder(setter(skip))]
pub updated_at: I64,
/// Tag Ids
#[serde(default)]
#[builder(default)]
pub tags: Vec<String>,
@@ -51,6 +52,7 @@ pub struct ResourceListItem<Info> {
pub resource_type: ResourceTargetVariant,
pub name: String,
pub created_at: I64,
/// Tag Ids
pub tags: Vec<String>,
pub info: Info,
}

View File

@@ -1,47 +1,23 @@
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, Document,
};
use partial_derive2::Partial;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
use typeshare::typeshare;
use crate::entities::MongoId;
use super::update::ResourceTargetVariant;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, EnumVariants)]
#[variant_derive(
Serialize,
Deserialize,
Debug,
Clone,
Copy,
Display,
EnumString
)]
#[serde(tag = "type", content = "params")]
pub enum Tag {
ResourceType { resource: ResourceTargetVariant }, // filter by resource type
Server { server_id: String }, // filter by server, eg deployments, builds, repos
Custom { tag_id: String }, // filter by presence of custom tag on resource
}
#[typeshare(serialized_as = "Partial<CustomTag>")]
pub type _PartialCustomTag = PartialCustomTag;
#[typeshare(serialized_as = "Partial<Tag>")]
pub type _PartialTag = PartialTag;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Builder, Partial, MongoIndexed,
)]
#[partial_derive(Serialize, Deserialize, Debug, Clone, Default)]
#[collection_name(Tag)]
#[unique_doc_index(doc! { "name": 1, "category": 1 })]
pub struct CustomTag {
pub struct Tag {
#[serde(
default,
rename = "_id",
@@ -51,42 +27,11 @@ pub struct CustomTag {
#[builder(setter(skip))]
pub id: MongoId,
#[index]
#[unique_index]
pub name: String,
#[serde(default)]
#[builder(default)]
#[index]
pub owner: String,
#[serde(default)]
#[builder(default)]
#[index]
pub category: String,
#[serde(default)]
#[builder(default)]
pub color: TagColor,
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
Copy,
Display,
EnumString,
Default,
)]
pub enum TagColor {
#[default]
Red,
Green,
Blue,
Yellow,
Purple,
Magenta,
Cyan,
}

View File

@@ -164,9 +164,9 @@ export type WriteResponses = {
UpdateProcedure: Types.Procedure;
// ==== TAG ====
CreateTag: Types.CustomTag;
DeleteTag: Types.CustomTag;
UpdateTag: Types.CustomTag;
CreateTag: Types.Tag;
DeleteTag: Types.Tag;
RenameTag: Types.Tag;
UpdateTagsOnResource: Types.UpdateTagsOnResourceResponse;
};

View File

@@ -15,6 +15,7 @@ export interface Resource<Config, Info> {
name: string;
description?: string;
updated_at?: I64;
/** Tag Ids */
tags?: string[];
info?: Info;
config: Config;
@@ -37,6 +38,7 @@ export interface ResourceListItem<Info> {
type: ResourceTarget["type"];
name: string;
created_at: I64;
/** Tag Ids */
tags: string[];
info: Info;
}
@@ -634,27 +636,15 @@ export type GetDockerContainersResponse = ContainerSummary[];
export type GetAvailableSecretsResponse = string[];
export enum TagColor {
Red = "Red",
Green = "Green",
Blue = "Blue",
Yellow = "Yellow",
Purple = "Purple",
Magenta = "Magenta",
Cyan = "Cyan",
}
export interface CustomTag {
export interface Tag {
_id?: MongoId;
name: string;
owner?: string;
category?: string;
color?: TagColor;
}
export type GetTagResponse = CustomTag;
export type GetTagResponse = Tag;
export type ListTagsResponse = CustomTag[];
export type ListTagsResponse = Tag[];
export enum Operation {
None = "None",
@@ -825,7 +815,7 @@ export interface ServerQuerySpecifics {
export type ServerQuery = ResourceQuery<ServerQuerySpecifics>;
export type _PartialCustomTag = Partial<CustomTag>;
export type _PartialTag = Partial<Tag>;
export interface GetLoginOptions {
}
@@ -1616,21 +1606,20 @@ export interface DeleteNetwork {
export interface CreateTag {
name: string;
category?: string;
color?: TagColor;
}
export interface DeleteTag {
id: string;
}
export interface UpdateTag {
export interface RenameTag {
id: string;
config: _PartialCustomTag;
name: string;
}
export interface UpdateTagsOnResource {
target: ResourceTarget;
/** Tag Ids */
tags: string[];
}
@@ -1850,7 +1839,7 @@ export type WriteRequest =
| { type: "UpdateProcedure", params: UpdateProcedure }
| { type: "CreateTag", params: CreateTag }
| { type: "DeleteTag", params: DeleteTag }
| { type: "UpdateTag", params: UpdateTag }
| { type: "RenameTag", params: RenameTag }
| { type: "UpdateTagsOnResource", params: UpdateTagsOnResource };
export type Execution =
@@ -1869,17 +1858,6 @@ export type Execution =
| { type: "PruneDockerImages", params: PruneDockerImages }
| { type: "PruneDockerContainers", params: PruneDockerContainers };
export type Tag =
| { type: "ResourceType", params: {
resource: ResourceTarget["type"];
}}
| { type: "Server", params: {
server_id: string;
}}
| { type: "Custom", params: {
tag_id: string;
}};
export type WsLoginMessage =
| { type: "Jwt", params: {
jwt: string;