-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from meiswjn/feature/credential-usage-event
Add CredentialsUseListener to improve tracking of Credentials usage
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
68 changes: 68 additions & 0 deletions
68
src/main/java/com/cloudbees/plugins/credentials/CredentialsUseListener.java
This file contains 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,68 @@ | ||
package com.cloudbees.plugins.credentials; | ||
|
||
import hudson.ExtensionPoint; | ||
import hudson.model.Item; | ||
import hudson.model.ModelObject; | ||
import hudson.model.Node; | ||
import hudson.model.Run; | ||
import jenkins.util.Listeners; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* A Listener to track {@link Credentials} usage. | ||
* @see CredentialsProvider#trackAll(Item, List) | ||
* @see CredentialsProvider#trackAll(Run, List) | ||
* @see CredentialsProvider#trackAll(Node, List) | ||
*/ | ||
public interface CredentialsUseListener extends ExtensionPoint { | ||
|
||
/** | ||
* Called when {@link Credentials} is read by a run. | ||
* | ||
* @param c The used Credentials. | ||
* @param run The run using the credentials. | ||
*/ | ||
void onUse(Credentials c, Run run); | ||
|
||
/** | ||
* Called when {@link Credentials} is read by a node. | ||
* | ||
* @param c The used Credentials. | ||
* @param node The node using the credentials. | ||
*/ | ||
void onUse(Credentials c, Node node); | ||
|
||
/** | ||
* Called when {@link Credentials} is read by an item. | ||
* | ||
* @param c The used Credentials. | ||
* @param item The item using the credentials. | ||
*/ | ||
void onUse(Credentials c, Item item); | ||
|
||
/** | ||
* Fires the {@link #onUse} event to track the run that uses credentials. | ||
* @see CredentialsProvider#trackAll(Run, List) | ||
*/ | ||
static void fireUse(Credentials c, Run run) { | ||
Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, run)); | ||
} | ||
|
||
/** | ||
* Fires the {@link #onUse} event to track the node that uses credentials. | ||
* @see CredentialsProvider#trackAll(Node, List) | ||
*/ | ||
static void fireUse(Credentials c, Node node) { | ||
Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, node)); | ||
} | ||
|
||
/** | ||
* Fires the {@link #onUse} event to track the item that uses credentials. | ||
* @see CredentialsProvider#trackAll(Item, List) | ||
*/ | ||
static void fireUse(Credentials c, Item item) { | ||
Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, item)); | ||
} | ||
} |