-
Notifications
You must be signed in to change notification settings - Fork 249
Add CredentialsUseListener to improve tracking of Credentials usage #295
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
Merged
jglick
merged 7 commits into
jenkinsci:master
from
meiswjn:feature/credential-usage-event
Apr 19, 2022
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70141de
Add CredentialsUseListener
meiswjn d43b53b
Simplify CredentialsUseListener by using latest LTS feature
meiswjn 735747f
Add @see links
meiswjn b91f8e9
Change CredentialsUseListener to Interface
meiswjn 5066407
Merge branch 'master' into feature/credential-usage-event
meiswjn 342e742
Make listener more type-specific
meiswjn d8c2e77
Merge branch 'feature/credential-usage-event' of https://github.com/m…
meiswjn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/cloudbees/plugins/credentials/CredentialsUseListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.cloudbees.plugins.credentials; | ||
|
|
||
| import hudson.ExtensionList; | ||
| import hudson.ExtensionPoint; | ||
| import hudson.model.AbstractModelObject; | ||
| import hudson.model.Item; | ||
| import hudson.model.Run; | ||
|
|
||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * A Listener to track {@link Credentials } usage. | ||
| */ | ||
| public abstract class CredentialsUseListener implements ExtensionPoint { | ||
meiswjn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Stop listening to {@link CredentialsUseListener}. | ||
| */ | ||
| public void unregister() { | ||
meiswjn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| all().remove(this); | ||
| } | ||
|
|
||
| /** | ||
| * Called when {@link Credentials} is used by an object, usually either {@link Run} or {@link hudson.model.Node} | ||
| * | ||
| * @param c The used Credentials. | ||
| * @param obj The object using the credentials. Object is usually either {@link Run} or {@link hudson.model.Node} | ||
| */ | ||
| public abstract void onUse(Credentials c, AbstractModelObject obj); | ||
meiswjn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Called when {@link Credentials} is used by an item . | ||
| * | ||
| * @param c The used Credentials. | ||
| * @param item The object using the credentials. | ||
| */ | ||
| public abstract void onUse(Credentials c, Item item); | ||
|
|
||
| /** | ||
| * Fires the {@link #onUse} event to track the object that uses credentials. | ||
| */ | ||
| public static void fireUse(Credentials c, AbstractModelObject obj) { | ||
| for (CredentialsUseListener listener : all()) { | ||
| try { | ||
| listener.onUse(c, obj); | ||
| } catch (ThreadDeath td) { | ||
| throw td; | ||
| } catch (Throwable t) { | ||
| Logger.getLogger(CredentialsUseListener.class.getName()).log(Level.WARNING, null, t); | ||
| } | ||
| } | ||
meiswjn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Fires the {@link #onUse} event to track the item that uses credentials. | ||
| */ | ||
| public static void fireUse(Credentials c, Item item) { | ||
| for (CredentialsUseListener listener : all()) { | ||
| try { | ||
| listener.onUse(c, item); | ||
| } catch (ThreadDeath td) { | ||
| throw td; | ||
| } catch (Throwable t) { | ||
| Logger.getLogger(CredentialsUseListener.class.getName()).log(Level.WARNING, null, t); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns all the registered {@link CredentialsUseListener} descriptors. | ||
| */ | ||
| public static ExtensionList<CredentialsUseListener> all() { | ||
meiswjn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ExtensionList.lookup(CredentialsUseListener.class); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.