pub struct DatabaseEngine { /* private fields */ }Expand description
The database secrets engine.
Stores connection configs and role definitions in the barrier-encrypted storage. Credential generation creates a random username/password pair and returns them with a lease.
Implementations§
Source§impl DatabaseEngine
impl DatabaseEngine
Sourcepub fn new(barrier: Arc<Barrier>, prefix: String) -> Self
pub fn new(barrier: Arc<Barrier>, prefix: String) -> Self
Create a new database engine with the given barrier and storage prefix.
§Errors
Returns DatabaseError if the barrier is sealed or storage fails.
Sourcepub async fn configure(
&self,
config: DatabaseConfig,
) -> Result<(), DatabaseError>
pub async fn configure( &self, config: DatabaseConfig, ) -> Result<(), DatabaseError>
Configure a database connection.
§Errors
Returns DatabaseError::InvalidConfig if required fields are missing.
Returns DatabaseError::Barrier if the barrier is sealed.
Sourcepub async fn get_config(
&self,
name: &str,
) -> Result<DatabaseConfig, DatabaseError>
pub async fn get_config( &self, name: &str, ) -> Result<DatabaseConfig, DatabaseError>
Read a database connection config by name.
§Errors
Returns DatabaseError::NotFound if the config does not exist.
Sourcepub async fn delete_config(&self, name: &str) -> Result<(), DatabaseError>
pub async fn delete_config(&self, name: &str) -> Result<(), DatabaseError>
Delete a database connection config.
§Errors
Returns DatabaseError::Barrier if the barrier is sealed.
Sourcepub async fn list_configs(&self) -> Result<Vec<String>, DatabaseError>
pub async fn list_configs(&self) -> Result<Vec<String>, DatabaseError>
List all configured database connections.
§Errors
Returns DatabaseError::Barrier if the barrier is sealed.
Sourcepub async fn create_role(&self, role: DatabaseRole) -> Result<(), DatabaseError>
pub async fn create_role(&self, role: DatabaseRole) -> Result<(), DatabaseError>
Create a role definition.
§Errors
Returns DatabaseError::InvalidConfig if required fields are missing.
Sourcepub async fn get_role(&self, name: &str) -> Result<DatabaseRole, DatabaseError>
pub async fn get_role(&self, name: &str) -> Result<DatabaseRole, DatabaseError>
Sourcepub async fn delete_role(&self, name: &str) -> Result<(), DatabaseError>
pub async fn delete_role(&self, name: &str) -> Result<(), DatabaseError>
Sourcepub async fn list_roles(&self) -> Result<Vec<String>, DatabaseError>
pub async fn list_roles(&self) -> Result<Vec<String>, DatabaseError>
Sourcepub async fn generate_credentials(
&self,
role_name: &str,
) -> Result<(DatabaseCredentials, DatabaseRole), DatabaseError>
pub async fn generate_credentials( &self, role_name: &str, ) -> Result<(DatabaseCredentials, DatabaseRole), DatabaseError>
Generate credentials for a role.
Creates a random username and password. In a production deployment, these would be executed against the actual database. For now, the credentials are generated and returned — the caller is responsible for creating a lease.
§Errors
Returns DatabaseError::RoleNotFound if the role does not exist.
Returns DatabaseError::NotFound if the referenced config is missing.