Class HttpAuthHeaderFactory

java.lang.Object
io.jenkins.plugins.opentelemetry.jenkins.HttpAuthHeaderFactory

public class HttpAuthHeaderFactory extends Object
Factory class to create HTTP authentication headers for Jenkins credentials. This class is used to create authentication headers for different types of Jenkins credentials. It supports API keys and basic authentication using username and password. The class retrieves the credentials from Jenkins using the provided credentials ID. It throws a CredentialsNotFoundException if the credentials are not found or if the credentials ID is not provided.
  • Constructor Details

    • HttpAuthHeaderFactory

      public HttpAuthHeaderFactory(String jenkinsCredentialsId)
      Constructor to create an instance of HttpAuthHeaderFactory.
      Parameters:
      jenkinsCredentialsId - the ID of the Jenkins credentials
    • HttpAuthHeaderFactory

      public HttpAuthHeaderFactory(com.cloudbees.plugins.credentials.Credentials jenkinsCredentials)
      Constructor to create an instance of HttpAuthHeaderFactory.
      Parameters:
      jenkinsCredentials - the Jenkins credentials
    • HttpAuthHeaderFactory

      public HttpAuthHeaderFactory(com.cloudbees.plugins.credentials.Credentials jenkinsCredentials, Boolean bearerMode)
      Constructor to create an instance of HttpAuthHeaderFactory with bearer mode.
      Parameters:
      jenkinsCredentials - the Jenkins credentials
      bearerMode - whether to use bearer mode for authentication
    • HttpAuthHeaderFactory

      public HttpAuthHeaderFactory(String jenkinsCredentialsId, Boolean bearerMode)
      Constructor to create an instance of HttpAuthHeaderFactory with bearer mode.
      Parameters:
      jenkinsCredentialsId - the ID of the Jenkins credentials
      bearerMode - whether to use bearer mode for authentication
  • Method Details

    • createAuthHeader

      public org.apache.hc.core5.http.Header createAuthHeader() throws CredentialsNotFoundException
      Creates an authentication header using the Jenkins credentials. This method checks the type of credentials and creates the appropriate header. It supports API key, Bearer, and basic authentication.
      Returns:
      the authentication header
      Throws:
      CredentialsNotFoundException - if the credentials are not found
    • createFactory

      @NonNull public static Optional<HttpAuthHeaderFactory> createFactory(String jenkinsCredentialsId)
      Creates an authentication header Factory using the provided credentials ID. This method returns an Optional object. If the credentials ID is null or empty, it returns an empty Optional. If the credentials ID is valid, it returns an Optional containing the HttpAuthHeaderFactory object.
      Parameters:
      jenkinsCredentialsId - the ID of the Jenkins credentials
      Returns:
      an Optional containing the HttpAuthHeaderFactory object
    • createFactory

      @NonNull public static Optional<HttpAuthHeaderFactory> createFactory(@NonNull Optional<String> jenkinsCredentialsId)
      Creates an authentication header Factory using the provided credentials ID Optional. This method returns an Optional object. If the credentials ID is null or empty, it returns an empty Optional. If the credentials ID is valid, it returns an Optional containing the HttpAuthHeaderFactory object.
      Parameters:
      jenkinsCredentialsId - the ID of the Jenkins credentials
      Returns:
      an Optional containing the HttpAuthHeaderFactory object
    • createFactoryUsernamePassword

      @NonNull public static Optional<HttpAuthHeaderFactory> createFactoryUsernamePassword(String username, String password)
      Creates an authentication header Factory using the provided username and password. This method returns an Optional object. If the username or password is null or empty, it returns an empty Optional. If the username and password are valid, it returns an Optional containing the HttpAuthHeaderFactory object.
      Parameters:
      username - the username for authentication
      password - the password for authentication
      Returns:
      an Optional containing the HttpAuthHeaderFactory object
    • createFactoryApikey

      @NonNull public static Optional<HttpAuthHeaderFactory> createFactoryApikey(String apiKey)
      Creates an authentication header Factory using the provided API key. This method returns an Optional object. If the API key is null or empty, it returns an empty Optional. If the API key is valid, it returns an Optional containing the HttpAuthHeaderFactory object.
      Parameters:
      apiKey - the API key for authentication
      Returns:
      an Optional containing the HttpAuthHeaderFactory object
    • createFactoryBearer

      @NonNull public static Optional<HttpAuthHeaderFactory> createFactoryBearer(String bearerToken)
      Creates an authentication header Factory using the provided Bearer token. This method returns an Optional object. If the Bearer token is null or empty, it returns an empty Optional. If the Bearer token is valid, it returns an Optional containing the HttpAuthHeaderFactory object.
      Parameters:
      bearerToken - the Bearer token for authentication
      Returns:
      an Optional containing the HttpAuthHeaderFactory object