Skip to content

Commit

Permalink
Rename tokenExpiry field to prevent Folders corruption issues when up…
Browse files Browse the repository at this point in the history
…grading from old versions of this plugin (#336)
  • Loading branch information
dwnusbaum authored Aug 30, 2024
1 parent d49bf74 commit 946b535
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public void setUsePolicies(Boolean usePolicies) {
this.usePolicies = usePolicies;
}

private transient Map<String, Calendar> tokenExpiry;
// Renamed from tokenExpiry to prevent XStream from attempting to deserialize old instances of this class which had the type `Calendar` prior to https://github.com/jenkinsci/hashicorp-vault-plugin/pull/223.
private transient Map<String, Calendar> tokenExpiryCache;
private transient Map<String, String> tokenCache;

protected AbstractVaultTokenCredentialWithExpiration(CredentialsScope scope, String id,
String description) {
super(scope, id, description);
tokenExpiry = new HashMap<>();
tokenExpiryCache = new HashMap<>();
tokenCache = new HashMap<>();
}

Expand Down Expand Up @@ -108,7 +109,7 @@ public Vault authorizeWithVault(VaultConfig config, List<String> policies) {
// Upgraded instances can have these not initialized in the constructor (serialized jobs possibly)
if (tokenCache == null) {
tokenCache = new HashMap<>();
tokenExpiry = new HashMap<>();
tokenExpiryCache = new HashMap<>();
}

String cacheKey = getCacheKey(policies);
Expand Down Expand Up @@ -150,11 +151,11 @@ private void setTokenExpiry(Vault vault, String cacheKey) {
}
Calendar expiry = Calendar.getInstance();
expiry.add(Calendar.SECOND, tokenTTL);
tokenExpiry.put(cacheKey, expiry);
tokenExpiryCache.put(cacheKey, expiry);
}

private boolean tokenExpired(String cacheKey) {
Calendar expiry = tokenExpiry.get(cacheKey);
Calendar expiry = tokenExpiryCache.get(cacheKey);
if (expiry == null) {
return true;
}
Expand Down

0 comments on commit 946b535

Please sign in to comment.