com.chavaillaz.client.jenkins.AbstractJenkinsClient Maven / Gradle / Ivy
package com.chavaillaz.client.jenkins;
import com.chavaillaz.client.common.AbstractClient;
import com.chavaillaz.client.common.utility.LazyCachedObject;
import com.chavaillaz.client.jenkins.api.JobApi;
import com.chavaillaz.client.jenkins.api.PipelineApi;
import com.chavaillaz.client.jenkins.api.PluginApi;
import com.chavaillaz.client.jenkins.api.QueueApi;
import com.chavaillaz.client.jenkins.api.SystemApi;
import com.chavaillaz.client.jenkins.api.UserApi;
/**
* Abstract class implementing common parts for Jenkins clients.
*
* @param The HTTP client type
*/
public abstract class AbstractJenkinsClient extends AbstractClient implements JenkinsClient {
protected final LazyCachedObject jobApi = new LazyCachedObject<>();
protected final LazyCachedObject pipelineApi = new LazyCachedObject<>();
protected final LazyCachedObject pluginApi = new LazyCachedObject<>();
protected final LazyCachedObject queueApi = new LazyCachedObject<>();
protected final LazyCachedObject systemApi = new LazyCachedObject<>();
protected final LazyCachedObject userApi = new LazyCachedObject<>();
protected JenkinsAuthentication authentication;
/**
* Creates a new abstract client.
*
* @param baseUrl The base URL of the endpoints
*/
protected AbstractJenkinsClient(String baseUrl) {
super(baseUrl);
}
@Override
public JenkinsClient withTokenAuthentication(String token) {
throw new UnsupportedOperationException("Token authentication needs username");
}
@Override
public JenkinsClient withTokenAuthentication(String username, String token) {
this.authentication = new JenkinsAuthentication(username, token);
return this;
}
@Override
public JenkinsClient withUserAuthentication(String username, String password) {
this.authentication = new JenkinsAuthentication(username, password);
return this;
}
@Override
public JenkinsClient withAnonymousAuthentication() {
this.authentication = new JenkinsAuthentication(null, null);
return this;
}
}