From 7a709c040529032da03e6ad9783a04b81338d268 Mon Sep 17 00:00:00 2001 From: Bly Kim Date: Fri, 3 Jan 2025 08:55:33 +0900 Subject: [PATCH] Update `insertNode` - `insertNode` GraphQL API no longer requires `config` for the `agents` parameter. --- CHANGELOG.md | 2 ++ src/graphql/node/control.rs | 11 ----------- src/graphql/node/crud.rs | 34 +++++++++++++++++++++++++++------- src/graphql/node/input.rs | 4 ++-- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e32aa..bb8d575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). that previously used source field as a parameter, and GraphQL APIs that return event, outlier, or triage related structs. - Updated review-database to 0.33.1. +- Updated `insertNode` GraphQL API to no longer require `config` for the + `agents` parameter. ### Fixed diff --git a/src/graphql/node/control.rs b/src/graphql/node/control.rs index c462b7f..9564c85 100644 --- a/src/graphql/node/control.rs +++ b/src/graphql/node/control.rs @@ -311,14 +311,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null @@ -1642,7 +1640,6 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "" }] giganto: null @@ -1785,14 +1782,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null @@ -1881,14 +1876,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null @@ -1962,14 +1955,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null @@ -2042,14 +2033,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null diff --git a/src/graphql/node/crud.rs b/src/graphql/node/crud.rs index e0ebe95..768738c 100644 --- a/src/graphql/node/crud.rs +++ b/src/graphql/node/crud.rs @@ -1,10 +1,9 @@ #![allow(clippy::fn_params_excessive_bools)] -use async_graphql::connection::OpaqueCursor; use async_graphql::{ - connection::{Connection, EmptyFields}, + connection::{Connection, EmptyFields, OpaqueCursor}, types::ID, - Context, Object, Result, + Context, Error, Object, Result, }; use chrono::Utc; use review_database::{Direction, Store}; @@ -12,7 +11,7 @@ use tracing::error; use super::{ super::{Role, RoleGuard}, - input::{AgentInput, GigantoInput, NodeDraftInput}, + input::{AgentDraftInput, GigantoInput, NodeDraftInput}, Node, NodeInput, NodeMutation, NodeQuery, NodeTotalCount, }; use crate::graphql::{ @@ -71,7 +70,7 @@ impl NodeMutation { customer_id: ID, description: String, hostname: String, - agents: Vec, + agents: Vec, giganto: Option, ) -> Result { let (id, customer_id) = { @@ -82,6 +81,29 @@ impl NodeMutation { .parse::() .map_err(|_| "invalid customer ID")?; + let agents: Vec = agents + .into_iter() + .map(|new_agent| { + let draft = match new_agent.draft { + Some(draft) => Some( + draft + .try_into() + .map_err(|_| Error::new("Failed to convert agent draft"))?, + ), + None => None, + }; + + Ok::<_, Error>(review_database::Agent { + node: u32::MAX, + key: new_agent.key, + kind: new_agent.kind.into(), + status: new_agent.status.into(), + config: None, + draft, + }) + }) + .collect::, _>>()?; + let value = review_database::Node { id: u32::MAX, name: name.clone(), @@ -220,14 +242,12 @@ mod tests { key: "unsupervised" kind: UNSUPERVISED status: ENABLED - config: null draft: "test = 'toml'" }, { key: "sensor" kind: SENSOR status: ENABLED - config: null draft: "test = 'toml'" }] giganto: null diff --git a/src/graphql/node/input.rs b/src/graphql/node/input.rs index 1ea3694..4ccd477 100644 --- a/src/graphql/node/input.rs +++ b/src/graphql/node/input.rs @@ -61,9 +61,9 @@ impl From for review_database::Agent { #[allow(clippy::module_name_repetitions)] #[derive(Clone, InputObject)] pub struct AgentDraftInput { - kind: AgentKind, + pub(super) kind: AgentKind, pub(super) key: String, - status: AgentStatus, + pub(super) status: AgentStatus, pub(super) draft: Option, }