Skip to content

Commit

Permalink
populate https_frontends in ConfigState
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 4, 2023
1 parent 565dbd6 commit 87b4d96
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ impl ConfigState {
.replace_certificate(replace)
.with_context(|| "Could not replace certificate"),
Request::AddHttpsFrontend(front) => self
.add_http_frontend(front)
.add_https_frontend(front)
.with_context(|| "Could not add HTTPS frontend"),
Request::RemoveHttpsFrontend(front) => self
.remove_http_frontend(front)
.remove_https_frontend(front)
.with_context(|| "Could not remove HTTPS frontend"),
Request::AddTcpFrontend(front) => self
.add_tcp_frontend(front)
Expand Down Expand Up @@ -296,6 +296,14 @@ impl ConfigState {
Ok(())
}

fn add_https_frontend(&mut self, front: &RequestHttpFrontend) -> anyhow::Result<()> {
match self.https_fronts.entry(front.to_string()) {
BTreeMapEntry::Vacant(e) => e.insert(front.clone().to_frontend()?),
BTreeMapEntry::Occupied(_) => bail!("This frontend is already present: {:?}", front),
};
Ok(())
}

fn remove_http_frontend(&mut self, front: &RequestHttpFrontend) -> anyhow::Result<()> {
if self.http_fronts.remove(&front.to_string()).is_none() {
let error_msg = match &front.cluster_id {
Expand All @@ -310,6 +318,20 @@ impl ConfigState {
Ok(())
}

fn remove_https_frontend(&mut self, front: &RequestHttpFrontend) -> anyhow::Result<()> {
if self.https_fronts.remove(&front.to_string()).is_none() {
let error_msg = match &front.cluster_id {
Some(cluster_id) => format!(
"No such frontend at {} for the cluster {}",
front.address, cluster_id
),
None => format!("No such frontend at {}", front.address),
};
bail!(error_msg);
}
Ok(())
}

fn add_certificate(&mut self, add: &AddCertificate) -> anyhow::Result<()> {
let fingerprint = Fingerprint(
calculate_fingerprint(add.certificate.certificate.as_bytes())
Expand Down

0 comments on commit 87b4d96

Please sign in to comment.