Class DockerCredentialsHelper

java.lang.Object
io.jenkins.plugins.swarmcloud.config.DockerCredentialsHelper

public class DockerCredentialsHelper extends Object
Helper class for working with Docker server credentials.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default Docker Hub registry URL for official and user images.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.github.dockerjava.api.model.AuthConfig
    createAuthConfig(String credentialsId, String registryAddress)
    Creates AuthConfig for Docker registry from credentials.
    static String
    Extracts registry address from Docker image name.
    fillCredentialsIdItems(Item context, String dockerHost)
    Fills a ListBoxModel with available Docker server credentials.
    static String
    getCaCertificate(org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
    Gets the CA certificate from credentials.
    static String
    getClientCertificate(org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
    Gets the client certificate from credentials.
    static String
    getClientKey(org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
    Gets the client key from credentials.
    static boolean
    Checks if the current user has permission to access credentials for the given item.
    static org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials
    lookupCredentials(String credentialsId, String dockerHost)
    Looks up Docker server credentials by ID.
    static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
    Looks up username/password credentials for Docker registry authentication.

    Methods inherited from class java.lang.Object

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

    • DOCKER_HUB_REGISTRY_URL

      public static final String DOCKER_HUB_REGISTRY_URL
      Default Docker Hub registry URL for official and user images.
      See Also:
  • Method Details

    • hasCredentialsAccess

      public static boolean hasCredentialsAccess(@Nullable Item item)
      Checks if the current user has permission to access credentials for the given item.
      Parameters:
      item - The context item (may be null for global context)
      Returns:
      true if the user has sufficient permissions
    • lookupCredentials

      @Nullable public static org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials lookupCredentials(@Nullable String credentialsId, @NonNull String dockerHost)
      Looks up Docker server credentials by ID.
      Parameters:
      credentialsId - The credentials ID
      dockerHost - The Docker host URL (for domain matching)
      Returns:
      The credentials, or null if not found
    • fillCredentialsIdItems

      @NonNull public static ListBoxModel fillCredentialsIdItems(@Nullable Item context, @NonNull String dockerHost)
      Fills a ListBoxModel with available Docker server credentials.
      Parameters:
      context - The context item (for permission checks)
      dockerHost - The Docker host URL (for domain matching)
      Returns:
      ListBoxModel with credentials
    • getCaCertificate

      @Nullable public static String getCaCertificate(@Nullable org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
      Gets the CA certificate from credentials.
    • getClientCertificate

      @Nullable public static String getClientCertificate(@Nullable org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
      Gets the client certificate from credentials.
    • getClientKey

      @Nullable public static String getClientKey(@Nullable org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials credentials)
      Gets the client key from credentials.
    • lookupRegistryCredentials

      @Nullable public static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials lookupRegistryCredentials(@Nullable String credentialsId)
      Looks up username/password credentials for Docker registry authentication.
      Parameters:
      credentialsId - The credentials ID
      Returns:
      The credentials, or null if not found
    • createAuthConfig

      @Nullable public static com.github.dockerjava.api.model.AuthConfig createAuthConfig(@Nullable String credentialsId, @Nullable String registryAddress)
      Creates AuthConfig for Docker registry from credentials.
      Parameters:
      credentialsId - The credentials ID for registry authentication
      registryAddress - The registry address (e.g., "docker.io", "gcr.io")
      Returns:
      AuthConfig or null if credentials not found
    • extractRegistryAddress

      @NonNull public static String extractRegistryAddress(@NonNull String imageName)
      Extracts registry address from Docker image name.

      Examples:

      • "myregistry.com/image:tag" -> "myregistry.com"
      • "gcr.io/project/image:tag" -> "gcr.io"
      • "image:tag" -> "https://index.docker.io/v1/" (Docker Hub)
      • "myuser/myimage:v1" -> "https://index.docker.io/v1/" (Docker Hub)
      • "myregistry.com:5000/image:tag" -> "myregistry.com:5000"
      Parameters:
      imageName - The Docker image name
      Returns:
      The registry address