Skip to content

Commit

Permalink
Update insertNode
Browse files Browse the repository at this point in the history
- `insertNode` GraphQL API no longer requires `config` for the `agents` parameter.
  • Loading branch information
BLYKIM committed Jan 2, 2025
1 parent 6ddaa0b commit 7a709c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/graphql/node/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1642,7 +1640,6 @@ mod tests {
key: "unsupervised"
kind: UNSUPERVISED
status: ENABLED
config: null
draft: ""
}]
giganto: null
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions src/graphql/node/crud.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#![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};
use tracing::error;

use super::{
super::{Role, RoleGuard},
input::{AgentInput, GigantoInput, NodeDraftInput},
input::{AgentDraftInput, GigantoInput, NodeDraftInput},
Node, NodeInput, NodeMutation, NodeQuery, NodeTotalCount,
};
use crate::graphql::{
Expand Down Expand Up @@ -71,7 +70,7 @@ impl NodeMutation {
customer_id: ID,
description: String,
hostname: String,
agents: Vec<AgentInput>,
agents: Vec<AgentDraftInput>,
giganto: Option<GigantoInput>,
) -> Result<ID> {
let (id, customer_id) = {
Expand All @@ -82,6 +81,29 @@ impl NodeMutation {
.parse::<u32>()
.map_err(|_| "invalid customer ID")?;

let agents: Vec<review_database::Agent> = 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::<Result<Vec<_>, _>>()?;

let value = review_database::Node {
id: u32::MAX,
name: name.clone(),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/node/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl From<AgentInput> 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<String>,
}

Expand Down

0 comments on commit 7a709c0

Please sign in to comment.