From 7bed8567a44f1d03dcaac2d0edc0d81ac1ac1adf Mon Sep 17 00:00:00 2001 From: Eric Ghildyal Date: Thu, 21 Nov 2024 16:38:10 -0500 Subject: [PATCH] Add rollback canary --- src/adapters/ingresses/apig.rs | 26 ++++++++++++++++++++++++++ src/adapters/ingresses/mod.rs | 6 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/adapters/ingresses/apig.rs b/src/adapters/ingresses/apig.rs index 3cba1c5..01ed46b 100644 --- a/src/adapters/ingresses/apig.rs +++ b/src/adapters/ingresses/apig.rs @@ -4,6 +4,7 @@ use crate::utils::load_default_aws_config; use super::Ingress; use async_trait::async_trait; +use aws_sdk_apigateway::types::{Op, PatchOperation}; use miette::miette; use miette::{IntoDiagnostic, Result}; use tokio::{fs::File, io::AsyncReadExt}; @@ -104,6 +105,25 @@ impl AwsApiGateway { Ok(()) } + + pub async fn delete_canary(&self, api_id: &str, stage_name: &str) -> Result<()> { + // Updates the stage to delete any canary settings from the API Gateway + let patch_op = PatchOperation::builder() + .op(Op::Remove) + .path("/canarySettings") + .build(); + + self.apig_client + .update_stage() + .rest_api_id(api_id) + .stage_name(stage_name) + .patch_operations(patch_op) + .send() + .await + .into_diagnostic()?; + + Ok(()) + } } /// given a path to a file, load it as an array of bytes. @@ -128,4 +148,10 @@ impl Ingress for AwsApiGateway { Ok(()) } + + async fn rollback_canary(&mut self) -> Result<()> { + self.delete_canary("Releases", "prod").await?; + + Ok(()) + } } diff --git a/src/adapters/ingresses/mod.rs b/src/adapters/ingresses/mod.rs index ba015d8..f73875f 100644 --- a/src/adapters/ingresses/mod.rs +++ b/src/adapters/ingresses/mod.rs @@ -10,7 +10,7 @@ pub trait Ingress { async fn deploy(&mut self) -> Result<()>; // TODO: define the other methods on this type. - // async fn yank_canary(&mut self) -> Result<()>; + async fn rollback_canary(&mut self) -> Result<()>; // async fn promote_canary(&mut self) -> Result<()>; // async fn set_canary_traffic(&mut self, percent: u8); } @@ -22,6 +22,10 @@ impl Ingress for MockIngress { async fn deploy(&mut self) -> Result<()> { todo!() } + + async fn rollback_canary(&mut self) -> Result<()> { + todo!() + } } impl From for BoxIngress {