You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-21 23:00:50 +03:00
storage: ensure the repository trait can be boxed
and define some wrappers to map the errors
This commit is contained in:
@@ -12,7 +12,22 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use mas_storage::Repository;
|
||||
use mas_storage::{
|
||||
compat::{
|
||||
CompatAccessTokenRepository, CompatRefreshTokenRepository, CompatSessionRepository,
|
||||
CompatSsoLoginRepository,
|
||||
},
|
||||
oauth2::{
|
||||
OAuth2AccessTokenRepository, OAuth2AuthorizationGrantRepository, OAuth2ClientRepository,
|
||||
OAuth2RefreshTokenRepository, OAuth2SessionRepository,
|
||||
},
|
||||
upstream_oauth2::{
|
||||
UpstreamOAuthLinkRepository, UpstreamOAuthProviderRepository,
|
||||
UpstreamOAuthSessionRepository,
|
||||
},
|
||||
user::{BrowserSessionRepository, UserEmailRepository, UserPasswordRepository, UserRepository},
|
||||
Repository,
|
||||
};
|
||||
use sqlx::{PgPool, Postgres, Transaction};
|
||||
|
||||
use crate::{
|
||||
@@ -59,84 +74,95 @@ impl PgRepository {
|
||||
impl Repository for PgRepository {
|
||||
type Error = DatabaseError;
|
||||
|
||||
type UpstreamOAuthLinkRepository<'c> = PgUpstreamOAuthLinkRepository<'c> where Self: 'c;
|
||||
type UpstreamOAuthProviderRepository<'c> = PgUpstreamOAuthProviderRepository<'c> where Self: 'c;
|
||||
type UpstreamOAuthSessionRepository<'c> = PgUpstreamOAuthSessionRepository<'c> where Self: 'c;
|
||||
type UserRepository<'c> = PgUserRepository<'c> where Self: 'c;
|
||||
type UserEmailRepository<'c> = PgUserEmailRepository<'c> where Self: 'c;
|
||||
type UserPasswordRepository<'c> = PgUserPasswordRepository<'c> where Self: 'c;
|
||||
type BrowserSessionRepository<'c> = PgBrowserSessionRepository<'c> where Self: 'c;
|
||||
type OAuth2ClientRepository<'c> = PgOAuth2ClientRepository<'c> where Self: 'c;
|
||||
type OAuth2AuthorizationGrantRepository<'c> = PgOAuth2AuthorizationGrantRepository<'c> where Self: 'c;
|
||||
type OAuth2SessionRepository<'c> = PgOAuth2SessionRepository<'c> where Self: 'c;
|
||||
type OAuth2AccessTokenRepository<'c> = PgOAuth2AccessTokenRepository<'c> where Self: 'c;
|
||||
type OAuth2RefreshTokenRepository<'c> = PgOAuth2RefreshTokenRepository<'c> where Self: 'c;
|
||||
type CompatSessionRepository<'c> = PgCompatSessionRepository<'c> where Self: 'c;
|
||||
type CompatSsoLoginRepository<'c> = PgCompatSsoLoginRepository<'c> where Self: 'c;
|
||||
type CompatAccessTokenRepository<'c> = PgCompatAccessTokenRepository<'c> where Self: 'c;
|
||||
type CompatRefreshTokenRepository<'c> = PgCompatRefreshTokenRepository<'c> where Self: 'c;
|
||||
|
||||
fn upstream_oauth_link(&mut self) -> Self::UpstreamOAuthLinkRepository<'_> {
|
||||
PgUpstreamOAuthLinkRepository::new(&mut self.txn)
|
||||
fn upstream_oauth_link<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn UpstreamOAuthLinkRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUpstreamOAuthLinkRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn upstream_oauth_provider(&mut self) -> Self::UpstreamOAuthProviderRepository<'_> {
|
||||
PgUpstreamOAuthProviderRepository::new(&mut self.txn)
|
||||
fn upstream_oauth_provider<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn UpstreamOAuthProviderRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUpstreamOAuthProviderRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn upstream_oauth_session(&mut self) -> Self::UpstreamOAuthSessionRepository<'_> {
|
||||
PgUpstreamOAuthSessionRepository::new(&mut self.txn)
|
||||
fn upstream_oauth_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn UpstreamOAuthSessionRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUpstreamOAuthSessionRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn user(&mut self) -> Self::UserRepository<'_> {
|
||||
PgUserRepository::new(&mut self.txn)
|
||||
fn user<'c>(&'c mut self) -> Box<dyn UserRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUserRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn user_email(&mut self) -> Self::UserEmailRepository<'_> {
|
||||
PgUserEmailRepository::new(&mut self.txn)
|
||||
fn user_email<'c>(&'c mut self) -> Box<dyn UserEmailRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUserEmailRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn user_password(&mut self) -> Self::UserPasswordRepository<'_> {
|
||||
PgUserPasswordRepository::new(&mut self.txn)
|
||||
fn user_password<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn UserPasswordRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgUserPasswordRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn browser_session(&mut self) -> Self::BrowserSessionRepository<'_> {
|
||||
PgBrowserSessionRepository::new(&mut self.txn)
|
||||
fn browser_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn BrowserSessionRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgBrowserSessionRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn oauth2_client(&mut self) -> Self::OAuth2ClientRepository<'_> {
|
||||
PgOAuth2ClientRepository::new(&mut self.txn)
|
||||
fn oauth2_client<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn OAuth2ClientRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgOAuth2ClientRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn oauth2_authorization_grant(&mut self) -> Self::OAuth2AuthorizationGrantRepository<'_> {
|
||||
PgOAuth2AuthorizationGrantRepository::new(&mut self.txn)
|
||||
fn oauth2_authorization_grant<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn OAuth2AuthorizationGrantRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgOAuth2AuthorizationGrantRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn oauth2_session(&mut self) -> Self::OAuth2SessionRepository<'_> {
|
||||
PgOAuth2SessionRepository::new(&mut self.txn)
|
||||
fn oauth2_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn OAuth2SessionRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgOAuth2SessionRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn oauth2_access_token(&mut self) -> Self::OAuth2AccessTokenRepository<'_> {
|
||||
PgOAuth2AccessTokenRepository::new(&mut self.txn)
|
||||
fn oauth2_access_token<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn OAuth2AccessTokenRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgOAuth2AccessTokenRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn oauth2_refresh_token(&mut self) -> Self::OAuth2RefreshTokenRepository<'_> {
|
||||
PgOAuth2RefreshTokenRepository::new(&mut self.txn)
|
||||
fn oauth2_refresh_token<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn OAuth2RefreshTokenRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgOAuth2RefreshTokenRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn compat_session(&mut self) -> Self::CompatSessionRepository<'_> {
|
||||
PgCompatSessionRepository::new(&mut self.txn)
|
||||
fn compat_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn CompatSessionRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgCompatSessionRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn compat_sso_login(&mut self) -> Self::CompatSsoLoginRepository<'_> {
|
||||
PgCompatSsoLoginRepository::new(&mut self.txn)
|
||||
fn compat_sso_login<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn CompatSsoLoginRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgCompatSsoLoginRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn compat_access_token(&mut self) -> Self::CompatAccessTokenRepository<'_> {
|
||||
PgCompatAccessTokenRepository::new(&mut self.txn)
|
||||
fn compat_access_token<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn CompatAccessTokenRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgCompatAccessTokenRepository::new(&mut self.txn))
|
||||
}
|
||||
|
||||
fn compat_refresh_token(&mut self) -> Self::CompatRefreshTokenRepository<'_> {
|
||||
PgCompatRefreshTokenRepository::new(&mut self.txn)
|
||||
fn compat_refresh_token<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn CompatRefreshTokenRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(PgCompatRefreshTokenRepository::new(&mut self.txn))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user