1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

storage: wrap the postgres repository in a struct

This commit is contained in:
Quentin Gliech
2023-01-13 18:03:37 +01:00
parent 488a666a8d
commit 195203823a
44 changed files with 505 additions and 548 deletions

View File

@@ -31,10 +31,9 @@ use mas_http::HttpServiceExt;
use mas_iana::oauth::OAuthClientAuthenticationMethod;
use mas_jose::{jwk::PublicJsonWebKeySet, jwt::Jwt};
use mas_keystore::Encrypter;
use mas_storage::{oauth2::OAuth2ClientRepository, DatabaseError, Repository};
use mas_storage::{oauth2::OAuth2ClientRepository, Repository};
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value;
use sqlx::PgConnection;
use thiserror::Error;
use tower::{Service, ServiceExt};
@@ -73,7 +72,10 @@ pub enum Credentials {
}
impl Credentials {
pub async fn fetch(&self, conn: &mut PgConnection) -> Result<Option<Client>, DatabaseError> {
pub async fn fetch<'r, R>(&self, repo: &'r mut R) -> Result<Option<Client>, R::Error>
where
R: Repository,
{
let client_id = match self {
Credentials::None { client_id }
| Credentials::ClientSecretBasic { client_id, .. }
@@ -81,7 +83,7 @@ impl Credentials {
| Credentials::ClientAssertionJwtBearer { client_id, .. } => client_id,
};
conn.oauth2_client().find_by_client_id(client_id).await
repo.oauth2_client().find_by_client_id(client_id).await
}
#[tracing::instrument(skip_all, err)]