-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[JENKINS-75378] Adding a CLI command listener #10382
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
krisstern
merged 18 commits into
jenkinsci:master
from
apuig:JENKINS-75378-cli-listener
Mar 22, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b41633f
[JENKINS-75378] cli command listener
apuig 99ba771
fix checkstyle
apuig 5cb32e0
impersonate as SYSTEM in listeners
apuig 7b9cb0a
introduce `fire` methods on the interface
apuig b1e15c4
@since in interface. @Restricted default impl
apuig 32ead10
Simplify CliListener interface.
apuig b8f360a
introduce hudson.cli.listeners.CliContext
apuig 206147e
missing header in CliContext
apuig 5433f59
pr comments
apuig 751313c
pr comments:
apuig dcbbdf6
Merge branch 'master' into JENKINS-75378-cli-listener
krisstern b5c3f70
Update core/src/main/java/hudson/cli/CLICommand.java
krisstern 1138c0d
move new classes to jenkins.cli package
apuig 4d7e35a
rename new classes to capitalize CLI
apuig 3679a4d
single call to getTransportAuthentication2
apuig 676835c
test CLIMethod unexpected error
apuig bdf2895
rename to `onThrowable`
apuig 737c08d
Merge branch 'master' into JENKINS-75378-cli-listener
apuig 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
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
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,88 @@ | ||
| /* | ||
| * The MIT License | ||
| * | ||
| * Copyright (c) 2025, CloudBees, Inc. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| package jenkins.cli.listeners; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.springframework.security.core.Authentication; | ||
|
|
||
| /** | ||
| * Holds information of a command execution. Same instance is used to all {@link CLIListener} invocations. | ||
| * Use {@code correlationId} in order to group related events to the same command. | ||
| * | ||
| * @since TODO | ||
| */ | ||
| public class CLIContext { | ||
| private final String correlationId = UUID.randomUUID().toString(); | ||
| private final String command; | ||
| private final List<String> args; | ||
| private final Authentication auth; | ||
|
|
||
| /** | ||
| * @param command The command being executed. | ||
| * @param args Arguments passed to the command. | ||
| * @param auth Authenticated user performing the execution. | ||
| */ | ||
| public CLIContext(@NonNull String command, @CheckForNull List<String> args, @Nullable Authentication auth) { | ||
| this.command = command; | ||
| this.args = args != null ? args : List.of(); | ||
| this.auth = auth; | ||
| } | ||
|
|
||
| /** | ||
| * @return Correlate this command event to other, related command events. | ||
| */ | ||
| @NonNull | ||
| public String getCorrelationId() { | ||
| return correlationId; | ||
| } | ||
|
|
||
| /** | ||
| * @return Command being executed. | ||
| */ | ||
| @NonNull | ||
| public String getCommand() { | ||
| return command; | ||
| } | ||
|
|
||
| /** | ||
| * @return Arguments passed to the command. | ||
| */ | ||
| @NonNull | ||
| public List<String> getArgs() { | ||
| return args; | ||
| } | ||
|
|
||
| /** | ||
| * @return Authenticated user performing the execution. | ||
| */ | ||
| @CheckForNull | ||
| public Authentication getAuth() { | ||
| return auth; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
BadCredentialsExceptionis not longer possible insideCLICommand#main, note{set/get}TransportAuth2:for HTTP or WebSocket the BadCredential is thrown/handled in the filters. When using command line
-auth user:passbasic auth : BasicHeaderAuthenticator / AbstractUserAuth.for SSH auth errors (not a BadCredentials) is also handled before executing the command (PublicKeyAuthenticatorImpl / UserAuthNamedFactory).
b1803a9 I can't find CliAuthenticationTest, may not apply anymore.
EDIT: this branch is only possible if a CLICommand implementation throws a
BadCredentialsException,