-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement initial lazy caching credentials provider #578
Implement initial lazy caching credentials provider #578
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My feeling here is we're adding a lot of layers but the layers don't necessarily abstract complexity in an ideal way. I think the refreshing Cache
is a layer that makes sense (and I'd pull it into it's own module with its own tests). But I'm not sure we need more than one layer for the actual credentials provider implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, happy to merge and keep iterating
|
||
#[derive(Clone)] | ||
pub(super) struct Cache { | ||
margin: Duration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a doc comment explaining what this field is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think building time based expiry into this cache explicitly might not be exactly what we want, but fine to keep it this way for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment and renamed to buffer_time
.
Hard to say right now, but I think alternate caching credentials provider implementations will use the cache the same way. Seems like a safe bet to defer refactoring until then.
self.value.read().await.get().cloned() | ||
} | ||
|
||
pub async fn refresh<F, Fut>(&self, f: F) -> CredentialsResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth a doc comment explaining that the caller should ensure f
is always the same and that there is no guarantee that this f
will be called.
Also, I'm not sure about the name refresh
here—it implies to me that it would reload load them. What about get_or_load
? or get_or_fetch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added doc comment and renamed to get_or_load
.
} | ||
|
||
/// If the credentials are expired, clears the cache. Otherwise, yields the current credentials value. | ||
pub async fn yield_or_clear_if_expired(&self, now: SystemTime) -> Option<Credentials> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll probably need a way to also explicitly expire credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use-case for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
credentials can become invalidated (eg. manually invalidated session credentials)
|
||
const DEFAULT_REFRESH_TIMEOUT: Duration = Duration::from_secs(5); | ||
const DEFAULT_CREDENTIAL_EXPIRATION: Duration = Duration::from_secs(15 * 60); | ||
const DEFAULT_EXPIRATION_MARGIN: Duration = Duration::from_secs(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about DEFAULT_CREDENTIAL_TTL
? I think TTL
is a little clearer than MARGIN
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time-to-live is kind of the opposite of what this is representing. I had chosen "margin" as in "safety margin". Chose to rename to buffer_time
, since maybe that is slightly clearer, but I can't think of a good name for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I totally misunderstood the purpose of this constant 🤕
This implements an initial lazy caching credentials provider, but doesn't attempt to add async runtime-agnostic timeouts or panic handling yet. Both of those will take a considerable amount of work still.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.