Skip to content

Commit

Permalink
Merge pull request #385 from umccr/fix/filemanager-credentials
Browse files Browse the repository at this point in the history
fix(filemanager): avoid using to_url_lossy when loading database credentials
  • Loading branch information
mmalenic authored Jul 1, 2024
2 parents 321366a + 4a5bcd2 commit ce4e4a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::database::aws::ingester::Ingester;
use crate::database::aws::ingester_paired::IngesterPaired;
use crate::env::Config;
use async_trait::async_trait;
use sea_orm::{ConnectOptions, Database, DatabaseConnection, SqlxPostgresConnector};
use sea_orm::{DatabaseConnection, SqlxPostgresConnector};
use sqlx::postgres::PgConnectOptions;
use sqlx::{ConnectOptions as SqlxConnectOptions, PgPool};
use sqlx::PgPool;
use tracing::debug;

use crate::error::Result;
Expand Down Expand Up @@ -49,28 +49,16 @@ impl Client {
generator: Option<impl CredentialGenerator>,
config: &Config,
) -> Result<Self> {
Ok(Self::new(Self::create_pool(generator, config).await?))
Ok(Self::from_pool(Self::create_pool(generator, config).await?))
}

/// Create a database connection pool using credential loading logic defined in
/// `Self::connect_options`.
pub async fn create_pool(
generator: Option<impl CredentialGenerator>,
config: &Config,
) -> Result<DatabaseConnection> {
Ok(Database::connect(Self::connect_options(generator, config).await?).await?)
}

/// Create database connect options using a series of credential loading logic.
pub async fn connect_options(
generator: Option<impl CredentialGenerator>,
config: &Config,
) -> Result<ConnectOptions> {
Ok(ConnectOptions::new(
Self::pg_connect_options(generator, config)
.await?
.to_url_lossy(),
))
) -> Result<PgPool> {
Ok(PgPool::connect_with(Self::pg_connect_options(generator, config).await?).await?)
}

/// Create database connect options using a series of credential loading logic.
Expand Down Expand Up @@ -117,6 +105,11 @@ impl Client {
pub fn connection_ref(&self) -> &DatabaseConnection {
&self.connection
}

/// Get the inner database connection.
pub fn into_inner(self) -> DatabaseConnection {
self.connection
}
}

#[async_trait]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ pub async fn ingest_s3_inventory(

/// Create a postgres database pool using an IAM credential generator.
pub async fn create_database_pool(env_config: &EnvConfig) -> Result<DatabaseConnection, Error> {
Ok(Client::create_pool(
let client = Client::from_generator(
Some(IamGeneratorBuilder::default().build(env_config).await?),
env_config,
)
.await?)
.await?;

Ok(client.into_inner())
}

/// Update connection options with new credentials.
Expand Down

0 comments on commit ce4e4a8

Please sign in to comment.