Class HALMConnection
- java.lang.Object
-
- hudson.model.AbstractDescribableImpl<HALMConnection>
-
- com.perforce.halm.jenkins.globalconfig.HALMConnection
-
- All Implemented Interfaces:
Describable<HALMConnection>
,Serializable
public class HALMConnection extends AbstractDescribableImpl<HALMConnection> implements Serializable
Global setting that defines a single Helix ALM REST API connection- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HALMConnection.AbstractResult
Abstract base class for results, provides common error handling.static class
HALMConnection.AuthInfoResult
Authorization information resultstatic class
HALMConnection.CertificateResult
Certificate resultstatic class
HALMConnection.ConnectionInfoResult
ConnectionInformation result object.static class
HALMConnection.CredentialDetailsResult
Credentials information resultstatic class
HALMConnection.DescriptorImpl
Used for validating the HALMConnection's config.jellystatic class
HALMConnection.OptionalConnectionProps
Optional connection properties
-
Field Summary
Fields Modifier and Type Field Description protected Boolean
acceptSSLCertificates
Deprecated.
-
Constructor Summary
Constructors Constructor Description HALMConnection(String connectionUUID, String connectionName, String halmAPIAddress, String credentialsID)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
getAcceptedSSLCertificates()
boolean
getAcceptSSLCertificates()
This is here due to what looks like an odd bug in Jenkins? I would expectHALMConnection.OptionalConnectionProps
to be invoked to retrieve this information, however the setting did not appear to be populated in the UI until I added this.HALMConnection.AuthInfoResult
getAuthInfo()
We need to check for a variety of conditions while parsing the credentials.protected static HALMConnection.AuthInfoResult
getAuthInfo(com.perforce.halm.reportingtool.APIAuthType authType, String credentialsID)
We need to check for a variety of conditions while parsing the credentials.HALMConnection.ConnectionInfoResult
getConnectionInfo()
Build a Helix ALM REST API 'ConnectionInfo' object based on this HALMConnection's settings.String
getConnectionName()
String
getConnectionUUID()
HALMConnection.CredentialDetailsResult
getCredentialDetails()
Retrieves credential info (username // password)static HALMConnection.CredentialDetailsResult
getCredentialDetails(String credentialsID)
Retrieves credential info (username // password)String
getCredentialsID()
com.perforce.halm.reportingtool.APIAuthType
getCredentialsType()
String
getCredentialTypeValue()
String
getHalmAPIAddress()
HALMConnection.OptionalConnectionProps
getOptionalConnectionProps()
boolean
getOptionalConnectionPropsIsSet()
This governs if the 'optional' checkbox is checked or not.List<String>
getOrRetrieveSSLCertificates()
This will either return the currently saved SSL Certificates or it will download new certificates that should work to connect to the configured Helix ALM REST API server.boolean
isHTTPSConnection()
Does this HALMConnection reference an HTTPS server?static boolean
isHTTPSConnection(String apiURL)
Does the supplied API URL reference an HTTPS server?protected Object
readResolve()
This allows upgrading old, saved XML configuration values to the current format.HALMConnection.CertificateResult
retrieveSSLCertificates()
Connect to the configured Helix ALM REST API address and attempt to download the server's SSL certificates.static HALMConnection.CertificateResult
retrieveSSLCertificates(String halmAPIAddress, String connectionName, boolean acceptSSLCertificates, List<String> currentCertificates)
Connect to the specified Helix ALM REST API address and attempt to download the server's SSL certificates.void
saveAcceptedSSLCertificates()
Saves a new set of accepted SSL certificates.static void
saveAcceptedSSLCertificates(String connectionUUID, String connectionName, List<String> acceptedSSLCertificates)
Saves a new set of accepted SSL certificates.void
setAcceptedSSLCertificates(List<String> acceptedSSLCertificates)
void
setAcceptSSLCertificates(boolean acceptSSLCertificates)
This is left for legacy support when 'AcceptSSLCertificates' was a top-level property.void
setConnectionName(String connectionName)
void
setCredentialsID(String credentialsID)
void
setCredentialType(com.perforce.halm.reportingtool.APIAuthType credentialType)
void
setCredentialTypeValue(String credentialType)
void
setHalmAPIAddress(String halmAPIAddress)
void
setOptionalConnectionProps(HALMConnection.OptionalConnectionProps optionalConnectionProps)
Sets the optional connection properties-
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
-
-
-
Field Detail
-
acceptSSLCertificates
@Deprecated protected transient Boolean acceptSSLCertificates
Deprecated.SeeHALMConnection.OptionalConnectionProps
. This is only here to ensure we can upgrade old configurations.
-
-
Constructor Detail
-
HALMConnection
@DataBoundConstructor public HALMConnection(String connectionUUID, String connectionName, String halmAPIAddress, String credentialsID)
Constructor.- Parameters:
connectionUUID
- - Unique connection IDconnectionName
- - the (hopefully unique) connection name.halmAPIAddress
- - Helix ALM API REST API addresscredentialsID
- - ID of the credentials
-
-
Method Detail
-
getConnectionUUID
public String getConnectionUUID()
- Returns:
- Unique, unfriendly, connection ID
-
getConnectionName
public String getConnectionName()
- Returns:
- Friendly connection name. May be empty. Maybe a duplicate of another connection. Prefer this (if it exists) when generating Pipeline syntax.
-
setConnectionName
@DataBoundSetter public final void setConnectionName(String connectionName)
- Parameters:
connectionName
- New connection ID to set
-
getHalmAPIAddress
public String getHalmAPIAddress()
- Returns:
- Helix ALM REST API address
-
setHalmAPIAddress
@DataBoundSetter public final void setHalmAPIAddress(String halmAPIAddress)
- Parameters:
halmAPIAddress
- Helix ALM REST API address
-
getCredentialTypeValue
public String getCredentialTypeValue()
- Returns:
- Credential type, for use w/ setting the global config dropdown
-
setCredentialTypeValue
@DataBoundSetter public final void setCredentialTypeValue(String credentialType)
- Parameters:
credentialType
- Credential type, as set on the global config dropdown.
-
getCredentialsType
public com.perforce.halm.reportingtool.APIAuthType getCredentialsType()
- Returns:
- Type of credentials (basic vs API Key)
-
setCredentialType
public void setCredentialType(com.perforce.halm.reportingtool.APIAuthType credentialType)
- Parameters:
credentialType
- Type of credentials (basic vs API Key)
-
getCredentialsID
public String getCredentialsID()
- Returns:
- ID of the credentials as stored in the Credentials plugin
-
setCredentialsID
@DataBoundSetter public final void setCredentialsID(String credentialsID)
- Parameters:
credentialsID
- ID of the credentials as stored in the Credentials plugin
-
setAcceptSSLCertificates
@DataBoundSetter public final void setAcceptSSLCertificates(boolean acceptSSLCertificates)
This is left for legacy support when 'AcceptSSLCertificates' was a top-level property. Old configurations may be saved with this setting and they need this function to self-upgrade the configuration.- Parameters:
acceptSSLCertificates
- Are we accepting SSL certificates
-
getAcceptSSLCertificates
public final boolean getAcceptSSLCertificates()
This is here due to what looks like an odd bug in Jenkins? I would expectHALMConnection.OptionalConnectionProps
to be invoked to retrieve this information, however the setting did not appear to be populated in the UI until I added this.- Returns:
- Returns the current setting for 'acceptSSLCertificates'
-
getOptionalConnectionPropsIsSet
public boolean getOptionalConnectionPropsIsSet()
This governs if the 'optional' checkbox is checked or not.- Returns:
- Is the optional connection props set?
-
getOptionalConnectionProps
public HALMConnection.OptionalConnectionProps getOptionalConnectionProps()
- Returns:
- The currently set optional properties object. This may be null
-
setOptionalConnectionProps
@DataBoundSetter public void setOptionalConnectionProps(HALMConnection.OptionalConnectionProps optionalConnectionProps)
Sets the optional connection properties- Parameters:
optionalConnectionProps
- Optional connection properties to set.
-
getAcceptedSSLCertificates
public List<String> getAcceptedSSLCertificates()
- Returns:
- List of accepted SSL certificates.
-
setAcceptedSSLCertificates
@DataBoundSetter public void setAcceptedSSLCertificates(List<String> acceptedSSLCertificates)
- Parameters:
acceptedSSLCertificates
- Set list of accepted SSL certificates
-
saveAcceptedSSLCertificates
public void saveAcceptedSSLCertificates() throws IOException
Saves a new set of accepted SSL certificates. This should only be called if the SSL certificates have changed.- Throws:
IOException
- Something went wrong while writing the certificates to the file.
-
saveAcceptedSSLCertificates
public static void saveAcceptedSSLCertificates(String connectionUUID, String connectionName, List<String> acceptedSSLCertificates) throws IOException
Saves a new set of accepted SSL certificates. This should only be called if the SSL certificates have changed.- Parameters:
connectionUUID
- UUID for the connection. This may be null.connectionName
- Connection name. This may NOT be null.acceptedSSLCertificates
- List of certificates that have been accepted and need to be saved.- Throws:
IOException
- Something went wrong while writing the certificates to the file.
-
readResolve
protected Object readResolve()
This allows upgrading old, saved XML configuration values to the current format.- Returns:
- The newly resolved // read in object.
-
getCredentialDetails
public HALMConnection.CredentialDetailsResult getCredentialDetails()
Retrieves credential info (username // password)- Returns:
- A CredentialDetailsResult object with either the credentials, or an error.
-
getCredentialDetails
public static HALMConnection.CredentialDetailsResult getCredentialDetails(String credentialsID)
Retrieves credential info (username // password)- Parameters:
credentialsID
- Jenkins Credentials ID- Returns:
- A CredentialDetailsResult object with either the credentials, or an error.
-
getAuthInfo
public HALMConnection.AuthInfoResult getAuthInfo()
We need to check for a variety of conditions while parsing the credentials. This handles all the odd edge cases and ensures we handle and return appropriate errors.- Returns:
- An authorization info result which either contains the auth info, or an error message indicating failure.
-
getAuthInfo
protected static HALMConnection.AuthInfoResult getAuthInfo(com.perforce.halm.reportingtool.APIAuthType authType, String credentialsID)
We need to check for a variety of conditions while parsing the credentials. This handles all the odd edge cases and ensures we handle and return appropriate errors.- Parameters:
authType
- Authorization type (API Key vs Basic)credentialsID
- Jenkins Credentials ID- Returns:
- An authorization info result which either contains the auth info, or an error message indicating failure.
-
getConnectionInfo
public HALMConnection.ConnectionInfoResult getConnectionInfo()
Build a Helix ALM REST API 'ConnectionInfo' object based on this HALMConnection's settings.- Returns:
- Various things can go wrong while building the ConnectionInfo. Check the 'IsError' on the result to ensure we successfully built a ConnectionInfo object.
-
isHTTPSConnection
public boolean isHTTPSConnection()
Does this HALMConnection reference an HTTPS server?- Returns:
- True if this references an HTTPS Helix ALM REST API server
-
isHTTPSConnection
public static boolean isHTTPSConnection(String apiURL)
Does the supplied API URL reference an HTTPS server?- Parameters:
apiURL
- URL to check- Returns:
- True if this references an HTTPS server
-
getOrRetrieveSSLCertificates
public List<String> getOrRetrieveSSLCertificates()
This will either return the currently saved SSL Certificates or it will download new certificates that should work to connect to the configured Helix ALM REST API server.- Returns:
- List of PEM encoded SSL certificates
-
retrieveSSLCertificates
public HALMConnection.CertificateResult retrieveSSLCertificates()
Connect to the configured Helix ALM REST API address and attempt to download the server's SSL certificates.- Returns:
- The certificate result object. Check 'isError' to see if the request was a success.
-
retrieveSSLCertificates
public static HALMConnection.CertificateResult retrieveSSLCertificates(String halmAPIAddress, String connectionName, boolean acceptSSLCertificates, List<String> currentCertificates)
Connect to the specified Helix ALM REST API address and attempt to download the server's SSL certificates.- Parameters:
halmAPIAddress
- Helix ALM REST API address.connectionName
- HALM Connection name in Jenkins (used for logging)acceptSSLCertificates
- Is the HALM Connection supposed to 'acceptSSLCertificates'?currentCertificates
- List of the current SSL Certificates.- Returns:
- The certificate result object. Check 'isError' to see if the request was a success.
-
-