mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-07 21:48:30 +00:00
refactoring the testAuth methods
This commit is contained in:
parent
05e3b54977
commit
7af15bb237
2 changed files with 51 additions and 7 deletions
|
@ -106,11 +106,29 @@ class ApiCall {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test the credentials (login/password) on the RunDeck instance
|
||||
* Test the authentication on the RunDeck instance. Will delegate to either {@link #testLoginAuth()} (in case of
|
||||
* login-based auth) or {@link #testTokenAuth()} (in case of token-based auth).
|
||||
*
|
||||
* @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
|
||||
* @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
|
||||
* @see #testLoginAuth()
|
||||
* @see #testTokenAuth()
|
||||
*/
|
||||
public void testAuth() throws RundeckApiLoginException, RundeckApiTokenException {
|
||||
if (client.getToken() != null) {
|
||||
testTokenAuth();
|
||||
} else {
|
||||
testLoginAuth();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the login-based authentication on the RunDeck instance
|
||||
*
|
||||
* @throws RundeckApiLoginException if the login fails
|
||||
* @see #testAuth()
|
||||
*/
|
||||
public void testCredentials() throws RundeckApiLoginException {
|
||||
public void testLoginAuth() throws RundeckApiLoginException {
|
||||
HttpClient httpClient = instantiateHttpClient();
|
||||
try {
|
||||
login(httpClient);
|
||||
|
@ -119,6 +137,22 @@ class ApiCall {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the token-based authentication on the RunDeck instance
|
||||
*
|
||||
* @throws RundeckApiTokenException if the token is invalid
|
||||
* @see #testAuth()
|
||||
*/
|
||||
public void testTokenAuth() throws RundeckApiTokenException {
|
||||
try {
|
||||
execute(new HttpGet(client.getUrl() + RundeckClient.API_ENDPOINT + "/system/info"));
|
||||
} catch (RundeckApiTokenException e) {
|
||||
throw e;
|
||||
} catch (RundeckApiException e) {
|
||||
throw new RundeckApiTokenException("Failed to verify token", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an HTTP GET request to the RunDeck instance, on the given path. We will login first, and then execute the
|
||||
* API call. At the end, the given parser will be used to convert the response to a more useful result object.
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.rundeck.api.RundeckApiException.RundeckApiLoginException;
|
|||
import org.rundeck.api.RundeckApiException.RundeckApiTokenException;
|
||||
import org.rundeck.api.domain.RundeckAbort;
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckExecution.ExecutionStatus;
|
||||
import org.rundeck.api.domain.RundeckHistory;
|
||||
import org.rundeck.api.domain.RundeckJob;
|
||||
import org.rundeck.api.domain.RundeckJobsImportMethod;
|
||||
|
@ -40,6 +39,7 @@ import org.rundeck.api.domain.RundeckJobsImportResult;
|
|||
import org.rundeck.api.domain.RundeckNode;
|
||||
import org.rundeck.api.domain.RundeckProject;
|
||||
import org.rundeck.api.domain.RundeckSystemInfo;
|
||||
import org.rundeck.api.domain.RundeckExecution.ExecutionStatus;
|
||||
import org.rundeck.api.parser.AbortParser;
|
||||
import org.rundeck.api.parser.ExecutionParser;
|
||||
import org.rundeck.api.parser.HistoryParser;
|
||||
|
@ -158,12 +158,22 @@ public class RundeckClient implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test your credentials (login/password) on the RunDeck instance
|
||||
* Test the authentication on the RunDeck instance.
|
||||
*
|
||||
* @throws RundeckApiLoginException if the login fails
|
||||
* @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
|
||||
* @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
|
||||
*/
|
||||
public void testCredentials() throws RundeckApiLoginException {
|
||||
new ApiCall(this).testCredentials();
|
||||
public void testAuth() throws RundeckApiLoginException, RundeckApiTokenException {
|
||||
new ApiCall(this).testAuth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #testAuth()}
|
||||
* @see #testAuth()
|
||||
*/
|
||||
@Deprecated
|
||||
public void testCredentials() throws RundeckApiLoginException, RundeckApiTokenException {
|
||||
testAuth();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue