-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TCP port exposure via "--expose" command-line argument (#70)
- Loading branch information
Showing
8 changed files
with
294 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anyhow::{anyhow, Context, Error}; | ||
use std::str::FromStr; | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct ExposedPort { | ||
pub external_port: u16, | ||
pub internal_port: u16, | ||
} | ||
|
||
impl FromStr for ExposedPort { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let splits: Vec<&str> = s.split(':').collect(); | ||
|
||
match splits.len() { | ||
2 => Ok(ExposedPort { | ||
external_port: splits[0] | ||
.parse() | ||
.context(format!("invalid external port {:?}", splits[0]))?, | ||
internal_port: splits[1] | ||
.parse() | ||
.context(format!("invalid internal port {:?}", splits[1]))?, | ||
}), | ||
_ => Err(anyhow!( | ||
"invalid exposed port specification {:?}, the format should be EXTERNAL:INTERNAL", | ||
s | ||
)), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::proxy::exposed_port::ExposedPort; | ||
|
||
#[test] | ||
fn exposed_port() { | ||
assert_eq!( | ||
ExposedPort { | ||
external_port: 2222, | ||
internal_port: 22 | ||
}, | ||
"2222:22".parse().unwrap() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.