Skip to content

Commit

Permalink
cloud/config: simplify message output (#2063)
Browse files Browse the repository at this point in the history
## Description

Fixes a UX issue where a message was not returned to the user on
sucessful update of a cloud router config.
  • Loading branch information
loshz committed Aug 19, 2024
1 parent 0155065 commit d9faa38
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
18 changes: 6 additions & 12 deletions crates/rover-client/src/operations/cloud/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub struct CloudConfigFetchResponse {
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CloudConfigUpdateInput {
pub struct CloudConfigInput {
pub graph_ref: GraphRef,
pub config: String,
}

impl From<CloudConfigUpdateInput> for UpdateQueryVariables {
fn from(input: CloudConfigUpdateInput) -> Self {
impl From<CloudConfigInput> for UpdateQueryVariables {
fn from(input: CloudConfigInput) -> Self {
Self {
graph_id: input.graph_ref.name,
variant: input.graph_ref.variant,
Expand All @@ -45,14 +45,8 @@ impl From<CloudConfigUpdateInput> for UpdateQueryVariables {
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CloudConfigValidateInput {
pub graph_ref: GraphRef,
pub config: String,
}

impl From<CloudConfigValidateInput> for ValidateQueryVariables {
fn from(input: CloudConfigValidateInput) -> Self {
impl From<CloudConfigInput> for ValidateQueryVariables {
fn from(input: CloudConfigInput) -> Self {
Self {
ref_: input.graph_ref.to_string(),
config: RouterConfigInput {
Expand All @@ -66,6 +60,6 @@ impl From<CloudConfigValidateInput> for ValidateQueryVariables {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CloudConfigValidateResponse {
pub struct CloudConfigResponse {
pub msg: String,
}
12 changes: 7 additions & 5 deletions crates/rover-client/src/operations/cloud/config/update.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use graphql_client::*;

use crate::blocking::StudioClient;
use crate::operations::cloud::config::types::CloudConfigUpdateInput;
use crate::operations::cloud::config::types::{CloudConfigInput, CloudConfigResponse};
use crate::shared::GraphRef;
use crate::RoverClientError;

Expand All @@ -22,9 +22,9 @@ use cloud_config_update_query::CloudConfigUpdateQueryGraphVariantUpsertRouterCon
pub struct CloudConfigUpdateQuery;

pub async fn run(
input: CloudConfigUpdateInput,
input: CloudConfigInput,
client: &StudioClient,
) -> Result<(), RoverClientError> {
) -> Result<CloudConfigResponse, RoverClientError> {
let graph_ref = input.graph_ref.clone();
let data = client.post::<CloudConfigUpdateQuery>(input.into()).await?;
build_response(graph_ref, data)
Expand All @@ -33,7 +33,7 @@ pub async fn run(
fn build_response(
graph_ref: GraphRef,
data: cloud_config_update_query::ResponseData,
) -> Result<(), RoverClientError> {
) -> Result<CloudConfigResponse, RoverClientError> {
let variant = data
.graph
.ok_or_else(|| RoverClientError::GraphNotFound {
Expand All @@ -46,7 +46,9 @@ fn build_response(

match variant.upsert_router_config {
// Router config successfully update.
Some(GraphVariant { .. }) => Ok(()),
Some(GraphVariant { .. }) => Ok(CloudConfigResponse {
msg: "Successfully updated cloud router config!".to_string(),
}),
// Error upserting router config.
Some(RouterUpsertFailure(OnRouterUpsertFailure { message })) => {
Err(RoverClientError::InvalidRouterConfig { msg: message })
Expand Down
12 changes: 6 additions & 6 deletions crates/rover-client/src/operations/cloud/config/validate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::types::{CloudConfigValidateInput, CloudConfigValidateResponse};
use super::types::{CloudConfigInput, CloudConfigResponse};

use graphql_client::*;

Expand All @@ -24,9 +24,9 @@ use crate::RoverClientError;
pub struct CloudConfigValidateQuery;

pub async fn run(
input: CloudConfigValidateInput,
input: CloudConfigInput,
client: &StudioClient,
) -> Result<CloudConfigValidateResponse, RoverClientError> {
) -> Result<CloudConfigResponse, RoverClientError> {
let graph_ref = input.graph_ref.clone();
let data = client
.post::<CloudConfigValidateQuery>(input.into())
Expand All @@ -37,7 +37,7 @@ pub async fn run(
fn build_response(
graph_ref: GraphRef,
data: cloud_config_validate_query::ResponseData,
) -> Result<CloudConfigValidateResponse, RoverClientError> {
) -> Result<CloudConfigResponse, RoverClientError> {
let graph_variant = match data.variant {
Some(GraphVariant(gv)) => gv,
_ => {
Expand All @@ -48,7 +48,7 @@ fn build_response(
};

match graph_variant.validate_router {
CloudValidationSuccess(res) => Ok(CloudConfigValidateResponse { msg: res.message }),
CloudValidationSuccess(res) => Ok(CloudConfigResponse { msg: res.message }),
InvalidInputErrors(e) => Err(RoverClientError::InvalidRouterConfig { msg: e.message }),
InternalServerError(e) => Err(RoverClientError::ClientError { msg: e.message }),
}
Expand Down Expand Up @@ -82,7 +82,7 @@ mod tests {
let data = serde_json::from_value(json_response).unwrap();
let output = build_response(mock_graph_ref(), data);

let expected = CloudConfigValidateResponse {
let expected = CloudConfigResponse {
msg: "No errors!".to_string(),
};
assert!(output.is_ok());
Expand Down
16 changes: 7 additions & 9 deletions src/command/cloud/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{RoverOutput, RoverResult};
use rover_client::blocking::StudioClient;
use rover_client::operations::cloud::config::{
fetch,
types::{CloudConfigFetchInput, CloudConfigUpdateInput, CloudConfigValidateInput},
types::{CloudConfigFetchInput, CloudConfigInput},
update, validate,
};

Expand Down Expand Up @@ -100,16 +100,16 @@ impl Config {

let config = file.read_file_descriptor("Cloud Router config", &mut std::io::stdin())?;

update::run(
CloudConfigUpdateInput {
let res = update::run(
CloudConfigInput {
graph_ref: graph.graph_ref.clone(),
config,
},
&client,
)
.await?;

Ok(RoverOutput::EmptySuccess)
Ok(RoverOutput::MessageResponse { msg: res.msg })
}

pub async fn validate(
Expand All @@ -122,17 +122,15 @@ impl Config {

let config = file.read_file_descriptor("Cloud Router config", &mut std::io::stdin())?;

let validation = validate::run(
CloudConfigValidateInput {
let res = validate::run(
CloudConfigInput {
graph_ref: graph.graph_ref.clone(),
config,
},
&client,
)
.await?;

Ok(RoverOutput::MessageResponse {
msg: validation.msg,
})
Ok(RoverOutput::MessageResponse { msg: res.msg })
}
}

0 comments on commit d9faa38

Please sign in to comment.