Skip to content

Commit

Permalink
Add rollback canary
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGhildyal committed Nov 21, 2024
1 parent 39ec82c commit 7bed856
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/adapters/ingresses/apig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand All @@ -128,4 +148,10 @@ impl Ingress for AwsApiGateway {

Ok(())
}

async fn rollback_canary(&mut self) -> Result<()> {
self.delete_canary("Releases", "prod").await?;

Ok(())
}
}
6 changes: 5 additions & 1 deletion src/adapters/ingresses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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<MockIngress> for BoxIngress {
Expand Down

0 comments on commit 7bed856

Please sign in to comment.