From 8ac3a8ce8ba268a3261e23694b8b62afa6a3ae37 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 1 Nov 2023 16:45:29 +0100 Subject: implement an AnyCredentials --- src/login/mod.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/login') diff --git a/src/login/mod.rs b/src/login/mod.rs index f403bcb..5bd976e 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -16,8 +16,6 @@ use rusoto_s3::S3Client; use crate::cryptoblob::*; use crate::storage::*; -use crate::storage::in_memory::MemTypes; -use crate::storage::garage::GrgTypes; /// The trait LoginProvider defines the interface for a login provider that allows /// to retrieve storage and cryptographic credentials for access to a user account @@ -32,19 +30,28 @@ pub trait LoginProvider { async fn public_login(&self, email: &str) -> Result; } -pub enum AnyCredentials { - InMemory(Credentials), - Garage(Credentials), -} - /// ArcLoginProvider is simply an alias on a structure that is used /// in many places in the code pub type ArcLoginProvider = Arc; +pub enum AnyCredentials { + InMemory(Credentials), + Garage(Credentials), +} +impl AnyCredentials where X: Sto +{ + fn to_gen(&self) -> Credentials { + match self { + Self::InMemory(u) => u, + Self::Garage(u) => u, + } + } +} + /// The struct Credentials represent all of the necessary information to interact /// with a user account's data after they are logged in. #[derive(Clone, Debug)] -pub struct Credentials { +pub struct Credentials { /// The storage credentials are used to authenticate access to the underlying storage (S3, K2V) pub storage: T::Builder, /// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V @@ -114,7 +121,7 @@ impl Region { // ---- -/* + impl Credentials { pub fn k2v_client(&self) -> Result { self.storage.k2v_client() @@ -125,14 +132,6 @@ impl Credentials { pub fn bucket(&self) -> &str { self.storage.bucket.as_str() } -}*/ -impl From for Credentials { - fn from(ac: AnyCredentials) -> Self { - match ac { - AnyCredentials::InMemory(c) => c, - AnyCredentials::Garage(c) => c, - } - } } impl StorageCredentials { -- cgit v1.2.3