JSONToken should always contain scopes.

This is already the case when writing a token file. Presumably the only
reason it was an Option was for backwards compatibility, but we're
already breaking compatibility with the change to the hash value so this
seems like an appropriate time to make the change.

This change also highlights how unused the hash value has been
previously. Future changes plan to use the hash value for more efficient
handling.
This commit is contained in:
Glenn Griffin
2019-11-15 09:57:28 -08:00
parent b70d07aac2
commit baa8d56653

View File

@@ -94,7 +94,7 @@ impl Storage {
#[derive(Debug, Clone, Serialize, Deserialize)]
struct JSONToken {
pub hash: u64,
pub scopes: Option<Vec<String>>,
pub scopes: Vec<String>,
pub token: Token,
}
@@ -141,15 +141,11 @@ impl JSONTokens {
T: AsRef<str>,
{
for t in self.tokens.iter() {
if let Some(token_scopes) = &t.scopes {
if scopes
.scopes
.iter()
.all(|s| token_scopes.iter().any(|t| t == s.as_ref()))
{
return Some(t.token.clone());
}
} else if scopes.hash == t.hash {
if scopes
.scopes
.iter()
.all(|s| t.scopes.iter().any(|t| t == s.as_ref()))
{
return Some(t.token.clone());
}
}
@@ -165,13 +161,11 @@ impl JSONTokens {
self.tokens.push(JSONToken {
hash: scopes.hash,
scopes: Some(
scopes
.scopes
.iter()
.map(|x| x.as_ref().to_string())
.collect(),
),
scopes: scopes
.scopes
.iter()
.map(|x| x.as_ref().to_string())
.collect(),
token,
});
}