mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-21 17:07:44 +02:00
Use a lazily initialised configuration static for easier access to config. (#268)
This commit is contained in:
Generated
+1
@@ -701,6 +701,7 @@ dependencies = [
|
||||
"hyper",
|
||||
"ignore",
|
||||
"intervaltree",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"libflate",
|
||||
"log 0.4.8",
|
||||
|
||||
@@ -29,6 +29,7 @@ futures-util = "0.3.4"
|
||||
hex = "^0.3"
|
||||
hyper = "^0.13"
|
||||
intervaltree = "0.2.6"
|
||||
lazy_static = "1.4.0"
|
||||
libflate = "1.0.0"
|
||||
log = "^0.4"
|
||||
openssl = { version = "^0.10", features = ["v110"] }
|
||||
|
||||
+3
-21
@@ -1,29 +1,11 @@
|
||||
extern crate krill;
|
||||
|
||||
use std::process;
|
||||
|
||||
use krill::commons::util::file;
|
||||
use krill::daemon::config::Config;
|
||||
use krill::daemon::http::server;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
match Config::create() {
|
||||
Ok(config) => {
|
||||
let pid_file = config.pid_file();
|
||||
if let Err(e) = file::save(process::id().to_string().as_bytes(), &pid_file) {
|
||||
eprintln!("Could not write PID file: {}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
if let Err(e) = server::start(config).await {
|
||||
eprintln!("Krill failed to start: {}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
if let Err(e) = server::start().await {
|
||||
eprintln!("Krill failed to start: {}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ mod tests {
|
||||
let ann_v6 = Announcement::from_str("2001:4:112::/48 => 112").unwrap();
|
||||
|
||||
let mut announcements = Announcements::default();
|
||||
announcements.update(vec![ann_v4.clone(), ann_v6.clone()]);
|
||||
announcements.update(vec![ann_v4, ann_v6]);
|
||||
|
||||
let matches = announcements.contained_by(ann_v4.prefix());
|
||||
assert_eq!(1, matches.len());
|
||||
|
||||
@@ -6,6 +6,7 @@ pub const KRILL_DEFAULT_CONFIG_FILE: &str = "./defaults/krill.conf";
|
||||
|
||||
pub const KRILL_ENV_TEST: &str = "KRILL_TEST";
|
||||
pub const KRILL_ENV_TEST_ANN: &str = "KRILL_TEST_ANN";
|
||||
pub const KRILL_ENV_TEST_UNIT_DATA: &str = "KRILL_TEST_UNIT_DATA";
|
||||
pub const KRILL_ENV_UPGRADE_ONLY: &str = "KRILL_UPGRADE_ONLY";
|
||||
pub const KRILL_ENV_REPO_ENABLED: &str = "KRILL_REPO_ENABLED";
|
||||
pub const KRILL_ENV_USE_TA: &str = "KRILL_USE_TA";
|
||||
|
||||
+46
-29
@@ -21,6 +21,18 @@ use crate::commons::util::ext_serde;
|
||||
use crate::constants::*;
|
||||
use crate::daemon::http::tls_keys;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: Config = {
|
||||
match Config::create() {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//------------ ConfigDefaults ------------------------------------------------
|
||||
|
||||
pub struct ConfigDefaults;
|
||||
@@ -349,37 +361,42 @@ impl Config {
|
||||
|
||||
/// Creates the config (at startup). Panics in case of issues.
|
||||
pub fn create() -> Result<Self, ConfigError> {
|
||||
let config_file = Self::get_config_filename();
|
||||
if let Ok(test_dir) = env::var(KRILL_ENV_TEST_UNIT_DATA) {
|
||||
let data_dir = PathBuf::from(test_dir);
|
||||
Ok(Config::test(&data_dir))
|
||||
} else {
|
||||
let config_file = Self::get_config_filename();
|
||||
|
||||
let config = match Self::read_config(&config_file) {
|
||||
Err(e) => {
|
||||
if config_file == KRILL_DEFAULT_CONFIG_FILE {
|
||||
Err(ConfigError::other(
|
||||
"Cannot find config file. Please use --config to specify its location.",
|
||||
))
|
||||
} else {
|
||||
Err(ConfigError::Other(format!(
|
||||
"Error parsing config file: {}, error: {}",
|
||||
config_file, e
|
||||
)))
|
||||
let config = match Self::read_config(&config_file) {
|
||||
Err(e) => {
|
||||
if config_file == KRILL_DEFAULT_CONFIG_FILE {
|
||||
Err(ConfigError::other(
|
||||
"Cannot find config file. Please use --config to specify its location.",
|
||||
))
|
||||
} else {
|
||||
Err(ConfigError::Other(format!(
|
||||
"Error parsing config file: {}, error: {}",
|
||||
config_file, e
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(config) => {
|
||||
config.init_logging()?;
|
||||
info!(
|
||||
"{} uses configuration file: {}",
|
||||
KRILL_SERVER_APP, config_file
|
||||
);
|
||||
Ok(config)
|
||||
}
|
||||
}?;
|
||||
config.verify().map_err(|e| {
|
||||
ConfigError::Other(format!(
|
||||
"Error parsing config file: {}, error: {}",
|
||||
config_file, e
|
||||
))
|
||||
})?;
|
||||
Ok(config)
|
||||
Ok(config) => {
|
||||
config.init_logging()?;
|
||||
info!(
|
||||
"{} uses configuration file: {}",
|
||||
KRILL_SERVER_APP, config_file
|
||||
);
|
||||
Ok(config)
|
||||
}
|
||||
}?;
|
||||
config.verify().map_err(|e| {
|
||||
ConfigError::Other(format!(
|
||||
"Error parsing config file: {}, error: {}",
|
||||
config_file, e
|
||||
))
|
||||
})?;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify(&self) -> Result<(), ConfigError> {
|
||||
|
||||
+25
-17
@@ -5,6 +5,7 @@ use std::convert::Infallible;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -14,7 +15,6 @@ use serde::Serialize;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use futures::TryFutureExt;
|
||||
|
||||
use hyper;
|
||||
use hyper::server::conn::AddrIncoming;
|
||||
use hyper::service::{make_service_fn, service_fn};
|
||||
@@ -26,8 +26,9 @@ use crate::commons::api::{
|
||||
};
|
||||
use crate::commons::error::Error;
|
||||
use crate::commons::remote::rfc8183;
|
||||
use crate::commons::util::file;
|
||||
use crate::constants::KRILL_ENV_UPGRADE_ONLY;
|
||||
use crate::daemon::config::Config;
|
||||
use crate::daemon::config::CONFIG;
|
||||
use crate::daemon::http::statics::statics;
|
||||
use crate::daemon::http::{tls, tls_keys, HttpResponse, Request, RequestPath, RoutingResult};
|
||||
use crate::daemon::krillserver::KrillServer;
|
||||
@@ -37,15 +38,21 @@ use crate::upgrades::{post_start_upgrade, pre_start_upgrade};
|
||||
|
||||
pub type State = Arc<RwLock<KrillServer>>;
|
||||
|
||||
pub async fn start(config: Config) -> Result<(), Error> {
|
||||
pub async fn start() -> Result<(), Error> {
|
||||
let pid_file = CONFIG.pid_file();
|
||||
if let Err(e) = file::save(process::id().to_string().as_bytes(), &pid_file) {
|
||||
eprintln!("Could not write PID file: {}", e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
// Call upgrade, this will only do actual work if needed.
|
||||
pre_start_upgrade(&config.data_dir)
|
||||
pre_start_upgrade(&CONFIG.data_dir)
|
||||
.map_err(|e| Error::Custom(format!("Could not upgrade Krill: {}", e)))?;
|
||||
|
||||
// Create the server, this will create the necessary data sub-directories if needed
|
||||
let krill = KrillServer::build(&config)?;
|
||||
let krill = KrillServer::build()?;
|
||||
|
||||
post_start_upgrade(&config.data_dir, &krill)
|
||||
post_start_upgrade(&CONFIG.data_dir, &krill)
|
||||
.map_err(|e| Error::Custom(format!("Could not upgrade Krill: {}", e)))?;
|
||||
|
||||
if env::var(KRILL_ENV_UPGRADE_ONLY).is_ok() {
|
||||
@@ -65,17 +72,17 @@ pub async fn start(config: Config) -> Result<(), Error> {
|
||||
}
|
||||
});
|
||||
|
||||
tls_keys::create_key_cert_if_needed(&config.data_dir)
|
||||
tls_keys::create_key_cert_if_needed(&CONFIG.data_dir)
|
||||
.map_err(|e| Error::HttpsSetup(format!("{}", e)))?;
|
||||
|
||||
let server_config_builder = tls::TlsConfigBuilder::new()
|
||||
.cert_path(tls_keys::cert_file_path(&config.data_dir))
|
||||
.key_path(tls_keys::key_file_path(&config.data_dir));
|
||||
.cert_path(tls_keys::cert_file_path(&CONFIG.data_dir))
|
||||
.key_path(tls_keys::key_file_path(&CONFIG.data_dir));
|
||||
let server_config = server_config_builder.build().unwrap();
|
||||
|
||||
let acceptor = tls::TlsAcceptor::new(
|
||||
server_config,
|
||||
AddrIncoming::bind(&config.socket_addr()).unwrap(),
|
||||
AddrIncoming::bind(&CONFIG.socket_addr()).unwrap(),
|
||||
);
|
||||
|
||||
let server = hyper::Server::builder(acceptor)
|
||||
@@ -1169,19 +1176,20 @@ mod tests {
|
||||
use crate::test;
|
||||
|
||||
use super::*;
|
||||
use crate::constants::KRILL_ENV_TEST_UNIT_DATA;
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_tls_server() {
|
||||
let dir = test::sub_dir(&PathBuf::from("work"));
|
||||
|
||||
let server_conf = {
|
||||
// Use a data dir for the storage
|
||||
let data_dir = test::sub_dir(&dir);
|
||||
Config::test(&data_dir)
|
||||
};
|
||||
let data_dir = test::sub_dir(&dir);
|
||||
env::set_var(
|
||||
KRILL_ENV_TEST_UNIT_DATA,
|
||||
data_dir.to_string_lossy().to_string(),
|
||||
);
|
||||
|
||||
tokio::spawn(super::start(server_conf));
|
||||
tokio::spawn(super::start());
|
||||
|
||||
assert!(test::primary_server_ready().await);
|
||||
assert!(test::server_ready().await);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -27,7 +27,7 @@ use crate::commons::{KrillEmptyResult, KrillResult};
|
||||
use crate::constants::*;
|
||||
use crate::daemon::auth::{Auth, Authorizer};
|
||||
use crate::daemon::ca::{self, ta_handle};
|
||||
use crate::daemon::config::Config;
|
||||
use crate::daemon::config::CONFIG;
|
||||
use crate::daemon::mq::EventQueueListener;
|
||||
use crate::daemon::scheduler::Scheduler;
|
||||
use crate::pubd::{PubServer, RepoStats};
|
||||
@@ -47,7 +47,7 @@ pub struct KrillServer {
|
||||
// Component responsible for API authorization checks
|
||||
authorizer: Authorizer,
|
||||
|
||||
// Publication server, with configured publishers
|
||||
// Publication server, with CONFIGured publishers
|
||||
pubserver: Option<Arc<PubServer>>,
|
||||
|
||||
// Handles the internal TA and/or CAs
|
||||
@@ -97,13 +97,13 @@ impl PostLimits {
|
||||
impl KrillServer {
|
||||
/// Creates a new publication server. Note that state is preserved
|
||||
/// on disk in the work_dir provided.
|
||||
pub fn build(config: &Config) -> KrillResult<Self> {
|
||||
let work_dir = &config.data_dir;
|
||||
let base_uri = &config.rsync_base;
|
||||
let service_uri = config.service_uri();
|
||||
let rrdp_base_uri = &config.rrdp_service_uri();
|
||||
let token = &config.auth_token;
|
||||
let ca_refresh_rate = config.ca_refresh;
|
||||
pub fn build() -> KrillResult<Self> {
|
||||
let work_dir = &CONFIG.data_dir;
|
||||
let base_uri = &CONFIG.rsync_base;
|
||||
let service_uri = CONFIG.service_uri();
|
||||
let rrdp_base_uri = &CONFIG.rrdp_service_uri();
|
||||
let token = &CONFIG.auth_token;
|
||||
let ca_refresh_rate = CONFIG.ca_refresh;
|
||||
|
||||
info!("Starting {} v{}", KRILL_SERVER_APP, KRILL_VERSION);
|
||||
info!("{} uses service uri: {}", KRILL_SERVER_APP, service_uri);
|
||||
@@ -117,12 +117,12 @@ impl KrillServer {
|
||||
let authorizer = Authorizer::new(token);
|
||||
|
||||
let pubserver = {
|
||||
if config.repo_enabled {
|
||||
if CONFIG.repo_enabled {
|
||||
Some(PubServer::build(
|
||||
&base_uri,
|
||||
rrdp_base_uri.clone(),
|
||||
work_dir,
|
||||
config.rfc8181_log_dir.as_ref(),
|
||||
CONFIG.rfc8181_log_dir.as_ref(),
|
||||
signer.clone(),
|
||||
)?)
|
||||
} else {
|
||||
@@ -130,7 +130,7 @@ impl KrillServer {
|
||||
&base_uri,
|
||||
rrdp_base_uri.clone(),
|
||||
work_dir,
|
||||
config.rfc8181_log_dir.as_ref(),
|
||||
CONFIG.rfc8181_log_dir.as_ref(),
|
||||
signer.clone(),
|
||||
)?
|
||||
}
|
||||
@@ -140,13 +140,13 @@ impl KrillServer {
|
||||
let event_queue = Arc::new(EventQueueListener::in_mem());
|
||||
let caserver = Arc::new(ca::CaServer::build(
|
||||
work_dir,
|
||||
config.rfc8181_log_dir.as_ref(),
|
||||
config.rfc6492_log_dir.as_ref(),
|
||||
CONFIG.rfc8181_log_dir.as_ref(),
|
||||
CONFIG.rfc6492_log_dir.as_ref(),
|
||||
event_queue.clone(),
|
||||
signer,
|
||||
)?);
|
||||
|
||||
if config.use_ta() {
|
||||
if CONFIG.use_ta() {
|
||||
let ta_handle = ta_handle();
|
||||
if !caserver.has_ca(&ta_handle) {
|
||||
info!("Creating embedded Trust Anchor");
|
||||
@@ -156,9 +156,9 @@ impl KrillServer {
|
||||
.ok_or_else(|| Error::PublisherNoEmbeddedRepo)?;
|
||||
let repo_info: RepoInfo = pubserver.repo_info_for(&ta_handle)?;
|
||||
|
||||
let ta_uri = config.ta_cert_uri();
|
||||
let ta_uri = CONFIG.ta_cert_uri();
|
||||
|
||||
let ta_aia = format!("{}ta/ta.cer", config.rsync_base.to_string());
|
||||
let ta_aia = format!("{}ta/ta.cer", CONFIG.rsync_base.to_string());
|
||||
let ta_aia = uri::Rsync::from_string(ta_aia).unwrap();
|
||||
|
||||
// Add TA
|
||||
@@ -178,9 +178,9 @@ impl KrillServer {
|
||||
}
|
||||
|
||||
let bgp_analyser = Arc::new(BgpAnalyser::new(
|
||||
config.bgp_risdumps_enabled,
|
||||
&config.bgp_risdumps_v4_uri,
|
||||
&config.bgp_risdumps_v6_uri,
|
||||
CONFIG.bgp_risdumps_enabled,
|
||||
&CONFIG.bgp_risdumps_v4_uri,
|
||||
&CONFIG.bgp_risdumps_v6_uri,
|
||||
));
|
||||
|
||||
let scheduler = Scheduler::build(
|
||||
@@ -192,9 +192,9 @@ impl KrillServer {
|
||||
);
|
||||
|
||||
let post_limits = PostLimits::new(
|
||||
config.post_limit_api,
|
||||
config.post_limit_rfc6492,
|
||||
config.post_limit_rfc8181,
|
||||
CONFIG.post_limit_api,
|
||||
CONFIG.post_limit_rfc6492,
|
||||
CONFIG.post_limit_rfc8181,
|
||||
);
|
||||
|
||||
Ok(KrillServer {
|
||||
@@ -238,7 +238,7 @@ impl KrillServer {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Configure publishers
|
||||
/// # CONFIGure publishers
|
||||
impl KrillServer {
|
||||
fn get_embedded(&self) -> KrillResult<&Arc<PubServer>> {
|
||||
self.pubserver
|
||||
@@ -251,7 +251,7 @@ impl KrillServer {
|
||||
self.get_embedded()?.repo_stats()
|
||||
}
|
||||
|
||||
/// Returns all currently configured publishers. (excludes deactivated)
|
||||
/// Returns all currently CONFIGured publishers. (excludes deactivated)
|
||||
pub fn publishers(&self) -> KrillResult<Vec<Handle>> {
|
||||
self.get_embedded()?.publishers()
|
||||
}
|
||||
@@ -578,7 +578,7 @@ impl KrillServer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return the info about the configured repository server for a given Ca.
|
||||
/// Return the info about the CONFIGured repository server for a given Ca.
|
||||
/// and the actual objects published there, as reported by a list reply.
|
||||
pub fn ca_repo_details(&self, handle: &Handle) -> KrillResult<CaRepoDetails> {
|
||||
let ca = self.caserver.get_ca(handle)?;
|
||||
@@ -586,7 +586,7 @@ impl KrillServer {
|
||||
Ok(CaRepoDetails::new(contact.clone()))
|
||||
}
|
||||
|
||||
/// Returns the state of the current configured repo for a ca
|
||||
/// Returns the state of the current CONFIGured repo for a ca
|
||||
pub async fn ca_repo_state(&self, handle: &Handle) -> KrillResult<CurrentRepoState> {
|
||||
let ca = self.caserver.get_ca(handle)?;
|
||||
let contact = ca.get_repository_contact()?;
|
||||
|
||||
@@ -12,6 +12,8 @@ extern crate futures_util;
|
||||
extern crate hex;
|
||||
extern crate hyper;
|
||||
extern crate intervaltree;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate libflate;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
+23
-66
@@ -1,11 +1,11 @@
|
||||
//! Helper functions for testing Krill.
|
||||
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use std::{env, fs};
|
||||
|
||||
use bytes::Bytes;
|
||||
use rand::{thread_rng, Rng};
|
||||
@@ -29,29 +29,17 @@ use crate::commons::bgp::Announcement;
|
||||
use crate::commons::remote::rfc8183;
|
||||
use crate::commons::remote::rfc8183::ChildRequest;
|
||||
use crate::commons::util::httpclient;
|
||||
use crate::constants::KRILL_ENV_TEST_UNIT_DATA;
|
||||
use crate::daemon::ca::ta_handle;
|
||||
use crate::daemon::config::Config;
|
||||
use crate::daemon::http::server;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum PubdTestContext {
|
||||
Main,
|
||||
Secondary,
|
||||
}
|
||||
const SERVER_URI: &str = "https://localhost:3000/";
|
||||
|
||||
pub async fn primary_server_ready() -> bool {
|
||||
server_ready("https://localhost:3000/health").await
|
||||
}
|
||||
|
||||
pub async fn secondary_server_ready() -> bool {
|
||||
server_ready("https://localhost:3001/health").await
|
||||
}
|
||||
|
||||
pub async fn server_ready(uri: &str) -> bool {
|
||||
pub async fn server_ready() -> bool {
|
||||
for _ in 0..300 {
|
||||
match httpclient::client(uri).await {
|
||||
match httpclient::client(SERVER_URI).await {
|
||||
Ok(client) => {
|
||||
let res = timeout(Duration::from_millis(100), client.get(uri).send()).await;
|
||||
let res = timeout(Duration::from_millis(100), client.get(SERVER_URI).send()).await;
|
||||
if let Ok(Ok(res)) = res {
|
||||
if res.status() == StatusCode::OK {
|
||||
return true;
|
||||
@@ -71,67 +59,29 @@ pub async fn server_ready(uri: &str) -> bool {
|
||||
pub async fn start_krill() -> PathBuf {
|
||||
let dir = tmp_dir();
|
||||
|
||||
let server_conf = {
|
||||
// Use a data dir for the storage
|
||||
let data_dir = sub_dir(&dir);
|
||||
Config::test(&data_dir)
|
||||
};
|
||||
let data_dir = sub_dir(&dir);
|
||||
|
||||
tokio::spawn(server::start(server_conf));
|
||||
env::set_var(
|
||||
KRILL_ENV_TEST_UNIT_DATA,
|
||||
data_dir.to_string_lossy().to_string(),
|
||||
);
|
||||
|
||||
assert!(primary_server_ready().await);
|
||||
tokio::spawn(server::start());
|
||||
|
||||
assert!(server_ready().await);
|
||||
dir
|
||||
}
|
||||
|
||||
pub async fn start_secondary_krill(base_dir: &PathBuf) {
|
||||
let data_dir = sub_dir(base_dir);
|
||||
let server_conf = Config::pubd_test(&data_dir);
|
||||
|
||||
tokio::spawn(server::start(server_conf));
|
||||
|
||||
assert!(secondary_server_ready().await);
|
||||
}
|
||||
|
||||
pub async fn krill_admin(command: Command) -> ApiResponse {
|
||||
let krillc_opts = Options::new(
|
||||
https("https://localhost:3000/"),
|
||||
"secret",
|
||||
ReportFormat::Json,
|
||||
command,
|
||||
);
|
||||
let krillc_opts = Options::new(https(SERVER_URI), "secret", ReportFormat::Json, command);
|
||||
match KrillClient::process(krillc_opts).await {
|
||||
Ok(res) => res, // ok
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn krill_admin_secondary(command: Command) -> ApiResponse {
|
||||
let krillc_opts = Options::new(
|
||||
https("https://localhost:3001/"),
|
||||
"secret",
|
||||
ReportFormat::Json,
|
||||
command,
|
||||
);
|
||||
match KrillClient::process(krillc_opts).await {
|
||||
Ok(res) => res, // ok
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn krill_pubd_admin(command: Command, server: PubdTestContext) -> ApiResponse {
|
||||
match server {
|
||||
PubdTestContext::Main => krill_admin(command).await,
|
||||
PubdTestContext::Secondary => krill_admin_secondary(command).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn krill_admin_expect_error(command: Command) -> Error {
|
||||
let krillc_opts = Options::new(
|
||||
https("https://localhost:3000/"),
|
||||
"secret",
|
||||
ReportFormat::Json,
|
||||
command,
|
||||
);
|
||||
let krillc_opts = Options::new(https(SERVER_URI), "secret", ReportFormat::Json, command);
|
||||
match KrillClient::process(krillc_opts).await {
|
||||
Ok(_res) => panic!("Expected error"),
|
||||
Err(e) => e,
|
||||
@@ -142,6 +92,13 @@ async fn refresh_all() {
|
||||
krill_admin(Command::Bulk(BulkCaCommand::Refresh)).await;
|
||||
}
|
||||
|
||||
pub async fn init_child(handle: &Handle) {
|
||||
krill_admin(Command::CertAuth(CaCommand::Init(CertAuthInit::new(
|
||||
handle.clone(),
|
||||
))))
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn init_child_with_embedded_repo(handle: &Handle) {
|
||||
krill_admin(Command::CertAuth(CaCommand::Init(CertAuthInit::new(
|
||||
handle.clone(),
|
||||
|
||||
+4
-8
@@ -53,16 +53,12 @@ fn make_server(work_dir: &PathBuf, scenario: &str) -> CaServer<OpenSslSigner> {
|
||||
server_cas_dir.push("cas");
|
||||
file::backup_dir(&source, &server_cas_dir).unwrap();
|
||||
|
||||
let server = {
|
||||
let signer = OpenSslSigner::build(&server_dir).unwrap();
|
||||
let signer = Arc::new(RwLock::new(signer));
|
||||
let signer = OpenSslSigner::build(&server_dir).unwrap();
|
||||
let signer = Arc::new(RwLock::new(signer));
|
||||
|
||||
let event_queue = Arc::new(EventQueueListener::in_mem());
|
||||
let event_queue = Arc::new(EventQueueListener::in_mem());
|
||||
|
||||
CaServer::<OpenSslSigner>::build(&server_dir, None, None, event_queue, signer).unwrap()
|
||||
};
|
||||
|
||||
server
|
||||
CaServer::<OpenSslSigner>::build(&server_dir, None, None, event_queue, signer).unwrap()
|
||||
}
|
||||
|
||||
fn assert_history(server: &CaServer<OpenSslSigner>, scenario: &str, ca: &Handle) {
|
||||
|
||||
+23
-98
@@ -8,9 +8,6 @@ use std::time::Duration;
|
||||
|
||||
use tokio::time::delay_for;
|
||||
|
||||
use rpki::manifest::Manifest;
|
||||
use rpki::roa::Roa;
|
||||
|
||||
use krill::cli::options::{CaCommand, Command, PublishersCommand};
|
||||
use krill::cli::report::ApiResponse;
|
||||
use krill::commons::api::{
|
||||
@@ -21,32 +18,25 @@ use krill::commons::remote::rfc8183;
|
||||
use krill::daemon::ca::ta_handle;
|
||||
use krill::test::{
|
||||
add_child_to_ta_embedded, add_parent_to_ca, ca_gets_resources, ca_route_authorizations_update,
|
||||
init_child_with_embedded_repo, krill_admin, krill_pubd_admin, start_krill,
|
||||
start_secondary_krill, PubdTestContext,
|
||||
init_child, krill_admin, start_krill,
|
||||
};
|
||||
|
||||
async fn repository_response(
|
||||
publisher: &PublisherHandle,
|
||||
server: PubdTestContext,
|
||||
) -> rfc8183::RepositoryResponse {
|
||||
async fn repository_response(publisher: &PublisherHandle) -> rfc8183::RepositoryResponse {
|
||||
let command = Command::Publishers(PublishersCommand::RepositoryResponse(publisher.clone()));
|
||||
match krill_pubd_admin(command, server).await {
|
||||
match krill_admin(command).await {
|
||||
ApiResponse::Rfc8183RepositoryResponse(response) => response,
|
||||
_ => panic!("Expected repository response."),
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_publisher(req: rfc8183::PublisherRequest, server: PubdTestContext) {
|
||||
async fn add_publisher(req: rfc8183::PublisherRequest) {
|
||||
let command = Command::Publishers(PublishersCommand::AddPublisher(req));
|
||||
krill_pubd_admin(command, server).await;
|
||||
krill_admin(command).await;
|
||||
}
|
||||
|
||||
async fn details_publisher(
|
||||
publisher: &PublisherHandle,
|
||||
server: PubdTestContext,
|
||||
) -> PublisherDetails {
|
||||
async fn details_publisher(publisher: &PublisherHandle) -> PublisherDetails {
|
||||
let command = Command::Publishers(PublishersCommand::ShowPublisher(publisher.clone()));
|
||||
match krill_pubd_admin(command, server).await {
|
||||
match krill_admin(command).await {
|
||||
ApiResponse::PublisherDetails(details) => details,
|
||||
_ => panic!("Expected publisher details"),
|
||||
}
|
||||
@@ -92,17 +82,6 @@ async fn will_publish(ca: &Handle, number: usize) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
async fn will_clean(publisher: &Handle, context: PubdTestContext) -> bool {
|
||||
for _ in 0..300 {
|
||||
let details = details_publisher(publisher, context).await;
|
||||
if details.current_files().is_empty() {
|
||||
return true;
|
||||
}
|
||||
delay_for(Duration::from_millis(100)).await
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// This tests that you can run krill with an embedded TA and CA, and
|
||||
/// have the CA publish at another krill instance which is is set up
|
||||
/// as a publication server only (i.e. it just has no TA and CAs).
|
||||
@@ -110,28 +89,33 @@ async fn will_clean(publisher: &Handle, context: PubdTestContext) -> bool {
|
||||
async fn remote_publication() {
|
||||
let dir = start_krill().await;
|
||||
|
||||
start_secondary_krill(&dir).await;
|
||||
|
||||
let ta_handle = ta_handle();
|
||||
|
||||
let child = unsafe { Handle::from_str_unsafe("child") };
|
||||
|
||||
// Set up child as a child of the TA
|
||||
init_child_with_embedded_repo(&child).await;
|
||||
init_child(&child).await;
|
||||
|
||||
let child_resources = ResourceSet::from_strs("", "10.0.0.0/16", "").unwrap();
|
||||
|
||||
let parent = {
|
||||
let parent_contact = add_child_to_ta_embedded(&child, child_resources.clone()).await;
|
||||
ParentCaReq::new(ta_handle, parent_contact)
|
||||
};
|
||||
|
||||
add_parent_to_ca(&child, parent).await;
|
||||
assert!(ca_gets_resources(&child, &child_resources).await);
|
||||
|
||||
// Child should now publish using the embedded repo
|
||||
let child_repo_details = repo_details(&child).await;
|
||||
assert!(child_repo_details.contact().is_embedded());
|
||||
assert!(will_publish(&child, 2).await);
|
||||
// Let child use the remote protocol instead
|
||||
let publisher_request = publisher_request(&child).await;
|
||||
add_publisher(publisher_request).await;
|
||||
|
||||
// Get a Repository Response for the child CA
|
||||
let response = repository_response(&child).await;
|
||||
|
||||
// Update the repo for the child
|
||||
let update = RepositoryUpdate::Rfc8181(response);
|
||||
repo_update(&child, update).await;
|
||||
|
||||
assert!(ca_gets_resources(&child, &child_resources).await);
|
||||
|
||||
// Add some roas to have more to migrate when moving publication servers
|
||||
let route_1 = RoaDefinition::from_str("10.0.0.0/24 => 64496").unwrap();
|
||||
@@ -141,72 +125,13 @@ async fn remote_publication() {
|
||||
updates.add(route_2);
|
||||
ca_route_authorizations_update(&child, updates).await;
|
||||
|
||||
// Add child to the secondary publication server
|
||||
let publisher_request = publisher_request(&child).await;
|
||||
add_publisher(publisher_request, PubdTestContext::Secondary).await;
|
||||
|
||||
// The child should now be known at the pub server and have no files
|
||||
let details_at_pubd = details_publisher(&child, PubdTestContext::Secondary).await;
|
||||
assert_eq!(details_at_pubd.current_files().len(), 0);
|
||||
|
||||
// Get a Repository Response for the child CA
|
||||
let response = repository_response(&child, PubdTestContext::Secondary).await;
|
||||
|
||||
// Update the repo for the child
|
||||
let update = RepositoryUpdate::Rfc8181(response);
|
||||
repo_update(&child, update).await;
|
||||
|
||||
// Child should now publish using the remote repo
|
||||
let child_repo_details = repo_details(&child).await;
|
||||
assert!(child_repo_details.contact().is_rfc8183());
|
||||
|
||||
assert!(will_publish(&child, 4).await);
|
||||
// Test that the new repo URI is used in newly published objects
|
||||
|
||||
let details = details_publisher(&child, PubdTestContext::Secondary).await;
|
||||
|
||||
let mft = details
|
||||
.current_files()
|
||||
.iter()
|
||||
.find(|e| e.uri().ends_with(".mft"))
|
||||
.unwrap();
|
||||
let mft = Manifest::decode(mft.base64().to_bytes(), true).unwrap();
|
||||
let mft_uri = mft.cert().signed_object().unwrap();
|
||||
let crl_uri = mft.cert().crl_uri().unwrap();
|
||||
assert!(mft_uri.to_string().starts_with("rsync://remotehost/repo/"));
|
||||
assert!(crl_uri.to_string().starts_with("rsync://remotehost/repo/"));
|
||||
|
||||
for roa in details
|
||||
.current_files()
|
||||
.iter()
|
||||
.filter(|e| e.uri().ends_with(".roa"))
|
||||
{
|
||||
let roa = Roa::decode(roa.base64().to_bytes(), true).unwrap();
|
||||
let roa_uri = roa.cert().signed_object().unwrap();
|
||||
let crl_uri = roa.cert().crl_uri().unwrap();
|
||||
assert!(roa_uri.to_string().starts_with("rsync://remotehost/repo/"));
|
||||
assert!(crl_uri.to_string().starts_with("rsync://remotehost/repo/"));
|
||||
}
|
||||
|
||||
// Child should now clean up the old repo
|
||||
assert!(will_clean(&child, PubdTestContext::Main).await);
|
||||
|
||||
// Now let's migrate back, so that we see that works too.
|
||||
|
||||
// Get a Repository Response for the child CA
|
||||
let response = repository_response(&child, PubdTestContext::Main).await;
|
||||
|
||||
// Update the repo for the child
|
||||
let update = RepositoryUpdate::Rfc8181(response);
|
||||
repo_update(&child, update).await;
|
||||
|
||||
// Child should now publish using the main repo
|
||||
let child_repo_details = repo_details(&child).await;
|
||||
assert!(child_repo_details.contact().is_rfc8183());
|
||||
assert!(will_publish(&child, 4).await);
|
||||
|
||||
// Child should now clean up the secondary repo
|
||||
assert!(will_clean(&child, PubdTestContext::Secondary).await);
|
||||
let details = details_publisher(&child).await;
|
||||
assert_eq!(4, details.current_files().len());
|
||||
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user