diff --git a/src/bldr/command/repo.rs b/src/bldr/command/repo.rs index e90013ad50..b0d470c6b4 100644 --- a/src/bldr/command/repo.rs +++ b/src/bldr/command/repo.rs @@ -46,5 +46,6 @@ use repo; /// /// * Fails if the repository fails to start - canot bind to the port, etc. pub fn start(config: &Config) -> BldrResult<()> { + println!("Repo listening on {:?}", config.repo_addr()); repo::run(&config) } diff --git a/src/bldr/config.rs b/src/bldr/config.rs index 6679ec4506..1f6ae37712 100644 --- a/src/bldr/config.rs +++ b/src/bldr/config.rs @@ -23,7 +23,10 @@ //! //! See the [Config](struct.Config.html) struct for the specific options available. +use std::net; + use topology::Topology; +use repo; #[derive(Debug, Clone, PartialEq, Eq)] /// An enum with the various CLI commands. Used to keep track of what command was called. @@ -60,6 +63,8 @@ pub struct Config { release: String, watch: Vec, key: String, + listen_addr: repo::ListenAddr, + port: repo::ListenPort, } impl Config { @@ -188,6 +193,15 @@ impl Config { pub fn topology(&self) -> &Topology { &self.topology } + + pub fn set_port(&mut self, port: u16) -> &mut Config { + self.port = repo::ListenPort(port); + self + } + + pub fn repo_addr(&self) -> net::SocketAddrV4 { + net::SocketAddrV4::new(self.listen_addr.0.clone(), self.port.0.clone()) + } } #[cfg(test)] diff --git a/src/bldr/repo.rs b/src/bldr/repo.rs index c044bc54cf..77f8fb02af 100644 --- a/src/bldr/repo.rs +++ b/src/bldr/repo.rs @@ -4,6 +4,7 @@ use iron::request::Body; use iron::headers; use router::Router; +use std::net; use std::sync::Arc; use std::fs::{self, File}; use std::io::{Read, Write, BufWriter}; @@ -25,6 +26,21 @@ impl Repo { } } +pub struct ListenAddr(pub net::Ipv4Addr); +pub struct ListenPort(pub u16); + +impl Default for ListenAddr { + fn default() -> Self { + ListenAddr(net::Ipv4Addr::new(0, 0, 0, 0)) + } +} + +impl Default for ListenPort { + fn default() -> Self { + ListenPort(9632) + } +} + fn write_file(path: PathBuf, filename: PathBuf, body: &mut Body) -> BldrResult { try!(fs::create_dir_all(path)); let tempfile = format!("{}.tmp", filename.to_string_lossy()); @@ -166,6 +182,6 @@ pub fn run(config: &Config) -> BldrResult<()> { router.post("/keys/:key", move |r: &mut Request| upload_key(&repo4, r)); router.get("/keys/:key", move |r: &mut Request| download_key(&repo5, r)); - Iron::new(router).http("0.0.0.0:9632").unwrap(); + Iron::new(router).http(config.repo_addr()).unwrap(); Ok(()) } diff --git a/src/main.rs b/src/main.rs index 2ed73d1a8e..e41cbdff64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ Usage: bldr install -u [-v ] [-r ] bldr start [--group=] [--topology=] [--watch=...] bldr sh bldr bash - bldr repo [-p ] + bldr repo [-p ] [--port=] bldr upload -u [-v ] [-r ] bldr key [-u ] bldr key-upload -u @@ -78,6 +78,7 @@ struct Args { arg_package: Option, arg_key: Option, flag_path: String, + flag_port: Option, flag_version: String, flag_release: String, flag_url: String, @@ -113,6 +114,9 @@ fn config_from_args(args: &Args, command: Command) -> BldrResult { t => return Err(BldrError::UnknownTopology(String::from(t))), } } + if let Some(port) = args.flag_port { + config.set_port(port); + } config.set_url(args.flag_url.clone()); config.set_group(args.flag_group.clone()); config.set_watch(args.flag_watch.clone());