Class SshCredentialsHelper

java.lang.Object
com.sonyericsson.hudson.plugins.gerrit.trigger.config.SshCredentialsHelper

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class SshCredentialsHelper extends Object
Resolves SSH private keys stored in the Jenkins credentials store (SSH Credentials Plugin) for the connection to Gerrit. Only credentials from the global (Jenkins root) scope are considered, since the Gerrit server configuration itself is global. See JENKINS-21637 / GitHub issue #664.
  • Method Summary

    Modifier and Type
    Method
    Description
    Lists the SSH private key credentials a Gerrit server can use.
    static boolean
    isKeyUsable(com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey credential)
    Checks that the credential holds a private key that JSch can parse and, if the key is encrypted, that the stored passphrase decrypts it.
    static com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey
    lookup(String credentialsId)
    Looks up an SSH private key credential by id in the global scope.
    static com.sonymobile.tools.gerrit.gerritevents.ssh.Authentication
    toAuthentication(com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey credential, String gerritUserName)
    Creates an Authentication holding the private key in memory instead of a key file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • lookup

      @CheckForNull public static com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey lookup(@CheckForNull String credentialsId)
      Looks up an SSH private key credential by id in the global scope.
      Parameters:
      credentialsId - the credentials id, may be null or empty.
      Returns:
      the credential or null if the id is empty or no such credential exists.
    • toAuthentication

      @NonNull public static com.sonymobile.tools.gerrit.gerritevents.ssh.Authentication toAuthentication(@NonNull com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey credential, @CheckForNull String gerritUserName)
      Creates an Authentication holding the private key in memory instead of a key file. The Gerrit user name configured on the server takes precedence, because the plugin also uses it to recognize its own review comments. The credential's user name is only used when the server configuration has none.
      Parameters:
      credential - the SSH credential.
      gerritUserName - the user name from the server configuration, may be empty.
      Returns:
      the authentication.
      Throws:
      IllegalStateException - if the credential holds no private key.
    • isKeyUsable

      public static boolean isKeyUsable(@NonNull com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey credential)
      Checks that the credential holds a private key that JSch can parse and, if the key is encrypted, that the stored passphrase decrypts it.
      Parameters:
      credential - the SSH credential.
      Returns:
      true if the key is usable.
    • fillCredentialsIdItems

      @NonNull public static ListBoxModel fillCredentialsIdItems(@CheckForNull String currentValue)
      Lists the SSH private key credentials a Gerrit server can use.
      Parameters:
      currentValue - the currently configured id, kept in the list even if it no longer resolves.
      Returns:
      the list box model.