diff --git a/src/adapters/ingresses/apig.rs b/src/adapters/ingresses/apig.rs index ea5c4f2..2270ca4 100644 --- a/src/adapters/ingresses/apig.rs +++ b/src/adapters/ingresses/apig.rs @@ -184,6 +184,38 @@ impl AwsApiGateway { Ok(()) } + + pub async fn promote_apig_canary(&self, api_name: &str, stage_name: &str) -> Result<()> { + let api = self.get_api_id_by_name(api_name).await?; + + // Overwrite the main deployment's ID with the canary's + let replace_deployment_op = PatchOperation::builder() + .op(Op::Copy) + .from("/canarySettings/deploymentId") + .path("/deploymentId") + .build(); + + // Reset canary traffic to 0% so we're ready for another release + let reset_traffic_op = PatchOperation::builder() + .op(Op::Replace) + .path("/canarySettings/percentTraffic") + // Note: this must be a string to pass into Value, but it's actually an f64 in AWS + .value("0.0") + .build(); + + // Send request to update stage + self.apig_client + .update_stage() + .rest_api_id(api.id.unwrap_or_default()) + .stage_name(stage_name) + .patch_operations(replace_deployment_op) + .patch_operations(reset_traffic_op) + .send() + .await + .into_diagnostic()?; + + Ok(()) + } } /// given a path to a file, load it as an array of bytes. @@ -228,4 +260,10 @@ impl Ingress for AwsApiGateway { Ok(()) } + + async fn promote_canary(&mut self) -> Result<()> { + self.promote_apig_canary("Releases", "prod").await?; + + Ok(()) + } } diff --git a/src/adapters/ingresses/mod.rs b/src/adapters/ingresses/mod.rs index 83bbf08..1b2a7b1 100644 --- a/src/adapters/ingresses/mod.rs +++ b/src/adapters/ingresses/mod.rs @@ -16,6 +16,9 @@ pub trait Ingress { async fn rollback_canary(&mut self) -> Result<()>; // async fn promote_canary(&mut self) -> Result<()>; async fn set_canary_traffic(&mut self, percent: WholePercent) -> Result<()>; + // async fn yank_canary(&mut self) -> Result<()>; + async fn promote_canary(&mut self) -> Result<()>; + // async fn set_canary_traffic(&mut self, percent: u8); } pub struct MockIngress; @@ -33,6 +36,10 @@ impl Ingress for MockIngress { async fn rollback_canary(&mut self) -> Result<()> { todo!() } + + async fn promote_canary(&mut self) -> Result<()> { + todo!() + } } impl From for BoxIngress {