Skip to content
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

Rename tokenExpiry field to prevent Folder corruption issues when upgrading from old versions of this plugin #336

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
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 @@
// 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<>();

Check warning on line 112 in src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 112 is not covered by tests
}

String cacheKey = getCacheKey(policies);
Expand Down Expand Up @@ -150,11 +151,11 @@
}
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