Skip to content

Commit

Permalink
v1.2.2
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Jan 15, 2020
1 parent cd31581 commit c017e49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crisp-status-local"
version = "1.2.1"
version = "1.2.2"
description = "Crisp Status local probe relay."
readme = "README.md"
license = "MPL-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ You might find it convenient to run Crisp Status Local via Docker. You can find
First, pull the `crispim/crisp-status-local` image:

```bash
docker pull crispim/crisp-status-local:v1.2.1
docker pull crispim/crisp-status-local:v1.2.2
```

Then, seed it a configuration file and run it (replace `/path/to/your/crisp-status-local/config.cfg` with the path to your configuration file):

```bash
docker run -v /path/to/your/crisp-status-local/config.cfg:/etc/crisp-status-local.cfg crispim/crisp-status-local:v1.2.1
docker run -v /path/to/your/crisp-status-local/config.cfg:/etc/crisp-status-local.cfg crispim/crisp-status-local:v1.2.2
```

In the configuration file, ensure that:
Expand Down
37 changes: 23 additions & 14 deletions src/probe/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt;

use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer};
use url::Url;
use url::{Host, Url};

#[derive(Serialize, Debug, Clone)]
pub enum ReplicaURL {
Expand All @@ -20,21 +20,17 @@ pub enum ReplicaURL {
impl ReplicaURL {
pub fn parse_from(raw_url: &str) -> Result<ReplicaURL, ()> {
match Url::parse(raw_url) {
Ok(parsed_url) => match parsed_url.scheme() {
"tcp" => match (parsed_url.host_str(), parsed_url.port()) {
(Some(host), Some(port)) => {
Ok(ReplicaURL::TCP(raw_url.to_owned(), host.to_string(), port))
}
Ok(url) => match url.scheme() {
"tcp" => match (url.host(), url.port()) {
(Some(host), Some(port)) => Ok(ReplicaURL::TCP(
raw_url.to_owned(),
Self::host_string(host),
port,
)),
_ => Err(()),
},
"http" => Ok(ReplicaURL::HTTP(
raw_url.to_owned(),
parsed_url.into_string(),
)),
"https" => Ok(ReplicaURL::HTTPS(
raw_url.to_owned(),
parsed_url.into_string(),
)),
"http" => Ok(ReplicaURL::HTTP(raw_url.to_owned(), url.into_string())),
"https" => Ok(ReplicaURL::HTTPS(raw_url.to_owned(), url.into_string())),
_ => Err(()),
},
_ => Err(()),
Expand All @@ -48,6 +44,19 @@ impl ReplicaURL {
&ReplicaURL::HTTPS(ref raw_url, _) => raw_url,
}
}

fn host_string(host: Host<&str>) -> String {
// Convert internal host value into string. This is especially useful for IPv6 addresses, \
// which we need returned in '::1' format; as they would otherwise be returned in \
// '[::1]' format using built-in top-level 'to_string()' method on the 'Host' trait. The \
// underlying address parser does not accept IPv6 addresses formatted as '[::1]', so \
// this seemingly overkill processing is obviously needed.
match host {
Host::Domain(domain_value) => domain_value.to_string(),
Host::Ipv4(ipv4_value) => ipv4_value.to_string(),
Host::Ipv6(ipv6_value) => ipv6_value.to_string(),
}
}
}

impl<'de> Deserialize<'de> for ReplicaURL {
Expand Down

0 comments on commit c017e49

Please sign in to comment.