use std::collections::BTreeMap;
use std::net::SocketAddr;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
pub use shuttle_common::{
database,
deployment::{DeploymentMetadata, Environment},
project::ProjectName,
resource::Type,
DatabaseReadyInfo, DbInput, DbOutput, SecretStore,
};
pub mod error;
pub use error::{CustomError, Error};
#[cfg(feature = "builder")]
pub mod builder;
#[async_trait]
pub trait Factory: Send + Sync {
async fn get_db_connection(
&mut self,
db_type: database::Type,
) -> Result<DatabaseReadyInfo, crate::Error>;
async fn get_secrets(&mut self) -> Result<BTreeMap<String, String>, crate::Error>;
fn get_metadata(&self) -> DeploymentMetadata;
}
#[async_trait]
pub trait ResourceBuilder<T> {
const TYPE: Type;
type Config: Serialize;
type Output: Serialize + DeserializeOwned;
fn new() -> Self;
fn config(&self) -> &Self::Config;
async fn output(self, factory: &mut dyn Factory) -> Result<Self::Output, crate::Error>;
async fn build(build_data: &Self::Output) -> Result<T, crate::Error>;
}
#[async_trait]
pub trait Service: Send {
async fn bind(mut self, addr: SocketAddr) -> Result<(), error::Error>;
}