From 930dbcca4e83c9cdf83cddda6c0f2ad9dfd23767 Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Wed, 21 Nov 2018 12:07:41 +0100 Subject: [PATCH] Small re-organisation of code for readability. --- src/pubc/config.rs | 2 +- src/pubd/server.rs | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/pubc/config.rs b/src/pubc/config.rs index e4d98ebf..4933c901 100644 --- a/src/pubc/config.rs +++ b/src/pubc/config.rs @@ -142,7 +142,7 @@ impl Config { }, _ => { Self::die( - "Expected subcommand (init, response, request, sync)" + "Expected sub-command (init, response, request, sync)" ); unreachable!() } diff --git a/src/pubd/server.rs b/src/pubd/server.rs index 9504d108..c067f618 100644 --- a/src/pubd/server.rs +++ b/src/pubd/server.rs @@ -49,6 +49,7 @@ pub struct PubServer { notify_sia: uri::Http } +/// # Set up and initialisation impl PubServer { /// Creates a new publication server. Note that state is preserved /// on disk in the work_dir provided. @@ -60,12 +61,10 @@ impl PubServer { rrdp_notification_uri: uri::Http ) -> Result { let store = CachingDiskKeyStore::new(PathBuf::from(&work_dir))?; - - let mut publisher_list = PublisherList::new( - work_dir.clone(), + let publisher_list = Self::init_publishers( + &work_dir, + pub_xml_dir, base_uri)?; - publisher_list.sync_from_dir(pub_xml_dir, actor())?; - let signer = OpenSslSigner::new(work_dir)?; Ok( @@ -79,8 +78,7 @@ impl PubServer { ) } - - /// Initialiase the publication server identity, if no identity had + /// Initialise the publication server identity, if no identity had /// been set up. Does nothing otherwise. pub fn init_identity_if_empty(&mut self) -> Result<(), Error> { match self.my_identity()? { @@ -101,12 +99,36 @@ impl PubServer { Ok(()) } + fn my_identity(&self) -> Result>, Error> { + self.store.get(&my_id_key()).map_err(|e| { Error::KeyStoreError(e)}) + } +} + +/// # Configure publishers +impl PubServer { + /// Synchronize publishers from disk + fn init_publishers( + work_dir: &PathBuf, + pub_xml_dir: PathBuf, + base_uri: uri::Rsync + ) -> Result { + let mut publisher_list = PublisherList::new( + work_dir.clone(), + base_uri)?; + publisher_list.sync_from_dir(pub_xml_dir, actor())?; + Ok(publisher_list) + } + + /// Returns all currently configured publishers. pub fn publishers(&self) -> Result>, Error> { self.publisher_list .publishers() .map_err(|e| { Error::PublisherListError(e) }) } + /// Returns a repository response for the given publisher. + /// + /// Returns an error if the publisher is unknown. pub fn repository_response( &self, publisher_name: &str @@ -140,12 +162,6 @@ impl PubServer { } else { Err(Error::Uninitialised) } - - } - - - fn my_identity(&self) -> Result>, Error> { - self.store.get(&my_id_key()).map_err(|e| { Error::KeyStoreError(e)}) } }