Class HttpAuthHeaderFactory
java.lang.Object
io.jenkins.plugins.opentelemetry.jenkins.HttpAuthHeaderFactory
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 Summary
ConstructorsConstructorDescriptionHttpAuthHeaderFactory
(com.cloudbees.plugins.credentials.Credentials jenkinsCredentials) Constructor to create an instance of HttpAuthHeaderFactory.HttpAuthHeaderFactory
(com.cloudbees.plugins.credentials.Credentials jenkinsCredentials, Boolean bearerMode) Constructor to create an instance of HttpAuthHeaderFactory with bearer mode.HttpAuthHeaderFactory
(String jenkinsCredentialsId) Constructor to create an instance of HttpAuthHeaderFactory.HttpAuthHeaderFactory
(String jenkinsCredentialsId, Boolean bearerMode) Constructor to create an instance of HttpAuthHeaderFactory with bearer mode. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.hc.core5.http.Header
Creates an authentication header using the Jenkins credentials.static Optional<HttpAuthHeaderFactory>
createFactory
(String jenkinsCredentialsId) Creates an authentication header Factory using the provided credentials ID.static Optional<HttpAuthHeaderFactory>
createFactory
(Optional<String> jenkinsCredentialsId) Creates an authentication header Factory using the provided credentials ID Optional.static Optional<HttpAuthHeaderFactory>
createFactoryApikey
(String apiKey) Creates an authentication header Factory using the provided API key.static Optional<HttpAuthHeaderFactory>
createFactoryBearer
(String bearerToken) Creates an authentication header Factory using the provided Bearer token.static Optional<HttpAuthHeaderFactory>
createFactoryUsernamePassword
(String username, String password) Creates an authentication header Factory using the provided username and password.
-
Constructor Details
-
HttpAuthHeaderFactory
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 credentialsbearerMode
- whether to use bearer mode for authentication
-
HttpAuthHeaderFactory
Constructor to create an instance of HttpAuthHeaderFactory with bearer mode.- Parameters:
jenkinsCredentialsId
- the ID of the Jenkins credentialsbearerMode
- whether to use bearer mode for authentication
-
-
Method Details
-
createAuthHeader
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
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 authenticationpassword
- the password for authentication- Returns:
- an Optional containing the HttpAuthHeaderFactory object
-
createFactoryApikey
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
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
-