Skip to content

Commit 946b535

Browse files
authored
Rename tokenExpiry field to prevent Folders corruption issues when upgrading from old versions of this plugin (#336)
1 parent d49bf74 commit 946b535

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ public void setUsePolicies(Boolean usePolicies) {
4444
this.usePolicies = usePolicies;
4545
}
4646

47-
private transient Map<String, Calendar> tokenExpiry;
47+
// 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.
48+
private transient Map<String, Calendar> tokenExpiryCache;
4849
private transient Map<String, String> tokenCache;
4950

5051
protected AbstractVaultTokenCredentialWithExpiration(CredentialsScope scope, String id,
5152
String description) {
5253
super(scope, id, description);
53-
tokenExpiry = new HashMap<>();
54+
tokenExpiryCache = new HashMap<>();
5455
tokenCache = new HashMap<>();
5556
}
5657

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

114115
String cacheKey = getCacheKey(policies);
@@ -150,11 +151,11 @@ private void setTokenExpiry(Vault vault, String cacheKey) {
150151
}
151152
Calendar expiry = Calendar.getInstance();
152153
expiry.add(Calendar.SECOND, tokenTTL);
153-
tokenExpiry.put(cacheKey, expiry);
154+
tokenExpiryCache.put(cacheKey, expiry);
154155
}
155156

156157
private boolean tokenExpired(String cacheKey) {
157-
Calendar expiry = tokenExpiry.get(cacheKey);
158+
Calendar expiry = tokenExpiryCache.get(cacheKey);
158159
if (expiry == null) {
159160
return true;
160161
}

0 commit comments

Comments
 (0)