use crate::rest_api::{BindConfig, RestApiServerError};
use super::{ResourceProvider, RestApi};
pub struct RunnableRestApi {
pub(super) resource_providers: Vec<Box<dyn ResourceProvider>>,
pub(super) bind: BindConfig,
}
impl RunnableRestApi {
pub fn run(self) -> Result<RestApi, RestApiServerError> {
let RunnableRestApi {
resource_providers,
bind,
} = self;
let (bind_url, acceptor_opt) = match bind {
BindConfig::Https {
bind,
cert_path,
key_path,
} => {
let mut acceptor =
openssl::ssl::SslAcceptor::mozilla_modern(openssl::ssl::SslMethod::tls())?;
acceptor.set_private_key_file(key_path, openssl::ssl::SslFiletype::PEM)?;
acceptor.set_certificate_chain_file(&cert_path)?;
acceptor.check_private_key()?;
(bind, Some(acceptor))
}
BindConfig::Http(url) => (url, None),
};
RestApi::new(bind_url, acceptor_opt, resource_providers)
}
}