Rework git askpass cache

This commit is contained in:
crschnick 2024-02-27 05:23:46 +00:00
parent 8e5550c61d
commit 6e64cdb96e
2 changed files with 17 additions and 4 deletions

View file

@ -74,4 +74,8 @@ public interface SecretQuery {
boolean cache(); boolean cache();
boolean retryOnFail(); boolean retryOnFail();
default boolean respectDontCacheSetting() {
return true;
}
} }

View file

@ -55,6 +55,8 @@ public class SecretQueryProgress {
} }
var firstSeenIndex = seenPrompts.indexOf(prompt); var firstSeenIndex = seenPrompts.indexOf(prompt);
var ref = new SecretReference(storeId, firstSeenIndex);
if (firstSeenIndex >= suppliers.size()) { if (firstSeenIndex >= suppliers.size()) {
countDown.pause(); countDown.pause();
var r = fallback.query(prompt); var r = fallback.query(prompt);
@ -63,14 +65,14 @@ public class SecretQueryProgress {
requestCancelled = true; requestCancelled = true;
return null; return null;
} }
if (shouldCache(fallback, prompt)) {
SecretManager.set(ref, r.getSecret());
}
return r.getSecret(); return r.getSecret();
} }
var ref = new SecretReference(storeId, firstSeenIndex);
var sup = suppliers.get(firstSeenIndex); var sup = suppliers.get(firstSeenIndex);
var shouldCache = sup.cache() var shouldCache = shouldCache(sup, prompt);
&& SecretManager.shouldCacheForPrompt(prompt)
&& !AppPrefs.get().dontCachePasswords().get();
var wasLastPrompt = firstSeenIndex == seenPrompts.size() - 1; var wasLastPrompt = firstSeenIndex == seenPrompts.size() - 1;
// Clear cache if secret was wrong/queried again // Clear cache if secret was wrong/queried again
@ -114,4 +116,11 @@ public class SecretQueryProgress {
} }
return r.getSecret(); return r.getSecret();
} }
private boolean shouldCache(SecretQuery query, String prompt) {
var shouldCache = query.cache()
&& SecretManager.shouldCacheForPrompt(prompt)
&& (!query.respectDontCacheSetting() || !AppPrefs.get().dontCachePasswords().get());
return shouldCache;
}
} }