|
| 1 | +package com.cloudbees.plugins.credentials; |
| 2 | + |
| 3 | +import hudson.ExtensionPoint; |
| 4 | +import hudson.model.Item; |
| 5 | +import hudson.model.ModelObject; |
| 6 | +import hudson.model.Node; |
| 7 | +import hudson.model.Run; |
| 8 | +import jenkins.util.Listeners; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | + |
| 13 | +/** |
| 14 | + * A Listener to track {@link Credentials} usage. |
| 15 | + * @see CredentialsProvider#trackAll(Item, List) |
| 16 | + * @see CredentialsProvider#trackAll(Run, List) |
| 17 | + * @see CredentialsProvider#trackAll(Node, List) |
| 18 | + */ |
| 19 | +public interface CredentialsUseListener extends ExtensionPoint { |
| 20 | + |
| 21 | + /** |
| 22 | + * Called when {@link Credentials} is read by a run. |
| 23 | + * |
| 24 | + * @param c The used Credentials. |
| 25 | + * @param run The run using the credentials. |
| 26 | + */ |
| 27 | + void onUse(Credentials c, Run run); |
| 28 | + |
| 29 | + /** |
| 30 | + * Called when {@link Credentials} is read by a node. |
| 31 | + * |
| 32 | + * @param c The used Credentials. |
| 33 | + * @param node The node using the credentials. |
| 34 | + */ |
| 35 | + void onUse(Credentials c, Node node); |
| 36 | + |
| 37 | + /** |
| 38 | + * Called when {@link Credentials} is read by an item. |
| 39 | + * |
| 40 | + * @param c The used Credentials. |
| 41 | + * @param item The item using the credentials. |
| 42 | + */ |
| 43 | + void onUse(Credentials c, Item item); |
| 44 | + |
| 45 | + /** |
| 46 | + * Fires the {@link #onUse} event to track the run that uses credentials. |
| 47 | + * @see CredentialsProvider#trackAll(Run, List) |
| 48 | + */ |
| 49 | + static void fireUse(Credentials c, Run run) { |
| 50 | + Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, run)); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Fires the {@link #onUse} event to track the node that uses credentials. |
| 55 | + * @see CredentialsProvider#trackAll(Node, List) |
| 56 | + */ |
| 57 | + static void fireUse(Credentials c, Node node) { |
| 58 | + Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, node)); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Fires the {@link #onUse} event to track the item that uses credentials. |
| 63 | + * @see CredentialsProvider#trackAll(Item, List) |
| 64 | + */ |
| 65 | + static void fireUse(Credentials c, Item item) { |
| 66 | + Listeners.notify(CredentialsUseListener.class, true, listener -> listener.onUse(c, item)); |
| 67 | + } |
| 68 | +} |
0 commit comments