storage set method should just accept a Token rather than Option<Token>.

No caller ever provided a None value. Presumably a None value should
delete the token, but it didn't do that and that would be more clearly
done with a remove or delete method.
This commit is contained in:
Glenn Griffin
2019-11-15 09:48:18 -08:00
parent 4b4b2fe3f4
commit b70d07aac2
3 changed files with 17 additions and 22 deletions

View File

@@ -59,7 +59,7 @@ where
} }
Ok(token) => token, Ok(token) => token,
}; };
self.storage.set(hashed_scopes, Some(token.clone())).await; self.storage.set(hashed_scopes, token.clone()).await;
Ok(token) Ok(token)
} }
None None
@@ -72,7 +72,7 @@ where
.auth_flow .auth_flow
.token(&self.hyper_client, &self.app_secret, scopes) .token(&self.hyper_client, &self.app_secret, scopes)
.await?; .await?;
self.storage.set(hashed_scopes, Some(t.clone())).await; self.storage.set(hashed_scopes, t.clone()).await;
Ok(t) Ok(t)
} }
} }

View File

@@ -277,7 +277,7 @@ where
scopes, scopes,
) )
.await?; .await?;
cache.set(hashed_scopes, Some(token.clone())).await; cache.set(hashed_scopes, token.clone()).await;
Ok(token) Ok(token)
} }
/// Send a request for a new Bearer token to the OAuth provider. /// Send a request for a new Bearer token to the OAuth provider.

View File

@@ -69,7 +69,7 @@ pub(crate) enum Storage {
} }
impl Storage { impl Storage {
pub(crate) async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Option<Token>) pub(crate) async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Token)
where where
T: AsRef<str>, T: AsRef<str>,
{ {
@@ -156,29 +156,24 @@ impl JSONTokens {
None None
} }
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Option<Token>) fn set<T>(&mut self, scopes: HashedScopes<T>, token: Token)
where where
T: AsRef<str>, T: AsRef<str>,
{ {
eprintln!("setting: {:?}, {:?}", scopes.hash, token); eprintln!("setting: {:?}, {:?}", scopes.hash, token);
self.tokens.retain(|x| x.hash != scopes.hash); self.tokens.retain(|x| x.hash != scopes.hash);
match token { self.tokens.push(JSONToken {
None => (), hash: scopes.hash,
Some(t) => { scopes: Some(
self.tokens.push(JSONToken { scopes
hash: scopes.hash, .scopes
scopes: Some( .iter()
scopes .map(|x| x.as_ref().to_string())
.scopes .collect(),
.iter() ),
.map(|x| x.as_ref().to_string()) token,
.collect(), });
),
token: t,
});
}
}
} }
// TODO: ideally this function would accept &Path, but tokio requires the // TODO: ideally this function would accept &Path, but tokio requires the
@@ -219,7 +214,7 @@ impl DiskStorage {
}) })
} }
async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Option<Token>) async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Token)
where where
T: AsRef<str>, T: AsRef<str>,
{ {