diff --git a/bin/core/src/helpers/mod.rs b/bin/core/src/helpers/mod.rs index 4524b88e6..da2ba21bb 100644 --- a/bin/core/src/helpers/mod.rs +++ b/bin/core/src/helpers/mod.rs @@ -1,13 +1,14 @@ use std::time::Duration; use anyhow::{anyhow, Context}; +use mongo_indexed::Document; use monitor_client::entities::{ permission::{Permission, PermissionLevel, UserTarget}, server::Server, update::ResourceTarget, user::User, }; -use mungos::mongodb::bson::doc; +use mungos::mongodb::bson::{doc, Bson}; use periphery_client::PeripheryClient; use rand::{thread_rng, Rng}; @@ -117,3 +118,23 @@ pub async fn create_permission( error!("failed to create permission for {target:?} | {e:#}"); }; } + +/// Flattens a document only one level deep +/// +/// eg `{ config: { label: "yes", thing: { field1: "ok", field2: "ok" } } }` -> +/// `{ "config.label": "yes", "config.thing": { field1: "ok", field2: "ok" } }` +pub fn flatten_document(doc: Document) -> Document { + let mut target = Document::new(); + + for (outer_field, bson) in doc { + if let Bson::Document(doc) = bson { + for (inner_field, bson) in doc { + target.insert(format!("{outer_field}.{inner_field}"), bson); + } + } else { + target.insert(outer_field, bson); + } + } + + target +} diff --git a/bin/core/src/resource/mod.rs b/bin/core/src/resource/mod.rs index af2682e83..9029b3b9a 100644 --- a/bin/core/src/resource/mod.rs +++ b/bin/core/src/resource/mod.rs @@ -31,7 +31,7 @@ use serror::serialize_error_pretty; use crate::{ config::core_config, helpers::{ - create_permission, + create_permission, flatten_document, query::{ get_resource_ids_for_non_admin, get_tag, get_user_permission_on_resource, id_or_name_filter, @@ -422,10 +422,12 @@ pub async fn update( let config_doc = T::update_document(resource, config) .context("failed to serialize config to bson document")?; + let update_doc = flatten_document(doc! { "config": config_doc }); + update_one_by_id( T::coll().await, &id, - mungos::update::Update::FlattenSet(doc! { "config": config_doc }), + doc! { "$set": update_doc }, None, ) .await diff --git a/frontend/src/components/config/util.tsx b/frontend/src/components/config/util.tsx index 6f1a603e1..b240d72ca 100644 --- a/frontend/src/components/config/util.tsx +++ b/frontend/src/components/config/util.tsx @@ -588,6 +588,7 @@ const REGISTRY_TYPES: Types.ImageRegistry["type"][] = [ "None", "DockerHub", "Ghcr", + "AwsEcr" ]; const RegistryTypeSelector = ({