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

View File

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

View File

@@ -69,7 +69,7 @@ pub(crate) enum 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
T: AsRef<str>,
{
@@ -156,29 +156,24 @@ impl JSONTokens {
None
}
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Option<Token>)
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Token)
where
T: AsRef<str>,
{
eprintln!("setting: {:?}, {:?}", scopes.hash, token);
self.tokens.retain(|x| x.hash != scopes.hash);
match token {
None => (),
Some(t) => {
self.tokens.push(JSONToken {
hash: scopes.hash,
scopes: Some(
scopes
.scopes
.iter()
.map(|x| x.as_ref().to_string())
.collect(),
),
token: t,
});
}
}
self.tokens.push(JSONToken {
hash: scopes.hash,
scopes: Some(
scopes
.scopes
.iter()
.map(|x| x.as_ref().to_string())
.collect(),
),
token,
});
}
// 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
T: AsRef<str>,
{